rbeauchamp / Swashbuckle.OData

Extends Swashbuckle with OData v4 support!
Other
129 stars 96 forks source link

Unable to generate Swagger documentation #133

Closed hpanchal18 closed 7 years ago

hpanchal18 commented 7 years ago

Hello,

We have IIS Hosted WebAPI project that has routes generated for WebAPI controller as well as oData controller. we are trying to generate documentation for the WebAPI for both type of controller using swashbucle.oData. I have added reference to the nuGet Packges and compiling the code too. but i see following 2 problems.

  1. we are expecting to generate Swagger.Json documentation using the controllers. but that file is not getting generated.
  2. when we try to use swagger UI (http://localhost/MyAPI/swagger/Docs/V1) in browser we see following exception.

i have following questions:

  1. At what point of time Swagger.json will be geenrated? during compile time of project or when someone try to access documenation for the first time using route?

  2. can we document both type of routes (web API ) and oData controller routes added through mapOdataRoutes method?

Any help resolving the issue will be appreciated.


An error has occurred. Object reference not set to an instance of an object. System.NullReferenceException at Swashbuckle.Application.SwaggerDocsConfig.GetSwaggerProvider(HttpRequestMessage swaggerRequest) at Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.<>c__DisplayClass4.b__1() at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync[TResult](ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Func`1 execute, Action`2 endTrace, Action`1 errorTrace) at System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.HttpServer.d__0.MoveNext()
hpanchal18 commented 7 years ago

I tired following that solve my issue.

Removed all ShwashBuckle references from project. Added SwashBuckle to the project First. Recompile the project and i started seeing Routes that are defined using WebAPI controller.

Added SwashBuckle.oData to the project next. Added oDataSwaggerProvider to swagger.config as following

c.CustomProvider(defaultProvider => new ODataSwaggerProvider(defaultProvider, c, GlobalConfiguration.Configuration).Configure(odataConfig => { // Set this flag to include navigation properties in your entity swagger models // //odataConfig.IncludeNavigationProperties(); }));

Recompile project and was able to generated documentation for Routes that are defined using oDataController and WebAPI Controller both.

9Rune5 commented 7 years ago

Thanks. The docs mention "SwaggerConfig", but it wasn't clear (to me atleast!) that there is an actual SwaggerConfig.cs file in the project.

Still doesn't work for me, but at least I got Swagger docs for other non-OData controllers now.