-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
CRDGenerator: Cannot specify @Pattern
annotation on type parameter
#6282
Comments
That seems to be relatively unsupported in Jackson v2 - https://groups.google.com/g/jackson-user/c/f7ZTj-0PFDQ and indeed with the annotation modified, I don't see the annotation in the type information provided to the JSONSchema when poking around in the debugger. There would need to be additional introspection, potentially based upon some hacks like the collectValidationRules method.
The v2 CRD generator will produce string for the following:
However the Pattern is still not associated because it is not seen by jackson as being associated with the parent field. If the beanProperty is a collection, and the collection type is string, but the collection class is not java.lang.String we can use: beanProperty.getType().getContentType().getRawClass().getAnnotation(Pattern.class) to find the nested annotation with this convention. However I agree it's not ideal to have this type of workaround. |
closes: fabric8io#6282 Signed-off-by: Steve Hawkins <[email protected]>
closes: fabric8io#6282 Signed-off-by: Steve Hawkins <[email protected]>
closes: fabric8io#6282 Signed-off-by: Steve Hawkins <[email protected]>
closes: fabric8io#6282 Signed-off-by: Steve Hawkins <[email protected]>
@Pattern
annotation on type parameter@Pattern
annotation on type parameter
Is your enhancement related to a problem? Please describe
Consider the following field in a CRD class:
What I would like to be able to add the
@io.fabric8.generator.annotation.Pattern
annotation so that the Kubernetes API server can validate that the elements of the array match the pattern.Adding the annotation to the field itself causes the following JSONSchema to be created, which is not what I want:
Describe the solution you'd like
I'd like to declare the validation constraint as follows:
And have that generate the following JSONSchema:
This can be achieved by changing the
@Target
on@Pattern
to includeElementType.TYPE_USE
, and detecting the presence of the annotation on the type parameters in the declaration to include thepattern
constraint.Describe alternatives you've considered
I've tried various ways to "trick" Fabric8 into letting me put the
pattern
constraint in the correct place, and nothing has worked.I tried creating a wrapper class for the string that I can attach the annotation to:
Unfortunately, the CRD generator does not detect that this class is supposed to be serialized as a string.
The other alternative would be to just have a normal wrapper object that I can attach the annotation to, but that would create gratuitous nesting of properties that I do not want.
Additional context
No response
The text was updated successfully, but these errors were encountered: