-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Make API field defaulting and validation less error-prone #25460
Comments
We talked about this today in the API SIG - there was general agreement On Wed, May 11, 2016 at 3:52 AM, Brian Grant notifications@github.com
|
I'd like to move this along in 1.5 slightly, probably by focusing on the minimal thing that would allow required / optional to be correct (not just omitempty) and allow us to validate everything around that. Now that @mbohlool has generated openapi we can rely on struct tags more. |
I have a proof of concept for a validation framework #32824. If you think we can add something to that please comment there. |
Issues go stale after 90d of inactivity. Prevent issues from auto-closing with an If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or |
/remove-lifecycle rotten I still think we need to move to declarative specifications as much as possible. cc @enisoc |
Currently it is a big pain to work with YAML and the API in most strongly typed languages, because when deserialising a YAML file into swagger-generated Model classes, missing optional scalar fields like What we would need is to expose the server default value in the schema through the JSON schema |
The inconsistency is also problematic - for example, Should all scalars with a default value be nullable or should they all be non-nullable? It's a bit cumbersome to work with a nullable type when querying the API when in reality the value will always be set because the server applies a default value. |
@apelisse I feel like we should probably close this old issue now, yes/no ? |
I don't have a strong opinion on this one. We technically don't have validation markers yet (or at least, we could have more, CEL partially covers that too, @jpbetz). |
There are frequent errors in API field specification, such as:
fsType
: https://github.com/kubernetes/kubernetes/blob/master/pkg/api/v1/types.go#L557); note that implicitly inferred is discouragedFor examples of multiple errors in one type, see:
#18885 (comment)
One way to make defaulting and validation less error prone would to be allow them to be specified declaratively, on API fields using tags or comments. Protocol buffers allow literal default values to be specified (though, unlike in Kubernetes, they aren't conveyed on the wire; non-literals, such as fields defaulted from other fields, can't be specified this way). Declarative validation, where possible (i.e., simple rules), was previously requested by #8116.
Since omitempty and pointer rules are apparently non-obvious, I think we should require specification of required vs optional and then either verify that the other properties are consistent or autogenerate them.
Auto-fixing field names in documentation is covered by #19319.
cc @lavalamp @thockin @kubernetes/sig-api-machinery
The text was updated successfully, but these errors were encountered: