RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

Swagger integration error #777

Closed vdecristofaro closed 7 years ago

vdecristofaro commented 7 years ago

ASP.NET Web API 2 project deployed in multiple urls (production, staging, development)

I have integrated the Nswag by following the NSwag Tutorial: Integrate the NSwag toolchain into your ASP.NET Web API project and more specifically the Register the OWIN middlewares in your Global.asax section.

I have then deployed wverything on an internal server we use for tests.

When I first browsed the url https://api.myserver.lab/swagger/index.html?url=/swagger/v1/swagger.json I have got an error saying

Can't read from server. It may not have the appropriate access-control-origin settings.

I have then enabled CORS on my API but the error remains the same.

What i have discovered is that by browsing directly to the generated json

https://api.myserver.lab/swagger/v1/swagger.json

I get the following error

System.MissingMethodException: Method not found: 'NJsonSchema.Generation.JsonObjectTypeDescription NJsonSchema.Generation.JsonObjectTypeDescription.FromType(System.Type, System.Collections.Generic.IEnumerable`1, NJsonSchema.EnumHandling)'.

Stack trace

at NSwag.SwaggerGeneration.WebApi.Processors.OperationParameterProcessor.<ProcessAsync>d__2.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.Start[TStateMachine](TStateMachine& stateMachine) at NSwag.SwaggerGeneration.WebApi.Processors.OperationParameterProcessor.ProcessAsync(OperationProcessorContext context) at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.d13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.d12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.d11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.d9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NSwag.AspNet.Owin.SwaggerMiddleware.d__7.MoveNext() in C:\projects\nswag\src\NSwag.AspNet.Owin\SwaggerMiddleware.cs:line 67`

any suggestion?

RicoSuter commented 7 years ago

I suspect that you installed NJsonSchema v9+ with NSwag v10.6 which is not compatible (NJS v9 is used in NSwag v11)

You have to downgrade to NJS v8.33

https://www.nuget.org/packages/NSwag.Core/

vdecristofaro commented 7 years ago

This is what I have at the moment

immagine

Could you please suggest the right combination of packages? Thanks!

RicoSuter commented 7 years ago

Just downgrade njs to v8.33