redoc: Failed to fetch .net core api swagger.json

I used.Net core API, and installed swagger plug-ins, I configured everything, and able to.

Normal access to the api/swagger address saw the swagger interface, and I started using your redoc to build my API introduction site, but when I introduced my http://{myuri}/swagger.json file, it always burst out `Something went wrong… Error downloading http://xxx/swagger/v1/swagger.json Failed to fetch Stack trace Error: Error downloading http://xxxxx/swagger/v1/swagger.json Failed to fetch at https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js:40:15553 at https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js:118:101808 at <anonymous>

TypeError: Failed to fetch

ReDoc Version: 2.0.0-alpha.17 Commit: de177a0`

I can normally open this http://xxx/swagger/v1/swagger.json address through browser and get content. But I don’t know why, because I’m a swagger document that is automatically generated through the swagger plug-in, so my document is theoretically completely consistent with the OpenAPI protocol.

can you help me

The following is the code of my.Net core related to the use of swagger

`services.AddSwaggerGen(c => { c.SwaggerDoc(“v1”, new Info { Title = “xxx API”, Version = “v1” }); //开启swagger对FluentValidation的支持 c.AddFluentValidationRules(); // Set the comments path for the Swagger JSON and UI. var basePath = AppContext.BaseDirectory; var xmlPath = Path.Combine(basePath, “xxxx.WebApi.xml”); c.IncludeXmlComments(xmlPath);

            //支持bearer token https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/603
            c.AddSecurityDefinition(Bearer, new ApiKeyScheme
            {
                In = "header",
                Description = "Please insert JWT with Bearer into field",
                Name = "Authorization",
                Type = "apiKey"
            });

            c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
            {
                {Bearer, new string[] { }}
            });

            c.OperationFilter<FormFileOperationFilter>();
        });`

`// Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger();

        // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
        app.UseSwaggerUI(c => { c.SwaggerEndpoint("../swagger/v1/swagger.json", "My API V1"); });`

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

Something is wrong with your setup. Maybe CORS is misconfigured. this is not an issue of redoc

Because you named your Swagger Docs “V1”, you should add it in app.SwaggerEndpoint() too:

app.UseSwaggerUI(c => c.SwaggerEndpoint(“/swagger/V1/swagger.json”, “Api”));

To see the effettive problem try to navigate directly to

https://localhost:port/swagger/v1/swagger.json

and analyze the output.

In case someone else gets the same error, I cloned an API endpoint and forgot to update the route (had a duplicate) and swagger was giving this helpful error message… corrected the route and the error disappeared.

To see the effettive problem try to navigate directly to

https://localhost:port/swagger/v1/swagger.json

and analyze the output.

Man, thx so much ! This way i could see what was happening

MissingMethodException: Method not found: ‘Void Microsoft.OpenApi.Writers.OpenApiJsonWriter…ctor(System.IO.TextWriter)’. Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.RespondWithSwaggerJson(HttpResponse response, OpenApiDocument swagger) System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine stateMachine) System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<TStateMachine>(ref TStateMachine stateMachine) Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.RespondWithSwaggerJson(HttpResponse response, OpenApiDocument swagger) Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I had also just encountered this error, it was because I copied a method from another API controller, and forgot to add the Http method and route

[SOLVED] The cause might be missing Http Method Annotation in Controller method

None of the previous worked for me when i upgraded to swashbuckle 5.4 (and Microsoft.OpenApi to 1.2 preview 3).

What did work was reverting Microsoft.OpenApi back to 1.1.4.

Hope this fix works for you.