yahehe / Nancy.Swagger

Nancy plugin for generated API documentation in Swagger format.
MIT License
133 stars 60 forks source link

Parameter types are not removed from route path strings #180

Open provegard opened 4 years ago

provegard commented 4 years ago

Expected Behavior

A typed parameter in a Nancy route is included without type in a route path in swagger.json.

Actual Behavior

The parameter type remains in the route path in swagger.json.

Steps to Reproduce the Problem

  1. Use a Nancy route with typed parameter like /something/{id:guid}
  2. Generate swagger.json
  3. Inspect the route path, it is /something/{id:guid}

Analysis

SwaggerRouteData contains a properly sanitized Path property, but it appears that the actual route path being used is the key of the dictionary returned by ISwaggerMetadataProvider.RetrieveSwaggerPaths, and that is the raw route path.

My workaround in a custom metadata provider:

    protected override IDictionary<string, SwaggerRouteData> RetrieveSwaggerPaths(NancyContext context)
    {
        var result = base.RetrieveSwaggerPaths(context);
        return result.Values.ToDictionary(rd => rd.Path);
    }

Specifications