0

I am upgrading my api from netcore2.1 to 3.1

When I run on localhost the UI works fine.

When I deploy via Azure DevOps and go to the myapplication/myapi/swagger.html url I get

Failed to load API definition 
Fetch Error
Service Unavailable /myapi/swagger/v1/swagger/json

Yet I can see the json at

myapplication/myapi/swagger/v1/swagger.json

I have the following

   public static IApplicationBuilder UseSwaggerDocumentation(this IApplicationBuilder app)
    {
        app.UseSwagger(c =>

            c.RouteTemplate = "myapi/swagger/{documentName}/swagger.json"
        );

        app.UseSwaggerUI(c =>
        {

            c.SwaggerEndpoint("/myapi/swagger/v1/swagger.json", "Versioned API v1.0");

            c.RoutePrefix = "myapi/swagger";

        });

        return app;
    }

I am using

Swashbuckle.AspNetCore (5.2.0)
Kirsten
  • 15,730
  • 41
  • 179
  • 318

1 Answers1

1

I found the following worked.

    public static IApplicationBuilder UseSwaggerDocumentation(this IApplicationBuilder app)
    {
        app.UseSwagger(c =>

            c.RouteTemplate = "myapi/{documentName}/swagger.json"
        );

        app.UseSwaggerUI(c =>
        {

            c.SwaggerEndpoint("./v1/swagger.json", "Versioned API v1.0");

            c.RoutePrefix = "myapi";

        });

        return app;
    }

The docs state

If using directories with IIS or a reverse proxy, set the Swagger endpoint to a relative path using the ./ prefix. For example, ./swagger/v1/swagger.json. Using /swagger/v1/swagger.json instructs the app to look for the JSON file at the true root of the URL (plus the route prefix, if used). For example, use http://localhost://swagger/v1/swagger.json instead of http://localhost:///swagger/v1/swagger.json.

However unfortunately my solution doesn't work with Autorest. Thus I asked another question

Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • Thanks Lance I feel like I am wrestling an octopus. As soon as I get something working other things fail. Thus I dont want to mark this as answered just yet, – Kirsten Mar 25 '20 at 18:17
  • I asked for more help at https://stackoverflow.com/questions/60819169/fatal-operationid-is-required-for-all-operations-please-add-it-for-get-opera – Kirsten Mar 25 '20 at 20:24
  • https://stackoverflow.com/questions/60861020/failed-resolving-swagger-json-against-file – Kirsten Mar 26 '20 at 04:28