kin-openapi
kin-openapi copied to clipboard
i tried to https to http reverse proxy. then fail
export-url : https://export.example.com/api/v1 go-api-url : http://app.example.com/api/v1
Server-URL: NG : https://export.example.com/api/v1 NG : /api/v1 -> fail
So, i change to swagger data. Send to client
swagger.Servers = openapi3.Servers{
{URL: "/api/v1"},
}
send to validate middleware.
// remove servers and rewrite from relative-path to absolute-path
swagger.Servers = openapi3.Servers{}
paths := openapi3.Paths{}
for k, v := range swagger.Paths {
paths[path.Join(basePath, k)] = v
}
swagger.Paths = paths
I don't think middleware needs any Server information. Because it is not possible to know the address accessed by the user under the proxy environment.
What is the issue? Where is your issue-reproducing code? What have you tried?
frontend server:https://example.com/ -> reverse-proxy -> backend server:http://goserver/
-
OpenAPI spec request:
https://example.com/api-docs -> http://goserver/api-docs
-
pets API request:
https://example.com/v1/pets -> http://goserver/v1/pets
So. OpenAPI spec's server.url is "https://example.com/v1/".
But goserver cannot match /v1/pets.
goserver_1 | 2021/10/02 13:50:46 routeRegexp:path /v1/pets ^/v1/pets$
goserver_1 | 2021/10/02 13:50:46 methodMatcher
goserver_1 | 2021/10/02 13:50:46 schemeMatcher
goserver_1 | 2021/10/02 13:50:46 1
goserver_1 | 2021/10/02 13:50:46 2 [https] http false
goserver_1 | 2021/10/02 13:50:46 DONT MATCH [https] &{<nil> <nil> map[] <nil>}
goserver_1 | 2021/10/02 13:50:46 routeRegexp:path /v1/pets ^/v1/pets/(?P<v0>[^/]+)$
goserver_1 | 2021/10/02 13:50:46 DONT MATCH &{/v1/pets/{petId} 0 {false true} 0xc00010fae0 /v1/pets/%s [petId] [0xc00010f9a0] false} &{<nil> <nil> map[] <nil>}
sample project is follows: https://github.com/uk-taniyama/kin-openapi-issue420