-
Notifications
You must be signed in to change notification settings - Fork 209
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
Generated enum fails validation when used for CRD creation #395
Comments
So you're using the test code to make a CRD and the CRD is invalid? From a very cursory look, that seems normal and expected, but the examples included in the tests should probably be valid. Alternative, we could also detect if the default is not part of the enum at generation time, and fail at that time, that'd probably be better. |
I'm using code generated by kube-openapi with an enum to make a CRD and the CRD can't be made for having an invalid default value, because the default zero value is not one of the enum values. I didn't provide the default value and the generator chose a zero value based on datatype. The example included in tests is not valid for the same reason, and that's why I showcased it using the example in tests. |
Looked at it again. It looks like the value is REQUIRED anyway, the default is kind of forced because the field is not a pointer, so I would say this works as expected. There's not really any other great way to do that. |
Uhm I worked around it by removing the |
Yeah, that's a little weird I agree. Also not entirely sure depending on your exact situation. (though required should ALWAYS be respected tbh). |
Can we have the default value use the first enum value then? |
IMO the schema is invalid if the default value wouldn’t pass validation itself. The schema generator should throw an error for that |
yeah, I don't think that's wrong. I'm not exactly sure why we have a default here, I need to double check. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
kube-openapi/pkg/generators/openapi_test.go
Line 1618 in 7828149
This shows an example of generated code:
kube-openapi/pkg/generators/openapi_test.go
Lines 1655 to 1662 in 7828149
However if we use this code to generate CRD it fails validation. The error message is like:
The text was updated successfully, but these errors were encountered: