Use object type query param in swagger documentation

后端 未结 3 2037
既然无缘
既然无缘 2020-11-29 13:17

I have a GET route where I would like to encode an object parameter in the url as a query string.

When writing the swagger documentation I basically get errors that

3条回答
  •  时光取名叫无心
    2020-11-29 13:39

    This is possible, just not with OpenAPI 2.0. OpenAPI 3.0 describes how this is possible here:

    https://swagger.io/docs/specification/describing-parameters/

    parameters:
    - in: query
      name: filter
      # Wrap 'schema' into 'content.'
      content:
        application/json:  # <---- media type indicates how to serialize / deserialize the parameter content
          schema:
            type: object
            properties:
              type:
                type: string
              color:
                type: string
    

    In the meantime you could just have the query parameter as a plain old string type and then perform the serialization manually, then set the query parameter as required. This is what I'm doing until Swagger UI fully supports OpenAPI 3.0.

提交回复
热议问题