Forum Discussion

arunpulimootil's avatar
arunpulimootil
New Member
5 months ago

OpenAPI spec to show query parameters and serialize it into an object

With @ModelAttribute in Spring framework we don't need to put the parameters as a number of arguments in a java endpoint definition function but with a simple object. How can we show that using openapi spec. So that the swagger UI will show all query parameters one after the other not just as a query object but the spec should indicate that the query parameters are mapped to a schema.

In the below example properties defined under User schemas should be shown as query params in path /api/users/getUserModel when rendered in swagger UI. But it is shown as an query object. Any thoughts on this ?

{ "openapi": "3.0.1", "info": { "title": "OpenAPI definition", "version": "v0" }, "servers": [ { "url": "http://localhost:8080/", "description": "Generated server url" } ], "paths": { "/api/users/getUserModel": { "get": { "tags": [ "user-controller" ], "summary": "Get user details from query parameters", "operationId": "getUserModel", "parameters": [ { "name": "user", "in": "query", "required": true, "schema": { "$ref": "#/components/schemas/User" } } ], "responses": { "200": { "description": "Successfully retrieved user details", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/User" } } } }, "400": { "description": "Invalid input" } } } } }, "components": { "schemas": { "User": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer", "format": "int32" }, "email": { "type": "string" } } } } } }

 

No RepliesBe the first to reply