Comments (4)
Hello,
This is an old issue but I think this code will be more apprpriate:
c.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/").TrimEnd('/'));
Because currently, VirtualPathRoot don't work for me...
Swagger's Docs are generated correctly but SwaggerUI gets a wrong url (without the virtual path).
from swashbuckle.webapi.
Hi there.
Although it's not documented (my bad!), Swashbuckle provides a config option to override the way in which the basePath is resolved. I think you'll be able to use this to work around the issue:
SwaggerSpecConfig.Customize(c =>
{
c.ResolveBasePathUsing((req) => .... );
}
The lambda takes the current HttpRequest (i.e. the request for a given Swagger ApiDeclaration) and should return a string to be used as the baseUrl for your Api. For load-balanced apps, this should return the load-balancer path.
The default implementation is as follows:
(req) => req.RequestUri.GetLeftPart(UriPartial.Authority) + req.GetConfiguration().VirtualPathRoot.TrimEnd('/');
Actually, until now I would have expected this to just work in a load balanced environment but your issue prompted me to investigate and lead me to the following blog http://www.rajeeshcv.com/post/details/40/stay-away-from-request-url. Now it's apparent that the default implementation should be modified to workaround this. I'll try get to it as soon as possible but in the meantime you should be able to implement a suitable override.
Re relative paths, the Swagger spec requires absolute paths because the URL at which the Swagger is being served need not be the URL of the actual API.
Let me know if this helps?
Thanks
from swashbuckle.webapi.
Thank you for proper explanation how it is implemented.
But unfortunately I wasn't able to get it work. When trying to set 'ResolveBasePathUsing', HttpRequest is not available. So I cannot get load-balancer path. And for same reason, I cannot implement the solution shown on blog post. Maybe I have missed something and you have some good idea, how I can still get it work ?
Thanks
from swashbuckle.webapi.
The lambda is passed a HttpRequestMessage instance ... you should be able to use this to get at the RequestUri etc. Another option, you could just place the host name in your web.config and have the lambda just read it from there.
from swashbuckle.webapi.
Related Issues (20)
- Using swagger with web.config in dotnet core web API
- Definitions are created when they are not referenced by any Operation HOT 1
- Static code analysis tool reported a high operational risk on the currently used package version of Microsoft.AspNet.WebApi.WebHost. Upgrade version to resolve dependencies on prerelease version of packages. HOT 1
- Custom model binder not working with swagger HOT 1
- Custom DocumentFilter not being applied HOT 1
- Client Code Generating Endpoints
- I cross domain request, do not want the browser to have pre check, options
- Change Controller Name HOT 1
- Model name is re-added to the Parameter if using AddVersionedApiExplorer
- swagger asp.net core failed to load api definition
- 876
- Swagger UI not loading with error Microsoft.AspNet.WebApi net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK) HOT 1
- Converting Swagger 2.0 to OpenAPI 3.0
- How can I not write an httppost in each method by default?
- How can I not specify httppost in each method?
- Swagger Query Parameter name prefix
- `UseOneOfForPolymorphism` puts `discriminator` in useless place in swagger-file
- Swashbuckle Example Data Type not showing correct markup HOT 1
- "Validation failed" error due to square brackets in $ref - swagger 2.0 json generated by swashbuckle web api - While importing in API Management HOT 1
- Restricting swagger ui endpoints and preventing developers from signing in twice
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swashbuckle.webapi.