Swagger complex response model with dynamic key value hash maps

Your usage of additionalProperties is correct and your model is correct. additionalProperties In Swagger/OpenAPI, hashmap keys are assumed to be strings, so the key type is not defined explicitly. additionalProperties define the type of hashmap values. So, this schema type: object additionalProperties: type: string defines a string-to-string map such as: { “en”: “English text”, “de”: … Read more

How to convert OpenAPI 2.0 to OpenAPI 3.0? [closed]

Swagger Editor Paste your OpenAPI 2.0 definition into https://editor.swagger.io and select Edit > Convert to OpenAPI 3 from the menu. Swagger Converter Converts OpenAPI 2.0 and Swagger 1.x definitions to OpenAPI 3.0. https://converter.swagger.io/api/convert?url=OAS2_YAML_OR_JSON_URL This gives you JSON. If you want YAML, send the request with the Accept: application/yaml header: curl “https://converter.swagger.io/api/convert?url=OAS2_YAML_OR_JSON_URL” -H “Accept: application/yaml” -o … Read more

Swagger 2.0: Multiple Path objects with different paths but same request and response

Yes, you can have a path item that references another path item: paths: /ab: post: summary: … … responses: … /a-b: $ref: ‘#/paths/~1ab’ # <———— Here, ~1ab is an encoded version of /ab (see below). One limitation of this approach is that you cannot have operationId in all operations of the referenced path item. This … Read more

How to define mutually exclusive query parameters in Swagger (OpenAPI)?

Mutually exclusive parameters are possible (sort of) in OpenAPI 3.x: Define the mutually exclusive parameters as object properties, and use oneOf or maxProperties to limit the object to just 1 property. Use the parameter serialization method style: form and explode: true, so that the object is serialized as ?propName=value. An example using the minProperties and … Read more

Swagger: map of

Using additionalPropertiesis the proper way to describe hashmap with OpenAPI (fka. Swagger) Specification but Swagger UI do not render them for now. The issue is tracked here https://github.com/swagger-api/swagger-ui/issues/1248 Meanwhile you can use this trick: define a non required property (defaultin the example below) of the same type of the map’s objects and give some hint … Read more

OpenAPI: what schema to accept any (complex) JSON value

An arbitrary-type schema can be defined using an empty schema {}: # swagger: ‘2.0’ definitions: AnyValue: {} # openapi: 3.0.0 components: schemas: AnyValue: {} or if you want a description: # swagger: ‘2.0’ definitions: AnyValue: description: ‘Can be anything: string, number, array, object, etc. (except `null`)’ # openapi: 3.0.0 components: schemas: AnyValue: description: ‘Can be … Read more

Swagger schema properties ignored when using $ref – why?

TL;DR: $ref siblings are supported (to an extent) in OpenAPI 3.1. In previous OpenAPI versions, any keywords alongside $ref are ignored. OpenAPI 3.1 Your definition will work as expected when migrated to OpenAPI 3.1. This new version is fully compatible with JSON Schema 2020-12, which allows $ref siblings in schemas. openapi: 3.1.0 … components: schemas: … Read more