-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
[Spring] Add JsonProperty access=READ_ONLY for readOnly properties #24929
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: ReadOnly Properties Test | ||
| version: 1.0.0 | ||
| paths: | ||
| /users: | ||
| get: | ||
| operationId: getUsers | ||
| responses: | ||
| '200': | ||
| description: Success | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/User' | ||
|
|
||
| components: | ||
| schemas: | ||
| User: | ||
| type: object | ||
| properties: | ||
| id: | ||
| type: string | ||
| description: Unique identifier | ||
| readOnly: true | ||
| createdAt: | ||
| type: string | ||
| format: date-time | ||
| description: Creation timestamp | ||
| readOnly: true | ||
| username: | ||
| type: string | ||
| description: User's login name | ||
| email: | ||
| type: string | ||
| format: email | ||
| description: User's email address | ||
| required: | ||
| - username | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,12 +39,12 @@ public HasOnlyReadOnlyDto bar(@Nullable String bar) { | |
| * @return bar | ||
| */ | ||
|
|
||
| @JsonProperty("bar") | ||
| @JsonProperty(value = "bar", access = JsonProperty.Access.READ_ONLY) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Jackson Prompt for AI agents |
||
| public @Nullable String getBar() { | ||
| return bar; | ||
| } | ||
|
|
||
| @JsonProperty("bar") | ||
| @JsonProperty(value = "bar", access = JsonProperty.Access.READ_ONLY) | ||
| public void setBar(@Nullable String bar) { | ||
| this.bar = bar; | ||
| } | ||
|
|
@@ -59,12 +59,12 @@ public HasOnlyReadOnlyDto foo(@Nullable String foo) { | |
| * @return foo | ||
| */ | ||
|
|
||
| @JsonProperty("foo") | ||
| @JsonProperty(value = "foo", access = JsonProperty.Access.READ_ONLY) | ||
| public @Nullable String getFoo() { | ||
| return foo; | ||
| } | ||
|
|
||
| @JsonProperty("foo") | ||
| @JsonProperty(value = "foo", access = JsonProperty.Access.READ_ONLY) | ||
| public void setFoo(@Nullable String foo) { | ||
| this.foo = foo; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,12 +39,12 @@ public HasOnlyReadOnlyDto bar(@Nullable String bar) { | |
| * @return bar | ||
| */ | ||
|
|
||
| @JsonProperty("bar") | ||
| @JsonProperty(value = "bar", access = JsonProperty.Access.READ_ONLY) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: For these Spring CLIENT models the shared READ_ONLY setter change prevents Jackson from deserializing readOnly fields, so the client silently receives null for server-generated values (e.g. IDs) in API responses. OpenAPI readOnly means 'may be sent in responses but should not be sent in requests', so a client must still be able to read these fields. Gate the READ_ONLY emission to server-side generators only, or apply it only where the model is used for request deserialization. Prompt for AI agents |
||
| public @Nullable String getBar() { | ||
| return bar; | ||
| } | ||
|
|
||
| @JsonProperty("bar") | ||
| @JsonProperty(value = "bar", access = JsonProperty.Access.READ_ONLY) | ||
| public void setBar(@Nullable String bar) { | ||
| this.bar = bar; | ||
| } | ||
|
|
@@ -59,12 +59,12 @@ public HasOnlyReadOnlyDto foo(@Nullable String foo) { | |
| * @return foo | ||
| */ | ||
|
|
||
| @JsonProperty("foo") | ||
| @JsonProperty(value = "foo", access = JsonProperty.Access.READ_ONLY) | ||
| public @Nullable String getFoo() { | ||
| return foo; | ||
| } | ||
|
|
||
| @JsonProperty("foo") | ||
| @JsonProperty(value = "foo", access = JsonProperty.Access.READ_ONLY) | ||
| public void setFoo(@Nullable String foo) { | ||
| this.foo = foo; | ||
| } | ||
|
|
||
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.
P2: This template change alters generated output for every readOnly property in existing Spring samples, but no samples were regenerated. The committed samples (e.g. samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/model/HasOnlyReadOnlyDto.java, which currently emits
@JsonProperty("bar")for its readOnly fields) will now produce@JsonProperty(value = "bar", access = JsonProperty.Access.READ_ONLY), so the sample-verification CI will fail. Regenerate the affected Spring samples (./bin/generate-samples.sh for the spring configs) as part of this PR.Prompt for AI agents