Cannot disable server name validation if the servers array includes a base path.
According to #882 , setting swagger.Servers = nil skips the server name matching, but the problem is if for example one has a base path in the server url entry (for example the petstore) it causes that all the routes return no matching operation was found.
In my case this is my server array and a path:
servers:
- url: 'http://localhost:8000/apis/myapp/v1'
paths:
"/health/live":
...
Calling http://localhost:8000/apis/myapp/v1/health/live fails if Servers is nil. I tried to debug and found that it tries to match /apis/myapp/v1/health/live (the request) with ^/health/live$ (the route).
Maybe doing Servers = nil is a bad idea as it drops critical information (the base path), so another way should be implemented.
I have the same issue, if I want to use some prefix on stage server:
servers:
- url: "https://stg.myserver/api/v1/"
paths:
/health:
...
I catch 404 if run local and fetch http://localhost:8080/v1/health
Generally its just better to use the base url in the servers section.
Since in case of future versions of the APIs, the paths do change quite often.
Also in case you have a swagger UI, there is clear distinction between the v1 and v2 APIs in the individual paths themselves.
I fixed it by using this where "/api/v1" is your prefix
swagger.Servers = openapi3.Servers{&openapi3.Server{URL: "/api/v1"}}
swagger.Servers = openapi3.Servers{&openapi3.Server{URL: "/api/v1"}}
Lord and saviour 🙏.
Maybe this should be added to the documentation somewhere. This wasted quite a bit of my time until I found this thread.
Maybe this should be added to the documentation somewhere. This wasted quite a bit of my time until I found this thread.
Same.