servers:
- url: https://{hostPort}/v{version}
x-ogen-server-name: development
variables:
version:
description: API version
default: UNKNOWN # Ogen requires a dummy default here
hostPort:
description: Host and port
default: UNKNOWN # Ogen requires a dummy default here
This will generate the following validation code:
func (s DevelopmentServer) Build() (string, error) {
zeroOr := func(s string, def string) string {
if s == "" {
return def
}
return s
}
s.HostPort = zeroOr(s.HostPort, "UNKNOWN")
// Validate "hostPort"
switch s.HostPort {
default:
return "", errors.Errorf("param %q: unexpected value %q", "hostPort", s.HostPort)
}
...
This means it's not possible to create structs with arbitrary data:
Given a server list like this:
This will generate the following validation code:
This means it's not possible to create structs with arbitrary data:
as this will fail with:
This is in violation of the OpenAPI spec, which says the
enum
is optional (emphasis mine):The validation template should just skip non-set values, e.g.: