Git Product home page Git Product logo

Comments (4)

Adriien-M avatar Adriien-M commented on July 17, 2024 3

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.

domaindrivendev avatar domaindrivendev commented on July 17, 2024

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.

rautsik avatar rautsik commented on July 17, 2024

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.

domaindrivendev avatar domaindrivendev commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.