From 0469142d0571984619405908ad4c0c502dc31588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Garc=C3=ADa?= Date: Fri, 17 Dec 2021 11:55:40 +0100 Subject: [PATCH] Added root object names for better api first code generation --- existingApis.yaml | 57 +++++++++++++++++++++++++------------------- readme.md | 6 ++--- similarProducts.yaml | 53 +++++++++++++++++++++++----------------- 3 files changed, 67 insertions(+), 49 deletions(-) diff --git a/existingApis.yaml b/existingApis.yaml index c6090ba..cf7805e 100644 --- a/existingApis.yaml +++ b/existingApis.yaml @@ -22,12 +22,7 @@ paths: content: application/json: schema: - type: array - description: List of productIds similar to a given one ordered by similarity - minItems: 0 - uniqueItems: true - items: - type: integer + $ref: '#/components/schemas/SimilarProducts' '/product/{productId}': parameters: - schema: @@ -45,21 +40,35 @@ paths: content: application/json: schema: - description: 'Product detail' - type: object - properties: - id: - type: string - minLength: 1 - name: - type: string - minLength: 1 - price: - type: number - availability: - type: boolean - required: - - id - - name - - price - - availability \ No newline at end of file + $ref: '#/components/schemas/ProductDetail' + '404': + description: Product Not found +components: + schemas: + SimilarProducts: + type: array + description: 'List of similar product Ids to a given one ordered by similarity' + minItems: 0 + uniqueItems: true + items: + type: string + example: ["1","2","3"] + ProductDetail: + description: 'Product detail' + type: object + properties: + id: + type: string + minLength: 1 + name: + type: string + minLength: 1 + price: + type: number + availability: + type: boolean + required: + - id + - name + - price + - availability \ No newline at end of file diff --git a/readme.md b/readme.md index 838d21d..13e00fb 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # Backend dev technical test -We want to offer a new feature to our customers showing similar products to the one they are seeing. To do this we agreed with our front-end applications to create a new REST API that will provide them the product detail of similar products to a given one. [Here](./similarProducts.yaml) is the contract we agreed. +We want to offer a new feature to our customers showing similar products to the one they are currently seeing. To do this we agreed with our front-end applications to create a new REST API operation that will provide them the product detail of the similar products for a given one. [Here](./similarProducts.yaml) is the contract we agreed. -We already have an endpoint that provides the product Ids similar to a given one. We also have another endpoint that returns the product detail by productId. [Here](./existingApis.yaml) is the documentation of the existing APIs. +We already have an endpoint that provides the product Ids similar for a given one. We also have another endpoint that returns the product detail by product Id. [Here](./existingApis.yaml) is the documentation of the existing APIs. **Create a Spring boot application that exposes the agreed REST API on port 5000.** @@ -30,4 +30,4 @@ Browse [http://localhost:3000/d/Le2Ku9NMk/k6-performance-test](http://localhost: The following topics will be considered: - Code clarity and maintainability - Performance -- Resilence +- Resilence \ No newline at end of file diff --git a/similarProducts.yaml b/similarProducts.yaml index 7a0d668..b8310c0 100644 --- a/similarProducts.yaml +++ b/similarProducts.yaml @@ -21,25 +21,34 @@ paths: content: application/json: schema: - type: array - description: 'List of similar products to a given one ordered by similarity' - minItems: 0 - uniqueItems: true - items: - type: object - required: - - id - - name - - price - - availability - properties: - id: - type: string - minLength: 1 - name: - type: string - minLength: 1 - price: - type: number - availability: - type: boolean \ No newline at end of file + $ref: '#/components/schemas/SimilarProducts' + '404': + description: Product Not found +components: + schemas: + SimilarProducts: + type: array + description: 'List of similar products to a given one ordered by similarity' + minItems: 0 + uniqueItems: true + items: + $ref: '#/components/schemas/ProductDetail' + ProductDetail: + description: 'Product detail' + type: object + properties: + id: + type: string + minLength: 1 + name: + type: string + minLength: 1 + price: + type: number + availability: + type: boolean + required: + - id + - name + - price + - availability \ No newline at end of file