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

NSwagStudio generating wrong endpoint address #843

Closed
andrecarlucci opened this issue Jul 12, 2017 · 5 comments
Closed

NSwagStudio generating wrong endpoint address #843

andrecarlucci opened this issue Jul 12, 2017 · 5 comments
Milestone

Comments

@andrecarlucci
Copy link

Hi @RSuter

I started a new project to try to reproduce the parameter problem (#842) and got another one:

namespace nswagtest.Controllers {
    [Produces("application/json")]
    [Route("/api/{subscriptionId}/[controller]")]
    public class SitesController : Controller {

        [HttpGet]
        [ProducesResponseType(typeof(Array), StatusCodes.Status200OK)]
        public IActionResult List(string searchString) {
            return Ok(new[] {"with", "parameter"});
        }

        [HttpGet("/api/sites")]
        [ProducesResponseType(typeof(Array), StatusCodes.Status200OK)]
        public IActionResult ListAll(string searchString) {
            return Ok(new[] {"list", "all"});
        }
    }
}

SwaggerUI generates the /api/sites endpoint correctly, but NSwagStudio creates it like: /api/{subscriptionId}/Sites/api/sites

@RicoSuter RicoSuter added this to the vNext milestone Jul 12, 2017
@RicoSuter
Copy link
Owner

The routes are appended but i think they only need to be appended if the httpget route does not start with /. Id say this is a bug...

@RicoSuter
Copy link
Owner

We need to add this check here

https://github.com/RSuter/NSwag/blob/master/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs#L275

Can you confirm that the class route is ignored when the operation route starts with /? What asp.net version are you working with?

@andrecarlucci
Copy link
Author

I'm using asp.net core.
Yes, from the docs (https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing):

Route templates applied to an action that begin with a / do not get combined with route templates applied to the controller. This example matches a set of URL paths similar to the default route.

[Route("Home")]
public class HomeController : Controller
{
    [Route("")]      // Combines to define the route template "Home"
    [Route("Index")] // Combines to define the route template "Home/Index"
    [Route("/")]     // Does not combine, defines the route template ""
    public IActionResult Index()
    {
        ViewData["Message"] = "Home index";
        var url = Url.Action("Index", "Home");
        ViewData["Message"] = "Home index" + "var url = Url.Action; =  " + url;
        return View();
    }

    [Route("About")] // Combines to define the route template "Home/About"
    public IActionResult About()
    {
        return View();
    }   
}

@RicoSuter
Copy link
Owner

Test with https://ci.appveyor.com/project/rsuter/nswag-25x6o/build/artifacts

@andrecarlucci
Copy link
Author

Wow! That was fast!
Thank you so much!!!
It worked :)

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

No branches or pull requests

2 participants