Web Api How to add a Header parameter for all API in Swagger

What the user “G T” wrote is correct but it is not working with Swagger 5. We have some new changes: From: Operation to: OpenApiOperation From: IParameter to: OpenApiParameter From: NonBodyParameter to: OpenApiParameter, and the most important is… From: Type = “string” to: Schema = new OpenApiSchema { Type = “String” } using System.Collections.Generic; using … Read more

Can’t read from file issue in Swagger UI

I am guessing “http://MYIP/swagger/docs/v1” is not publicly accessible. By default swagger ui uses an online validator: online.swagger.io. If it cannot access your swagger url then you will see that error message. Possible solutions: Disable validation: config.EnableSwagger().EnableSwaggerUi(c => c.DisableValidator()); Make your site publicly accessible Host the validator locally: You can get the validator from: https://github.com/swagger-api/validator-badge#running-locally You … Read more

List of swagger UI alternatives [closed]

Yes, there are a few of them. ReDoc [Article on swagger.io] [GitHub] [demo] – Reinvented OpenAPI/Swagger-generated API Reference Documentation (I’m the author) OpenAPI GUI [GitHub] [demo] – GUI / visual editor for creating and editing OpenApi / Swagger definitions (has OpenAPI 3 support) Responsive Fork of SwaggerUI [GitHub] [demo] SwaggerUI-Angular [GitHub] [demo] – An angularJS … Read more

How to describe a model in Swagger for an array with simple objects?

Tony YUEN was close, but no cigar. This is the proper definition using YAML in OpenAPI/Swagger: /test: post: summary: test 123 description: test 123 parameters: – name: param1 in: body required: true description: test param1 schema: $ref: ‘#/definitions/stackoverflow’ responses: 200: description: OK This produces: stackoverflow2[ { name: string } ] Tony’s example produces: [ stackoverflow … 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

Swagger TypeError: Failed to execute ‘fetch’ on ‘Window’: Request with GET/HEAD method cannot have body

I ran into this issue. Here is how I resolved it: I had a method like this: [HttpGet] public IEnumerable<MyObject> Get(MyObject dto) { … } and I was getting the error. I believe swagger UI is interpreting the Get parameters as FromBody, so it uses the curl -d flag. I added the [FromQuery] decorator and … Read more