简体   繁体   中英

openapi.json not found when hosting NetCore 3.1 Web Api on IIS

I generated my server stub for ASP.NET Core 3.1 using the openapi generator with the following command:

npx @openapitools/openapi-generator-cli generate -i myapi.json -g aspnetcore -o C:\\myapi --additional-properties aspnetCoreVersion=3.1

After opening that project in Visual Studio 2019 and running it I get the swagger page where I can try out the different endpoints. So far OK.

However: after publishing this on our IIS Server and visiting the proper URL that swagger page is loading with the error:

Not found: /swagger/1.0.0/openapi.json

Swagger error on IIS

The endpoint itself (GET request) can be reached.

The Swagger Endpoint code in startup.cs is the default code as it was generated by open-api generator:

app.UseSwagger(c =>
            {
                c.RouteTemplate = "swagger/{documentName}/openapi.json";
            })
            .UseSwaggerUI(c =>
            {
                //TODO: Either use the SwaggerGen generated Swagger contract (generated from C# classes)
                c.SwaggerEndpoint("/swagger/1.0.0/openapi.json", "Swagger WP RUH Delivery");

                //TODO: Or alternatively use the original Swagger contract that's included in the static files
                // c.SwaggerEndpoint("/openapi-original.json", "Swagger WP RUH Delivery Original");
            });

Why is this Swagger page working on my machine, but on IIS things go wrong? I found some hints on changing the c.SwaggerEndpoint in startup.cs, but nothing helped.

尝试从 URL 路径中删除/swagger/

c.SwaggerEndpoint("1.0.0/openapi.json", "Swagger WP RUH Delivery")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM