How to add method description in Swagger UI in WebAPI Application

This is well documented in the project: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#include-descriptions-from-xml-comments Include Descriptions from XML Comments To enhance the generated docs with human-friendly descriptions, you can annotate controller actions and models with Xml Comments and configure Swashbuckle to incorporate those comments into the outputted Swagger JSON: 1 – Open the Properties dialog for your project, click the “Build” … 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

How to configure Swashbuckle to ignore property on model

If you need to do this but without using JsonIgnore (maybe you still need to serialize/deserialize the property) then just create a custom attribute. [AttributeUsage(AttributeTargets.Property)] public class SwaggerExcludeAttribute : Attribute { } Then a schema filter similar to Johng’s public class SwaggerExcludeFilter : ISchemaFilter { #region ISchemaFilter Members public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type … 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

ASP.NET Core – Swashbuckle not creating swagger.json file

I had the same problem. Check http://localhost:XXXX/swagger/v1/swagger.json. If you get any a errors, fix them. For example, I had an ambiguous route in a base controller class and I got the error: “Ambiguous HTTP method for action. Actions require an explicit HttpMethod binding for Swagger 2.0.”. If you use base controllers make sure your public … Read more