Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load API definition issue #266

Closed
ljubomir-bacovic opened this issue Jun 6, 2023 · 17 comments
Closed

Failed to load API definition issue #266

ljubomir-bacovic opened this issue Jun 6, 2023 · 17 comments
Assignees

Comments

@ljubomir-bacovic
Copy link

Hello,

I successfully installed Swagger for Ocelot and it runs fine on my localhost. However, when I publish to IIS server, I get this error.

I tried to find if anyone else had the same problem, but noticed that anyone who reported this issue, had it on localhost. I am puzzled why it works locally, but not on the server?

The gateway and microservices work, I can access them normally through Postman.

@Burgyn
Copy link
Owner

Burgyn commented Jun 6, 2023

Hi @ljubomir-bacovic,

please provide more information. Some logs from your gateway, logs from browsers, ...

Thanks.

@Burgyn Burgyn added the waiting-8-days Closing after 8 days of waiting for the additional info requested. label Jun 6, 2023
@ljubomir-bacovic
Copy link
Author

The log from gateway:

RequestPath: /swagger/docs/v1/scheduling

An unhandled exception has occurred while executing the request.

Exception:
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at System.Net.Http.HttpClient.GetStringAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at MMLib.SwaggerForOcelot.Repositories.DownstreamSwaggerDocsRepository.GetSwaggerJsonAsync(RouteOptions route, SwaggerEndPointOptions endPoint, String docsVersion)
at MMLib.SwaggerForOcelot.Middleware.SwaggerForOcelotMiddleware.Invoke(HttpContext context, ISwaggerEndPointProvider swaggerEndPointRepository, IDownstreamSwaggerDocsRepository downstreamSwaggerDocs)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

@github-actions github-actions bot removed the waiting-8-days Closing after 8 days of waiting for the additional info requested. label Jun 6, 2023
@ljubomir-bacovic
Copy link
Author

Browser just shows 500 error fetching API definition.

image

@Burgyn
Copy link
Owner

Burgyn commented Jun 6, 2023

This is still very general. Please provide your gateway configuration and try to explain how you host in IIS.

If you use Virtual directories look here: https://github.com/Burgyn/MMLib.SwaggerForOcelot#virtual-directory

Thank you.

@ljubomir-bacovic
Copy link
Author

I don't use virtual directory. At this point, I host two sites, Gateway, which is publicly accessible through https, and one microservice that is accessed by gateway via http at the port 5001.

@ljubomir-bacovic
Copy link
Author

My gateway configuration:

{
"Routes": [
{
"UpstreamPathTemplate": "/api/scheduling/{everything}",
"UpstreamHttpMethod": [
"GET",
"POST",
"PUT",
"DELETE"
],
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "http",
"SwaggerKey": "scheduling",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5001
}
]
}
]
}

@ljubomir-bacovic
Copy link
Author

Swagger endpoints:

{
"SwaggerEndPoints": [
{
"Key": "scheduling",
"Config": [
{
"Name": "MyCorp.Services.Scheduling.API",
"Version": "v1",
"Url": "http://localhost:5001/swagger/v1/swagger.json"
}
]
}
]
}

@ljubomir-bacovic
Copy link
Author

@Burgyn any idea?

@Burgyn
Copy link
Owner

Burgyn commented Jun 7, 2023

At the moment, I can't think of anything you might have a problem with. It normally works on IIS. Please check all addresses and ports to see if they match. Also check the logs in the browser (network tab) to see what kind of query the SwaggerUI is sending internally, if there has been any change in the base address.

@ljubomir-bacovic
Copy link
Author

This is my Network tab

image

@Burgyn
Copy link
Owner

Burgyn commented Jun 7, 2023

Hey @ljubomir-bacovic .

I really want to help you, but without relevant information and your proper investigation it will not work.

Check all logs and configurations properly (ocelot.json and Startup.cs).
Check if you can get the swagger.json for the downstream service directly through the browser http://localhost:5001/swagger/v1/swagger.json
...

Friendly advice. If you are asking for help somewhere then really try to give as much information which can help. Also try to format things sensibly. If something is code (even JSON) then format it as code until you can read things. Thank you very much. See markdown docs

@ljubomir-bacovic
Copy link
Author

@Burgyn

I tried to explain as much as I could. Also, I spent two full days investigating this issue and trying to understand it. There is not much information online, since locally everything works perfectly when I start from Visual Studio. Also, the gateway and the API work on the server as well, we use them to develop frontend. But we would like to have Swagger deployed, so that the frontend team can understand the API better.

@Burgyn
Copy link
Owner

Burgyn commented Jun 7, 2023

From this url http://localhost:5001/swagger/v1/swagger.json you get correct swagger.json? If so, try looking at the logs from the gateway to see what address it was trying to forward it to.

I can't help more. So far I haven't had a problem with IIS.

@ljubomir-bacovic
Copy link
Author

No, when I try this on the server, I get 404 error.

@ljubomir-bacovic
Copy link
Author

So that means that the issue is that Swagger is not working on API level. I will try to investigate that.

@ljubomir-bacovic
Copy link
Author

Yes, that was the issue. Thanks a lot for your help. It works like a charm now!

@Burgyn
Copy link
Owner

Burgyn commented Jun 8, 2023

That's good to hear.

@Burgyn Burgyn closed this as completed Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants