Swagger 5.2.3 SupportedSubmitMethods removed? - swagger

I noticed that from version 5.0 and above the SupportedSubmitMethods option has been removed and now all HTTP verbs are implicitly supported, according to this part of the Swashbuckle documentation.
Is there a way to choose which HTTP verbs will support the "Try it out" option in swagger 5.X.X ?

No, I don't think so. You can however modify the behavior of swagger ui. VisualBean has put a solution here
The idea of his solution is to let Swashbuckle inject custom javascript that removes buttons with specific classes (eg .put .submit and .post .submit).

Related

Anyway to avoid Swagger be affected by authorization policies in .NET 5.0?

Every was fine with Swagger until I added an authorization policy in the StartUp Class:
options.AddPolicy("requiredRoleType", policy => policy.RequireRole());
The problem: Swagger is inaccessible because this policy. I've tried to move services.AddSwaggerGen in a different order but the problem remains.
Anyway to make Swagger bypasses authorization policies?
(using .NET 5.0 and Swashbuckle.AspNetCore 6.0.7)
I solved the issue by using Authorization Requirements as described in the official documentation:
https://learn.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-5.0
In this case Swagger is not affected by Authorization Requirements.

.net core 3.1 with swagger/swashbuckler without controller attributes

Anyone know how to configure swagger when using endpoint routing?
I see the following but no code on how to configure it.
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1306
The issue is without the following on my controller swagger doesn't find it.
[Route("[controller]")]
Also if there are multiple endpoints with the same HttpMethod it pukes. I have to define the route attribute on there too. I don't want to have to do this. Dev's will forget.
[Route("[controller]/MyGetRoute")]
Is there a configuration at the app level to just follow the endpoint routing convention?
I guess you use conventional based routing. If so, try the Swashbuckle.AspNetCore.SwaggerGen.ConventionalRouting package instead, which is an extension on top of Swashbuckle and supports conventional routing as well.

separate swagger UI URLs for ASPNETCORE 1.1

We have a .NET core 1.1 webapi project. We have two controller files and I've been able to generate separate swagger JSON files for each controller by decorating methods with GroupName.
When I browser the swagger UI (/swagger) I see that it has a drop down on top right corner that allows us to select the group.
Our requirement is to have a separate URL itself for swagger UI (not just JSON file) so that we can send a URL dedicated to a controller to our customers that doesn't confuse them. Is there a way to tell swashbuckle/swagger UI to use a specific URL for given JSON file/group name?
I tried checking if there's any query string parameter that swagger UI uses on change of dropdown but unfortunately it uses referer http header...
Yes swagger-ui has the url param that does exactly that.
Here are a few examples:
http://petstore.swagger.io/?url=http://heldersepu.github.io/hs-scripts/swagger/4134_swagger.json
http://offleaseonly.azurewebsites.net/swagger/ui/index?url=https://raw.githubusercontent.com/oasis-tcs/odata-openapi/master/examples/People.openapi3.json
http://swagger-net-test.azurewebsites.net/swagger/ui/index?url=http://heldersepu.github.io/hs-scripts/swagger/DiegoGuidi.json

How to use own swagger-ui with Liberty JSON generated content

There is an internal Liberty swagger-ui and it is working fine for me, but actually we need to make our own swagger layout, I mean putting our logo and our company name ... etc.
This is what we get when calling https://localhost:9443/ibm/api/docs with basic swagger-ui
But when we use the browser url and paste https://localhost:9443/ibm/api/docs we got the json content for our services
This is how it working with ibm liberty swagger-ui
And this how we need to show it to our clients
Currently there's no way to alter the "look & feel" of the built-in Liberty Swagger UI, but there is a Request For Enhancement that you can vote for: https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=87860
If you want to have your own Swagger UI totally independent of Liberty's UI, you can still pull from /ibm/api/docs like your first screenshot showed - the only thing you're missing is to setup CORS support on that Liberty instance, so that your custom Swagger UI is allowed to call it.
Here's the doc for setting up CORS in Liberty: https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_webcontainer_cors_config.html?cp=SSEQTP_8.5.5%2F1-8-1-1-21-1
Main sample from the link:
<cors domain="/ibm/api/collective"
allowedOrigins="https://alice.com:8090"
allowedMethods="GET, DELETE, POST"
allowedHeaders="accept, MyRequestHeader1"
exposeHeaders="MyResponseHeader1"
allowCredentials="true"
maxAge="3600" />

Swagger spec in Swagger Core Jersey 1.X

I am using Swagger with Jersey 1. It generates spec in Swagger spec v1.2. Most of the tools out there (e.g. Editor ) require spec v2.0. Is there a way to generate spec v2.0 ?
I actually wanted printable/static docs like bootprint-swagger which also required spec v2.0.
I have not tried it myself, but https://github.com/lucybot/api-spec-converter seems to be able to convert Swagger 1.2 to Swagger 2.0
I'm not sure if it is an "official" Swagger-Tool, but it is just two clicks away from the Swagger-1.2-to-2.0-Migration-Guide, so I guess its like "half-official" at least.
I might try to incoorporate it into bootprint-swagger so that it supports Swagger 1.2 as well. I've just created an issue at github so that it is not forgotten.

Resources