Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to group multiple parameters in Swagger 2.0?

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?

like image 854
cansik Avatar asked Aug 19 '15 09:08

cansik


People also ask

How do you pass multiple parameters in swagger?

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):

How do you specify optional parameters in swagger?

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.

What are the three primary sections in a Swagger specification?

Basic authentication. API key (as a header or query parameter) OAuth 2 common flows (implicit, password, application and access code)

What are Swagger parameter types?

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)

Why do we need to group APIs in Swagger?

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.

Does Swagger support combination schema?

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.

What is the swagger–OpenAPI Specification?

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:


1 Answers

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

like image 197
cansik Avatar answered Sep 28 '22 10:09

cansik