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
feat: add annotation @PreserveUnknownFields for field #4398
Conversation
Signed-off-by: wineway <wangyuweihx@gmail.com>
As much as I'm unhappy adding yet another way to emit Just one more question: have you considered extending |
side note: you can run |
Signed-off-by: wineway <wangyuweihx@gmail.com>
Hmmm. I think this could be just a not so good workaround, it destroyed the inheritance and did not work for the sealed interface. boolean preserveUnknownFields = (definition.getFullyQualifiedName() != null &&
definition.getFullyQualifiedName().equals(JSON_NODE_TYPE)); More than this, it seems that it won't check if the type of the field extends |
@wineway thanks for the argument, you can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments and one question, have you attempted to refactor the code such as we can setXKubernetesPreserveUnknownFields
in only one place instead of two in the JsonSchema
classes?
Thanks a lot!
CHANGELOG.md
Outdated
@@ -11,6 +11,7 @@ | |||
* Fix #4383: bump snakeyaml from 1.30 to 1.31 | |||
|
|||
#### New Features | |||
* Feat: add annotation @PreserveUnknownFields for generation field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please expand a little this sentence, for example saying that it affects the crd-generator
@@ -352,6 +362,7 @@ private static class PropertyOrAccessor { | |||
private boolean required; | |||
private boolean ignored; | |||
private boolean preserveUnknownFields; | |||
private boolean preserveSelfUnknownFields; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need an extra field here?
Is it possible to rely on the already existing preserveUnknownFields
?
import java.lang.annotation.*; | ||
|
||
/* | ||
* Used to tweak the behavior of the crd-generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like to emit 'x-kubernetes-preserve-unknown-fields'
doc/CRD-generator.md
Outdated
@@ -357,6 +357,28 @@ Corresponding `x-kubernetes-preserve-unknown-fields: true` will be generated in | |||
x-kubernetes-preserve-unknown-fields: true | |||
``` | |||
|
|||
You can also annotation a field with @PreserveUnknownFields: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you, please, add the annotation to the cheatsheet
below.
doc/CRD-generator.md
Outdated
@@ -357,6 +357,28 @@ Corresponding `x-kubernetes-preserve-unknown-fields: true` will be generated in | |||
x-kubernetes-preserve-unknown-fields: true | |||
``` | |||
|
|||
You can also annotation a field with @PreserveUnknownFields: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also s/annotation/annotate/ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also s/annotation/annotate/ ?
sorry I can't find where it is, can I ask for help😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace annotation
with annotate
so that the sentence reads:
You can also annotate a field with @PreserveUnknownFields:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace
annotation
withannotate
so that the sentence reads:
sorry😂……fixed
I have tried, but I'm afraid I can't refactor the two fields to one in limited code change. if I just separate |
Signed-off-by: wineway <wangyuweihx@gmail.com>
SonarCloud Quality Gate failed. |
Signed-off-by: wineway wangyuweihx@gmail.com
Description
like #4313, we need to use a sealed interface as a field type and offer multi implementations for this interface, it seems we can't and don't need to validate its fields in this situation, and we don't want to add something like @JsonAnyGetter might change its serialize behavior. so we think we can add a new annotation
@PreserveUnknownFields
for this scenario.Type of change
test, version modification, documentation, etc.)
Checklist