Stephan Hoffmann
Stephan Hoffmann

Reputation: 311

Swagger not functioning when run through APIGEE

I've got an ASP.NET Web API Core 2 project, that uses Swashbuckle.AspNetCore nuget to add swagger UI to my solution. When I run this in debugger or hosting it in IIS, swagger UI comes up nicely and it all works as expected.

But when I put a proxy for my web site into APIGEE, it comes up with

Fetch error Not Found /swagger/v1/swagger.json

Here are the relevant pieces of my project

services.AddSwaggerGen(c => {
    c.SwaggerDoc("v1", new Info {
        Version = "v1",
            Title = "My Web API",
            Description = "An awesome API.",
            TermsOfService = "",
            Contact = new Contact {
                Name = "...",
                    Email = "...",
                    Url = "http://..."
            }
    });
});
services.AddSwaggerGen(c => { c.IncludeXmlComments(GetXmlCommentsPath("Project1.xml")); });
services.AddSwaggerGen(c => { c.IncludeXmlComments(GetXmlCommentsPath("Project2.xml")); });

and

app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Web API v1"); });

How can I enable swagger to work when its run through APIGEE?

UPDATE
The debug console shows an error.

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(XHR) GET - https://mysite.apigee.net/swagger/v1/swagger.json

It has dropped the site path completely. When I added

app.UseSwaggerUI(c => { c.SwaggerEndpoint("../swagger/v1/swagger.json", "My Web API v1"); });

it swagger UI comes up, but the calls it can make are now dropping the site prefix. For example,

https://mysite.apigee.net/myapp/about becomes https://mysite.apigee.net/about

What should happen is

https://mysite.apigee.net/myapp/swagger brings up the swagger ui
https://mysite.apigee.net/myapp/swagger/v1/swagger.json gets me the JSON
https://mysite.apigee.net/myapp/about calls my normal endpoints.

Its only the first that doesnt work, which looks in the wrong place.

Upvotes: 0

Views: 1064

Answers (1)

Eric Abraham
Eric Abraham

Reputation: 21

I was having the same issue. You need to add your Apigee base path to the Swagger Endpoint. In this example "myapp" is the base path. I also had to do a Ctrl + F5 on my Chrome browser to reload the page to see the change.

app.UseSwaggerUI(c => { c.SwaggerEndpoint("/myapp/swagger/v1/swagger.json", "My Web API v1"); });

Upvotes: 2

Related Questions