How to document dynamic query parameter names in OpenAPI (Swagger)?

Free-form query parameters can be described using OpenAPI 3.x, but not OpenAPI 2.0 (Swagger 2.0). The parameter must have type: object with the serialization method style: form and explode: true. The object will be serialized as ?prop1=value1&prop2=value2&…, where individual prop=value pairs are the object properties. openapi: 3.0.3 … paths: /users: get: parameters: – in: query … Read more

Swagger/OpenAPI mock server

An easy way to create simple mock from an OpenAPI (fka Swagger) spec without code is to use a tool call prism available at http://github.com/stoplightio/prism written in Typescript. This command line is all you need: ./prism run –mock –list –spec <your swagger spec file> The mock server will return a dynamic response based on the … Read more

How to return an array of objects in SwaggerHub?

An array of objects is defined as follows. The value of items must be a single model that describes the array items. definitions: AllContacts: type: array items: $ref: ‘#/definitions/ContactModel’ ContactModel: type: object properties: id: type: integer example: 1 firstName: type: string example: Sherlock lastName: type: string example: Holmes By default, Swagger UI displays the array … Read more

Swagger: How to have a property reference a model in OpenAPI 2.0 (i.e. nest the models)?

The correct way to model it in OpenAPI 2.0 would be: swagger: ‘2.0’ … definitions: SomeModel: type: object properties: prop1: type: string prop2: type: integer prop3: $ref: ‘#/definitions/OtherModel’ # <—– OtherModel: type: object properties: otherProp: type: string If you use OpenAPI 3.0, models live in components/schemas instead of definitions: openapi: 3.0.1 … components: schemas: SomeModel: … Read more