Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UrlHelper returns swagger route instead of resource route #481

Closed
ivanmartinvalle opened this issue Sep 3, 2015 · 2 comments
Closed

UrlHelper returns swagger route instead of resource route #481

ivanmartinvalle opened this issue Sep 3, 2015 · 2 comments

Comments

@ivanmartinvalle
Copy link

It seems that after installing Swashbuckle, UrlHelper starts returning all routes as a swagger route instead of the expected resource route. This caused us issues, as we rely on UrlHelper to set the Location header on POST requests.

HttpRequestMessage requestMessage = ...;
UrlHelper urlHelper = new UrlHelper(requestMessage);
var routeValues = new Dictionary<string, object> { {"Controller", "Users"}, {"userId", 10271992}};
var route = urlHelper.route(null, routeValues);
// Expected: "users/10271992"
// Actual: "swagger?Controller=Users&userId=10271992"

The issue comes from this line when relying on the default swagger-ui route.

Our current workaround is to configure a different route for swagger-ui

GlobalConfiguration.Configuration
                .EnableSwaggerUi("swagger/explorer/{*assetPath}", c => { 
                    // Our configuration 
                 } )

My questions:

  • Is there a better work around that allows us to keep the same "/swagger" route for swagger-ui?
  • Can this be documented somewhere, so someone else having the same issue can find the answer quickly (maybe this formal write-up of the issue is enough information to help someone out already)? I know it took us a non-trivial amount of time to track down the exact cause and an acceptable work around.
@domaindrivendev
Copy link
Owner

Interesting ... one way to get around this would be to pass a routeName instead of null to the route method. If you're using attribute routing, the value "DefaultApi" should suffice to scope the route lookup to just your API routes:

var route = urlHelper.Route("DefaultApi", new { controller = "users", userId = "123" });

If you're using traditional routing, you'll need to use the appropriate route name you've supplied when mapping your routes.

However, I can also fix this in Swashbuckle by constraining that specific route to be for UrlResolution only. See the following commit which will go out with the next release:

3e3a2c5

Thanks for pointing this out.

@domaindrivendev
Copy link
Owner

See 5.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants