Swagger: Add description with ref

For anyone using Swashbuckle with ASP.NET, you can use the following code to have the $ref construct put under the allOf (just like the : // do this wherever you are calling AddSwaggerGen() ArgBuilder.Services.AddSwaggerGen(opts => { opts.UseAllOfToExtendReferenceSchemas(); // add this line. }); Now if you have a model with two properties of the same type, … Read more

How can I describe complex json model in swagger

Okay, so based on the comments above, you want the following schema: { “definitions”: { “user”: { “type”: “object”, “required”: [ “name” ], “properties”: { “name”: { “type”: “string” }, “address”: { “type”: “array”, “items”: { “$ref”: “#/definitions/address” } } } }, “address”: { “type”: “object”, “properties”: { “type”: { “type”: “string”, “enum”: [ “home”, … Read more

How to fix java.lang.RuntimeException: missing swagger input or config?

You are using Swagger Codegen 2.x which does not support OpenAPI 3.0. You need to use Swagger Codegen 3.x instead. You can download the latest 3.x CLI JAR from Maven Central: https://mvnrepository.com/artifact/io.swagger.codegen.v3/swagger-codegen-cli Here’s a direct link to v. 3.0.20 CLI (the latest version as of the time of writing): https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.20/swagger-codegen-cli-3.0.20.jar Or if you prefer to … 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 to define header parameters in OpenAPI 3.0?

In OpenAPI 3.0, header parameters are defined in the same way as in OpenAPI 2.0, except the type has been replaced with schema: paths: /post: post: parameters: – in: header name: X-username schema: type: string When in doubt, check out the Describing Parameters guide. But in Swagger 3.0.0 parameters are replaced by request bodies. This … Read more

tech