JWT Authentication and Swagger with .NET Core 3.0

After some research, I eventually found the answer here Before seeing this page, I knew that I should use AddSecurityRequirement after AddSecurityDefinition because of many samples, but it was a problem that the function parameters have changed on .NET Core 3.0. By the way, the final answer is as below: services.AddSwaggerGen(c => { c.SwaggerDoc(“v1”, new … Read more

Swagger; specify two responses with same code based on optional parameter

OpenAPI 2.0 OAS2 does not support multiple response schemas per status code. You can only have a single schema, for example, a free-form object (type: object without properties). OpenAPI 3.x In OAS3 you can use oneOf to define multiple possible request bodies or response bodies for the same operation: openapi: 3.0.0 … paths: /path: get: … Read more

How to annotate a field as deprecated in OpenAPI (Swagger) 2.0?

The possibility to mark schemas and schema properties as deprecated was added in OpenAPI 3.0: openapi: 3.0.1 … components: schemas: Service: type: object properties: location: type: string description: Location of the service example: ‘400 Street name, City State postcode, Country’ deprecated: true # <——— If you use OpenAPI 2.0 (Swagger 2.0), the only thing you … Read more

How to post files in Swagger (OpenAPI)?

OpenAPI Specification 2.0 In Swagger 2.0 (OpenAPI Specification 2.0), use a form parameter (in: formData) with the type set to file. Additionally, the operation’s consumes must be multipart/form-data. consumes: – multipart/form-data parameters: – name: file in: formData # <—– description: The uploaded file data required: true type: file # <—– OpenAPI Specification 3.0 In OpenAPI … Read more

How to define an enum in OpenAPI (Swagger)?

“enum” works like this in OpenAPI 2.0: { “in”: “query”, “name”: “sample”, “description”: “a sample parameter with an enum value”, “type”: “string”, “enum”: [ “1”, “2”], “required”: true } and in OpenAPI 3.0: { “in”: “query”, “name”: “sample”, “description”: “a sample parameter with an enum value”, “schema”: { “type”: “string”, “enum”: [ “1”, “2”] }, … Read more

Generate static docs with swagger

Use swagger-codegen: swagger-codegen generate -i <path to your swagger file> -l html2 -o <path to output location> If you decide to customize the HTML template: Clone the swagger-codegen project from github Copy modules/swagger-codegen/src/main/resources/htmlDocs2 folder to another place, for example: cp -R modules/swagger-codegen/src/main/resources/htmlDocs2 ~/templates Modify the .mustache templates in ~/templates to fit your requirements. Run: swagger-codegen … Read more

Swagger Inheritance and Composition

As a beginner in swagger I don’t find the official documentation about polimorphism and composition easy to undestand, because it lacks an example. When I searched the net, there are lots of good examples refering to swagger 1.2 when extends was valid. For swagger 2.0 I found a good example in swagger spec sources on … 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

techhipbettruvabetnorabahisbahis forumuedusedueduedueduseduedusedusedusedus