yahehe / Nancy.Swagger

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

NancyModule.ModulePath support #114

Closed DGuidi closed 7 years ago

DGuidi commented 7 years ago

A NancyModule can be initialized with a modulePath like

public class V1Module : NancyModule
{
  public V1Module() : base("v1") 
  {
    // init "test/get"
    // init "test/post"
  }
}

so "test/get" and "test/post" requests are actually "v1/test/get" and "v1/test/post".

I've digged into RouteDescriber and RouteBuilder but I've missed how to specify this. I am missing something?

jnallard commented 7 years ago

~~Right now, it's set in the bootstrapper, as seen in the demo: https://github.com/yahehe/Nancy.Swagger/blob/master/samples/Nancy.Swagger.Demo/Bootstrapper.cs#L15~~

(We should probably add something to allow it to be over-written, in case people want to document different versions of a route)

yahehe commented 7 years ago

This should be handled automatically? I have a service with different versions for endpoints and I see the version picked up without additional setup

DGuidi commented 7 years ago

I have a service with different versions for endpoints and I see the version picked up without additional setup

This looks different to me: endpoinds (correct me if I'm wrong) are configured when boostrapping service, so you have some modules used only when your request matches certains constans. I've made similar things with Nancy+Owin, like:

app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments(new PathString("api")),

so your module "v1/test/get" is actually "api/v1/test/get"... this is fine, and actually swaggermodule too listen to "api/api-docs".

ModulePath looks different to me: is used when creating a module - used in constructor in my sample - and appears in nancy route but not in swagger metadata route.

jnallard commented 7 years ago

@yahehe You're right. Disregard my earlier statement.

Nancy.Swagger just grabs the route from Nancy.Routing, I believe. https://github.com/yahehe/Nancy.Swagger/blob/master/src/Nancy.Swagger/Services/DefaultSwaggerMetadataProvider.cs#L35

I could look into whether we could find that data, but that might be difficult. Thought I guess we could also add a way to override the automatically generated paths. But as we said before, we're not actively developing for the 1.4.3 stable branch. So I would recommend updating if possible. Otherwise, we would need to make sure to add whatever we change to both branches.

yahehe commented 7 years ago

If you're talking about adding a basePath then what Josh said is correct. If you're talking about swagger picking up the inherited routes from parent modules then that already happens in 1.4.3 (apparently my service runs 1.4.3). If you have complex routing logic that should still be captured normally

DGuidi commented 7 years ago

If you're talking about swagger picking up the inherited routes from parent modules

nope, I talk about what @jnallard said, he point exactly where I see the "problem", metadata provider build routes from Nancy.RouteDescriptor, that doesn't contain ModulePath information.

but as we said before, we're not actively developing for the 1.4.3 stable branch

yep, maybe if you fix master branch, I can try to fix 1.4.3 one

DGuidi commented 7 years ago

sorry guys, I made a mistake. all is fine, I'm simply dumb and I've missed a check in my code. sorry, again, for the time loss. screenshot_1