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

Setting servers to nil still fails validation #987

Open
pbdeuchler opened this issue Mar 3, 2023 · 0 comments
Open

Setting servers to nil still fails validation #987

pbdeuchler opened this issue Mar 3, 2023 · 0 comments

Comments

@pbdeuchler
Copy link

When using the chi-middleware validator setting swagger.Servers = nil will fail every request.

This can be reproduced by starting a server that correctly validates hostnames (i.e. not setting swagger.Servers to nil) and properly handles requests, and then setting swagger.Servers = nil. All requests will fail.

Here is the snippet of code that works as expected:

// Versions of our API to serve
v010123Handler := v010123def.NewStrictHandler(
	// Build service interface (business logic impl)
	v010123service.NewAPI(highPrioritySQS, normalPrioritySQS),
	[]v010123def.StrictMiddlewareFunc{},
)

// Get Swagger defininition for previous version
swagger, err := v010123def.GetSwagger()
if err != nil {
	panic(fmt.Errorf("Failed to get swagger for version 010123: %w", err))
}


// swagger.Servers = nil

// This holds the various versioned API routers
handlers := map[string]http.Handler{
	"010123": v010123def.HandlerWithOptions(v010123Handler, v010123def.ChiServerOptions{
		Middlewares: []v010123def.MiddlewareFunc{
			middleware.OapiRequestValidator(swagger),
		},
	}),
}

Then, changing nothing but uncommenting out // swagger.Servers = nil will cause the server to always fail requests.

I'm having difficulty finding exactly where the bug is, as it's difficult to inject debugging code kin-openapi libraries, but everything seems to be pointing to a similar issue here: getkin/kin-openapi#740, which also found regressions in this code getkin/kin-openapi#705.

I will be bringing this up with the kin-openapi project as well, but given there were recent changes in this project around swagger.Servers being nil I wanted to ensure that the issue was filed here first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants