swashbuckle

Using Swashbuckle for Asp.net core how can I add a model to the generated model list?

匆匆过客 提交于 2019-11-30 09:39:59
I'm using Swashbuckle with ASP.net core. It is producing a nice website with a list of models at the bottom. How can I add a model to this list that isn't already appearing? I return an abstract class in one of my requests and I want to list all the variations that inherit that abstract class. Thanks in advance You could create an document filter and register it globally. public class CustomModelDocumentFilter<T> : IDocumentFilter where T : class { public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context) { context.SchemaRegistry.GetOrRegister(typeof(T)); } } and then

Unable to change swagger ui path

醉酒当歌 提交于 2019-11-30 09:35:39
问题 I'm using Swagger / Swashbuckle version 5.6 to generate documentation for my ASP.Net Web API 2 project. By default API documentation is accessible at URL http://localhost:56081/swagger/ui/index But, I want it should be available at http://localhost:56081/apihelp/ I searched a lot, tried changing settings in the SwaggerConfig.cs file but nothing seems to make this work. So, is this even possible? if yes, can anyone help me with this ? 回答1: You can add the path to the call of EnableSwaggereUi ,

Grouping of API methods in documentation - is there some custom attribute

瘦欲@ 提交于 2019-11-30 04:59:35
I have controller like public class UserController : ApiController { [Route("api/user")] IHttpActionResult GetUser() { ... } } public class ResumeController : ApiController { [Route("api/user/resumes")] IHttpActionResult GetResumes() { ... } } Which on swagger generates output like Is there a way (besides overriding default implementation by rolling out your own ISwaggerProvider or merging two controllers into one) to enforce the group name ? Something like public class UserController : ApiController { [Route("api/user")] [MagicalAttributeName(Group="User")] IHttpActionResult GetUser() { ... }

Modifications to Swagger UI header

夙愿已清 提交于 2019-11-29 19:51:23
问题 I have created a personal WEB API using Swashbuckle and Swagger API. While I am able to integrate this successfully, I would like to modify the default UI for Swagger. Changing the color of the header and replacing the swagger image. Is this possible by modifying existing files? 回答1: These are the steps I took: Create a new file SwaggerHeader.css Right click on SwaggerHeader.css , select Properties . Set Build action to Embedded Resource . In SwaggerConfig.cs , add the below line of code:

Swagger not working correctly with multiple versions of ASP.NET WebApi app

谁说我不能喝 提交于 2019-11-29 18:20:58
问题 Please help me with this, it looked easy at first, now I'm late in the project: I'm trying to setup API versioning for a ASP.NET WebApi project, along with Swagger. The API versioning works fine, calling different versions returns the correct results (see below). On the contrary, Swagger fails to serve both versions. While debugging, I noticed that when c.MultipleApiVersions(...) gets called in SwaggerConfig.cs, the controller reported by apiDesc.ActionDescriptor.ControllerDescriptor is

500 Error when setting up Swagger in asp .net CORE / MVC 6 app

穿精又带淫゛_ 提交于 2019-11-29 16:38:36
问题 I'm trying to setup a basic swagger API doc in a new asp .net CORE / MVC 6 project and receiving a 500 error from the swagger UI: 500 : http://localhost:4405/swagger/v1/swagger.json My startup class has the following code in it: using Swashbuckle.SwaggerGen; using Swashbuckle.SwaggerGen.XmlComments; using Swashbuckle.Application; .... public void ConfigureServices(IServiceCollection services) { ... services.AddSwaggerGen(); services.ConfigureSwaggerDocument(options => { options

Data annotations in Swagger

五迷三道 提交于 2019-11-29 09:15:41
I am using ASP.NET and Swagger that exposes a complex type that accepts a POST. It has a number of string fields that have different restricted lengths. How can I reflect that in the Swagger UI? You can annotate the properties with the StringLengthAttribute from System.ComponentModel.DataAnnotations . For instance: [StringLength(10)] public String Name {get;set;} will become: "name": { "minLength": 0, "maxLength": 10, "type": "string" } And this: [StringLength(10, MinimumLength = 5)] public String Name {get;set;} becomes: "name": { "minLength": 5, "maxLength": 10, "type": "string" } Besides

SwashBuckle/Swagger - OAuth Resource Owner Password Flow

♀尐吖头ヾ 提交于 2019-11-29 07:23:04
I'm trying to implement swagger into my Asp.Net Web API, and i'm running into a problem. I'm using the password resource owner flow, and i'm having to add a work around in order to do this, which is covered in the following stack overflow question :- Swagger/Swashbuckle: OAuth2 with Resource Owner Password Credentials Grant I've got everything working, the Bearer token is added via javascript to the request header in the current browser window, but the api calls to the controller methods requiring authorization are still return "401 - Authorization Failed". Here is the JavaScript that gets the

Integrate swashbuckle swagger with odata in ASP.Net Core [closed]

浪尽此生 提交于 2019-11-29 07:00:40
I have tried to implement both ( swagger and odata ) in asp.net core, but it's not working. I'm unable to integrate the route given for odata. I have the following Configuration and I receive a generic error. This is the error We ran into the same issue when adding OData to our .Net Core project. The workarounds shown in the code snippet on this post fixed our API error(s) when Swagger UI loads. As far as I can tell, OData isn't supported in Swashbuckle for AspNetCore. So after adding the workaround code in the link above, our Swagger UI works, but none of the OData endpoints show. Code

Not supported by Swagger 2.0: Multiple operations with path

此生再无相见时 提交于 2019-11-29 05:17:22
问题 I have integrated swagger in WebApi 2 application. It works fine when application has single controller. When I added second controller in the application. I got following error : An error has occurred.","ExceptionMessage":"Not supported by Swagger 2.0: Multiple operations with path 'api/Credential' and method 'GET'. See the config setting - \"ResolveConflictingActions\" for a potential workaround","ExceptionType":"System.NotSupportedException","StackTrace":" at Swashbuckle.Swagger