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

Custom path ignored when route name specified #166

Open
chmely opened this issue Jan 9, 2019 · 1 comment
Open

Custom path ignored when route name specified #166

chmely opened this issue Jan 9, 2019 · 1 comment

Comments

@chmely
Copy link

chmely commented Jan 9, 2019

Expected Behavior

When I specify the Name and custom Path parameters in the Route() attribute both are used to generate the swagger file

Actual Behavior

When Name is specified the custom Path is ignored.

Steps to Reproduce the Problem

  1. Create a Nancy method, e.g.:
public class TestModule: NancyModule
{
    public TestModule()
    {
        Get("/test/{param:guid}", ctx => AMethod(ctx.param), name: "AMethod");
    }

    [Route("AMethod")]
    [Route(HttpMethod.Get, "/test/{param}")]
    [RouteParam(ParameterIn.Path, Name = "param", ParamType = typeof(Guid), Required = true)]
    private object AMethod(Guid param) => param.ToString();
}
  1. Generate swagger docs
  2. The route in the doc says '/test/{param:guid}' instead of /test/{param}' and you get a parse error at editor.swagger.io saying that "Declared path parameter "param:guid" needs to be defined as a path parameter at either the path or operation level"

Specifications

I think the problem is in the code in Nancy.Swagger.Annotations / RouteId.Create() method, if the code

            if (!string.IsNullOrEmpty(swaggerRouteAttribute.Name))
            {
                routeId.Name = swaggerRouteAttribute.Name;
            }
            else if (swaggerRouteAttribute.Path != null)
            {
                routeId.Method = swaggerRouteAttribute.Method;
                routeId.Path = module.ModulePath.EnsureForwardSlash() + swaggerRouteAttribute.Path;
                routeId.Path = routeId.Path.Replace("//", "/");
            }

was modified to do without the else keyword into

            if (!string.IsNullOrEmpty(swaggerRouteAttribute.Name))
            {
                routeId.Name = swaggerRouteAttribute.Name;
            }
            if (swaggerRouteAttribute.Path != null)
            {
                routeId.Method = swaggerRouteAttribute.Method;
                routeId.Path = module.ModulePath.EnsureForwardSlash() + swaggerRouteAttribute.Path;
                routeId.Path = routeId.Path.Replace("//", "/");
            }

it would work as expected

  • Version: 2.2.53-alpha
  • Project:
  • Platform:
  • Subsystem:
@jnallard
Copy link
Collaborator

[Route(HttpMethod.Get, "/test/{param}")] doesn't work as a Custom path, but actually is an alternative to mapping the attributes to the Nancy route by name. You really only need to specify either one.
As a future thing, we can probably make it so it does override the path if a mapping was found by name (or at least clean up the bad examples that show both at the same time).

However, you do have a valid problem - I created #168 to fix this issue. It will remove the type parameters from the swagger paths.

And sorry for the delay!

yahehe added a commit that referenced this issue Feb 26, 2019
Removes Parameter types from generated swagger path. #166
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