-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Default value for attribute 'type' not specified #1388
Comments
It does not appear to be defined by the JSON Schema standard, but I believe these rules for type inference are valid and used by other tools: https://github.com/json-schema-faker/json-schema-faker#inferred-types |
It would be good if this was specified in the spec since this behaviour is already used in the wild. |
JSON Schema does not specify this because JSON Schema keywords do not have type implications. They work the other way around. If you have a schema like this: {
"required": ["foo"],
"minItems": 4
} Then This may seem counter-intuitive, and this specific example would be strange to encounter, but it makes a lot more sense when you think about |
@handrews granted, but as OpenAPI doesn't allow for |
Does that mean it is likely a mistake of the open api spec of Kubernetes that it omits so many type attributes? Should the rest of the open api tooling world actually reject specs not having type attributes? |
|
It means it's possible that the schema objects in the Kubernetes OpenAPI definition validate too loosely. It doesn't make it an invalid definition. The type inference rules I linked above are used in at least two projects I know of where example data is generated from a schema object, but they should probably not be used to tighten validation. If you are trying to generate types for a statically-typed language from the schema objects, you may have no choice though.
No, not unless the specification is changed to make |
Ok, so the real bug is with swagger2 which apparently requires a type attribute for definition objects. Still it might be an unfortunate choice not to provide a type in the Kubernetes Spec. |
It looks like this issue can be closed. As for the Kubernetes definition - it really depends on what their API accepts, and I know they had to work within some of the limitations of 2.0. |
I still hold out hope that OpenAPI will support something like
which would have exactly the same implications as the current |
@handrews But then you'd get people doing "type:" ["null", "null"] 😃 |
Oh FFS... ;-)
or even just
Satisfied? :-P |
Apparently there exists defaulting logic for the attribute 'type' of 'definitions' to 'object' (at least in case there are properties specified)
Unfortunately this is not part of the spec (or I couldn't find it) so that there are tools that are not aware of this. E.g. https://hackage.haskell.org/package/swagger2
The Kubernetes OpenAPI spec at https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json does not specify types explicitly, swagger2 cannot parse it because it expects explicit types to be specified. Swagger-cli validates the same spec successfully.
I will open a bug in the related repo as well and will provide a link here as soon as it exists. GetShopTV/swagger2#131
The text was updated successfully, but these errors were encountered: