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

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

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

Bearer authentication in Swagger UI, when migrating to Swashbuckle.AspNetCore version 5

Got this working in the end by trial and error. This is the code that works for me: c.AddSecurityDefinition(“Bearer”, new OpenApiSecurityScheme { Description = “JWT Authorization header using the Bearer scheme. \r\n\r\n Enter ‘Bearer’ [space] and then your token in the text input below.\r\n\r\nExample: \”Bearer 12345abcdef\””, Name = “Authorization”, In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, … Read more

swagger error: Conflicting schemaIds: Duplicate schemaIds detected for types A and B

Every class in the swagger JSON must have a unique schemaId. Swashbuckler tries to just use the class name as a simple schemaId, however if you have two classes in different namespaces with the same name (as you do) this will not work. As the error suggests, you can use the config setting “UseFullTypeNameInSchemaIds*” for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)