From 59afec1c00dcdabcdd3110d3815c0840a6bcc9a2 Mon Sep 17 00:00:00 2001 From: "alex.peptan" Date: Sat, 23 May 2020 20:06:43 +0300 Subject: [PATCH] BAEL-3896: OpenAPI JSON Objects in Query Params - README file revert + required changes --- spring-rest-http/README.md | 1 - .../jsonParamOpenApiSwagger3Definition | 32 ++ .../jsonParamOpenApiSwaggerDefinition | 276 ++++++++++-------- 3 files changed, 179 insertions(+), 130 deletions(-) create mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition diff --git a/spring-rest-http/README.md b/spring-rest-http/README.md index cba017eb74..35793cb281 100644 --- a/spring-rest-http/README.md +++ b/spring-rest-http/README.md @@ -13,4 +13,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RequestMapping](https://www.baeldung.com/spring-requestmapping) - [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result) - [Using JSON Patch in Spring REST APIs](https://www.baeldung.com/spring-rest-json-patch) -- [OpenAPI JSON Objects in Query Params](https://www.baeldung.com/openapi-json-objects-in-query-params) diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition new file mode 100644 index 0000000000..218e24b12b --- /dev/null +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition @@ -0,0 +1,32 @@ +swagger: '3.0' +info: + title: Sample API to send JSON objects as query parameters using OpenAPI 3 + description: API description. + version: 1.0.0 + +paths: + /tickets: + get: + parameters: + - in: query + name: params + required: true + # Parameter is an object that should be serialized as JSON + content: + application/json: + schema: + type: object + properties: + type: + type: string + name: + color: string + responses: + '200': + description: successful process + '401': + description: Unauthorized + '403': + description: Forbidden + '404': + description: Not Found diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition index 9f9bcb788a..3261736e15 100644 --- a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition @@ -1,5 +1,9 @@ swagger: '2.0' -... +info: + title: Sample API to send JSON objects as query parameters using OpenAPI 2 + description: API description. + version: 1.0.0 + paths: /tickets: get: @@ -10,10 +14,16 @@ paths: description: A JSON object with the `type` and `color` properties type: string example: '{"type":"foo","color":"green"}' + responses: + '200': + description: successful process + '401': + description: Unauthorized + '403': + description: Forbidden + '404': + description: Not Found -swagger: '2.0' -... -paths: /tickets: post: requestBody: @@ -26,129 +36,137 @@ paths: responses: '200': description: successful process + '201': + description: Created + '401': + description: Unauthorized + '403': + description: Forbidden + '404': + description: Not Found -"/api/tickets": { - "get": { - "tags": [ - "account-resource" - ], - "summary": "testQueryParamApi", - "operationId": "testQueryParamApiUsingGET", - "produces": [ - "*/*" - ], - "parameters": [ - { - "name": "params", - "in": "query", - "description": "params", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not Found" - } - }, - "deprecated": false - }, - "post": { - "tags": [ - "account-resource" - ], - "summary": "testBodyParamApi", - "operationId": "testBodyParamApiUsingPOST", - "consumes": [ - "application/json" - ], - "produces": [ - "*/*" - ], - "parameters": [ - { - "in": "body", - "name": "params", - "description": "params", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "201": { - "description": "Created" - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not Found" - } - }, - "deprecated": false - } -}, -"/api/tickets2": { - "get": { - "tags": [ - "account-resource" - ], - "summary": "testGetBodyParamApi", - "operationId": "testGetBodyParamApiUsingGET", - "produces": [ - "*/*" - ], - "parameters": [ - { - "in": "body", - "name": "params", - "description": "params", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not Found" - } - }, - "deprecated": false - } -} + /api/tickets: { + get: { + tags: [ + "account-resource" + ], + summary: "testQueryParamApi", + operationId: "testQueryParamApiUsingGET", + produces: [ + "*/*" + ], + parameters: [ + { + name: "params", + in: "query", + description: "params", + required: true, + type: "string" + } + ], + responses: { + 200: { + description: "OK", + schema: { + type: "string" + } + }, + 401: { + description: "Unauthorized" + }, + 403: { + description: "Forbidden" + }, + 404: { + description: "Not Found" + } + }, + deprecated: false + }, + post: { + tags: [ + "account-resource" + ], + summary: "testBodyParamApi", + operationId: "testBodyParamApiUsingPOST", + consumes: [ + "application/json" + ], + produces: [ + "*/*" + ], + parameters: [ + { + in: "body", + name: "params", + description: "params", + required: true, + schema: { + type: "string" + } + } + ], + responses: { + 200: { + description: "OK", + schema: { + type: "string" + } + }, + 201: { + description: "Created" + }, + 401: { + description: "Unauthorized" + }, + 403: { + description: "Forbidden" + }, + 404: { + description: "Not Found" + } + }, + deprecated: false + } + }, + /api/tickets2: { + get: { + tags: [ + "account-resource" + ], + summary: "testGetBodyParamApi", + operationId: "testGetBodyParamApiUsingGET", + produces: [ + "*/*" + ], + parameters: [ + { + in: "body", + name: "params", + description: "params", + required: true, + schema: { + type: "string" + } + } + ], + responses: { + 200: { + description: "OK", + schema: { + type: "string" + } + }, + 401: { + description: "Unauthorized" + }, + 403: { + description: "Forbidden" + }, + 404: { + description: "Not Found" + } + }, + deprecated: false + } + }