Is it possible to group multiple parameters to reference them in multiple routes?
For example I have a combination of parameters which I need in every route. They are defined as global parameters. How can I group them?
I think about a definition like this:
parameters:
MetaDataParameters:
# Meta Data Properties
- name: id
in: query
description: Entry identification number
required: false
type: integer
- name: time_start
in: query
description: Start time of flare
required: false
type: string
- name: nar
in: query
description: Active region number
required: false
type: string
And then reference the whole group in my route:
/test/:
get:
tags:
- TEST
operationId: routes.test
parameters:
- $ref: "#/parameters/MetaDataParameters"
responses:
200:
description: OK
Is this possible with Swagger 2.0?
If you are trying to send a body with multiple parameters, add an object model in the definitions section and refer it in your body parameter, see below (works with editor.swagger.io):
You can use the default key to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter's data type.
Basic authentication. API key (as a header or query parameter) OAuth 2 common flows (implicit, password, application and access code)
Swagger distinguishes between the following parameter types based on the parameter location. The location is determined by the parameter’s in key, for example, in: query or in: path . body parameters that describe the body of POST, PUT and PATCH requests (see Describing Request Body)
And also, there are some critical APIs that might change our database state or some configuration and we might not want to expose them. To solve this, we can group APIs in Swagger (using springdoc-openapi) so that only limited APIs are displayed in one group.
This "schema form" is the only form supported by Swagger. JSON Schema allows schemas that combine explicitly defined properties with additionalProperties. We'll call this a combination schema. However, in certain contexts, Swagger doesn't support combination schemas.
Powerful IDE for API-first design, documentation and development. The Swagger–OpenAPI 2.0 specification allows you to specify data types and structures for your API contract, using Schema Objects, and similar constructs that appear in Parameters and Headers. Schema Objects in particular provide the models for request and response message payloads:
This is not possible with Swagger 2.0 or OpenAPI 3.0. I've opened a feature request for this and it is proposed for a future version:
https://github.com/OAI/OpenAPI-Specification/issues/445
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With