Open LucasMoffitt opened 6 years ago
@LucasMoffitt
Could you provide more information about your sample ?
Based on your steps , I can get the result as follow ,
{
"swagger": "2.0",
"info": {
"title": "thing api",
"description": "thing.ly",
"contact": {
"url": "http://thing/support",
"email": "support@thing"
},
"version": "v1.5"
},
"paths": {
"/ping": {
"get": {
"summary": "Ping",
"description": "",
"operationId": "Ping",
"responses": {
"200": {
"description": "OK"
}
}
},
"parameters": [ ]
}
}
}
@catcherwong
Example Repo: https://github.com/LucasMoffitt/nancy.swagger.test
It's as close to the configuration I have now as possible. It's clearly an issue on my end, I just honestly can't see it. What am I doing wrong?
Get: /api-docs
Exception:
{ "statusCode": 500, "message": "Something went horribly, horribly wrong while servicing your request.", "details": "<pre>Nancy.RequestExecutionException: Oh noes! ---< Swagger.ObjectModel.Builders.RequiredFieldException: 'Paths' is required.\r\n at Swagger.ObjectModel.Builders.SwaggerRootBuilder.Build()\r\n at Nancy.Swagger.Services.SwaggerMetadataProvider.GetSwaggerJson(NancyContext context)\r\n at Nancy.Swagger.Modules.SwaggerModule.><c__DisplayClass0_0.>.ctor<b__0(Object _)\r\n at Nancy.NancyModule.><c__DisplayClass14_0'1.>Get<b__0(Object args)\r\n at Nancy.NancyModule.><c__DisplayClass16_0'1.>Get<b__0(Object args, CancellationToken ct)\r\n at Nancy.Routing.Route'1.Invoke(DynamicDictionary parameters, CancellationToken cancellationToken)\r\n at Nancy.Routing.DefaultRouteInvoker.>Invoke<d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Nancy.Routing.DefaultRequestDispatcher.>Dispatch<d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Nancy.NancyEngine.>InvokeRequestLifeCycle<d__22.MoveNext()\r\n --- End of inner exception stack trace ---\r\n at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)</pre>" }
So I've been trying for an hour and I can't seem to get your sample code to work either. The error you're seeing is what happens when there are no routes defined - my best guess is that the Container/Dependency Injector is not automatically detecting something.
However, I was able to get your module to produce the paths by using Nancy.Swagger.Annotations.
I can look into your problem more later, but in the meantime I recommend using the Annotations so this isn't blocking for you.
You'll also want to make sure you add this to your bootstrapper to clean up the misc endpoints: SwaggerAnnotationsConfig.ShowOnlyAnnotatedRoutes = true;
(It's possible that Autofac was never working with the base Nancy project, because we originally tested and created the sample using annotations)
@jnallard Thanks for validating, i've been slowly going insane.
Looking here: https://github.com/yahehe/Nancy.Swagger/blob/master/src/Nancy.Swagger/Services/DefaultSwaggerMetadataProvider.cs#L27
No metadata is available in the routeCacheProvider.GetCache().
@LucasMoffitt, thanks! My debugger in VS was really not doing what I expected today, so I didn't get too far.
If that's the case, then it makes sense that the Annotations project still works, because it doesn't use that cache to get the module information. However, I think that says that the problem doesn't exist with our library, but rather with a combination of Nancy and Autofac/Container. That cache is handled outside our domain - we were just reading it.
I can look into it more soon. Does Nancy.Swagger.Annotations suit your needs, though?
@LucasMoffitt I check your sample and find out the problem .
You need to change the name from Home
to HomeModule
, and after changing , you will get the result !
//public class Home : NancyModule
public class HomeModule : NancyModule
{
//public Home(IMediator mediator)
public HomeModule(IMediator mediator)
{
//...
}
}
For more details , you can visit DefaultMetadataModuleConventions to find more information !
Oof that's a gnarly error for such a seemingly simple thing.
We do have it documented that it should be
Thanks for your help @catcherwong and @jnallard !
Thanks for your help @catcherwong @jnallard @yahehe, appreciate it!
I've followed the instructions here and looked at the Autofac / default samples, but I still continue to get 'Path's is required:
{ "ClassName": "Swagger.ObjectModel.Builders.RequiredFieldException", "Message": "'Paths' is required.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at Swagger.ObjectModel.Builders.SwaggerRootBuilder.Build()\r\n at Nancy.Swagger.Services.SwaggerMetadataProvider.GetSwaggerJson(NancyContext context)\r\n at Nancy.Swagger.Modules.SwaggerModule.<>c__DisplayClass0_0.<.ctor>b__0(Object _)\r\n at Nancy.NancyModule.<>c__DisplayClass14_0'1.<Get>b__0(Object args)\r\n at Nancy.NancyModule.<>c__DisplayClass16_0'1.<Get>b__0(Object args, CancellationToken ct)\r\n at Nancy.Routing.Route'1.Invoke(DynamicDictionary parameters, CancellationToken cancellationToken)\r\n at Nancy.Routing.DefaultRouteInvoker.<Invoke>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Nancy.Routing.DefaultRequestDispatcher.<Dispatch>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Nancy.NancyEngine.<InvokeRequestLifeCycle>d__22.MoveNext()", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": "8\nBuild\nSwagger.ObjectModel, Version=2.2.42.0, Culture=neutral, PublicKeyToken=null\nSwagger.ObjectModel.Builders.SwaggerRootBuilder\nSwagger.ObjectModel.SwaggerRoot Build()", "HResult": -2146233079, "Source": "Swagger.ObjectModel", "WatsonBuckets": null }
I add the following to my bootstrapper:
SwaggerMetadataProvider.SetInfo("thing api", "v1.5", "thing.ly", new Contact { EmailAddress = "support@thing", Url = "http://thing/support" });
And I add names to my Nancy module routes
Get("/ping", _ => { this.RequiresAuthentication(); return HttpStatusCode.OK; }, null, "Ping");
I created a class and ensured that it'sMetadataModule and in the same namespace as "Home"
public class HomeMetadataModule : SwaggerMetadataModule { public HomeMetadataModule(ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog) : base(modelCatalog, tagCatalog) { RouteDescriber.DescribeRoute("Ping", "", "Ping", new[] { new HttpResponseMetadata {Code = 200, Message = "OK"} }); } }
I hit run, head to /api-docs and I'm still getting the 'Paths' is required message.
I'm running vs 2015 so haven't tried to debug the demos of yet.
Version: Nancy.Swagger 2.2.42-alpha