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 format Swagger 2.0 text descriptions?

Markdown is supported in the Swagger Editor. Below is an example of using Markdown in an OpenAPI (Swagger) document: swagger: ‘2.0’ info: version: 0.0.0 title: Markdown description: | # Heading Text attributes _italic_, *italic*, __bold__, **bold**, `monospace`. Horizontal rule: — Bullet list: * apples * oranges * pears Numbered list: 1. apples 2. oranges 3. … Read more

Swagger/OpenAPI – use $ref to pass a reusable defined parameter

This feature already exists in Swagger 2.0. The linked ticket talks about some specific mechanics of it which doesn’t affect the functionality of this feature. At the top level object (referred to as the Swagger Object), there’s a parameters property where you can define reusable parameters. You can give the parameter any name, and refer … 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

How can I represent ‘Authorization: Bearer ‘ in a Swagger Spec (swagger.json)

Maybe this can help: swagger: ‘2.0’ info: version: 1.0.0 title: Based on “Basic Auth Example” description: > An example for how to use Auth with Swagger. host: basic-auth-server.herokuapp.com schemes: – http – https securityDefinitions: Bearer: type: apiKey name: Authorization in: header paths: /: get: security: – Bearer: [] responses: ‘200’: description: ‘Will send `Authenticated`’ ‘403’: … Read more

How to define a mixed-type array (with different element types) in OpenAPI 2.0?

The answer depends on which version of the OpenAPI Specification you use. OpenAPI 3.1 type can be a list of types, so you can write your schema as: # openapi: 3.1.0 obj1: type: array items: type: [string, integer] # or if nulls are allowed: # type: [string, integer, ‘null’] OpenAPI 3.0.x Mixed types are supported … Read more

How to configure Spring Security to allow Swagger URL to be accessed without authentication

Adding this to your WebSecurityConfiguration class should do the trick. @Configuration public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers(“/v2/api-docs”, “/configuration/ui”, “/swagger-resources/**”, “/configuration/security”, “/swagger-ui.html”, “/webjars/**”); } }

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