-
Notifications
You must be signed in to change notification settings - Fork 113
#1351: Add missing @JsonProperty to setter methods for POJOs #1355
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
client/integration-tests/jsonproperty-getter-and-setter/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>quarkus-openapi-generator-integration-tests</artifactId> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <version>3.0.0-SNAPSHOT</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>quarkus-openapi-generator-it-jsonproperty-getter-and-setter</artifactId> | ||
| <name>Quarkus - OpenAPI Generator - Integration Tests - Client - @JsonProperty for getters and setters</name> | ||
| <description>Ensures that @JsonProperty is properly added to getters and setters</description> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.quarkiverse.openapi.generator</groupId> | ||
| <artifactId>quarkus-openapi-generator</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-junit5</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>io.quarkus</groupId> | ||
| <artifactId>quarkus-maven-plugin</artifactId> | ||
| <extensions>true</extensions> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>build</goal> | ||
| <goal>generate-code</goal> | ||
| <goal>generate-code-tests</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <profiles> | ||
| <profile> | ||
| <id>native-image</id> | ||
| <activation> | ||
| <property> | ||
| <name>native</name> | ||
| </property> | ||
| </activation> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <skipTests>${native.surefire.skip}</skipTests> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <artifactId>maven-failsafe-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>integration-test</goal> | ||
| <goal>verify</goal> | ||
| </goals> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <native.image.path> | ||
| ${project.build.directory}/${project.build.finalName}-runner | ||
| </native.image.path> | ||
| <java.util.logging.manager>org.jboss.logmanager.LogManager | ||
| </java.util.logging.manager> | ||
| <maven.home>${maven.home}</maven.home> | ||
| </systemPropertyVariables> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <properties> | ||
| <quarkus.package.type>native</quarkus.package.type> | ||
| </properties> | ||
| </profile> | ||
| </profiles> | ||
|
|
||
| </project> |
129 changes: 129 additions & 0 deletions
129
...tegration-tests/jsonproperty-getter-and-setter/src/main/openapi/jsonproperty-openapi.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| { | ||
| "openapi": "3.0.2", | ||
| "info": { | ||
| "title": "Animals - OpenAPI 3.0", | ||
| "version": "1.0.5" | ||
| }, | ||
| "servers": [ | ||
| { | ||
| "url": "/api/v3" | ||
| } | ||
| ], | ||
| "tags": [ | ||
| { | ||
| "name": "primate", | ||
| "description": "Everything about Primates" | ||
| } | ||
| ], | ||
| "paths": { | ||
| "/primate/{id}": { | ||
| "get": { | ||
| "tags": [ | ||
| "primate" | ||
| ], | ||
| "summary": "Find primate by ID", | ||
| "description": "Returns a single primate", | ||
| "operationId": "getPrimateById", | ||
| "parameters": [ | ||
| { | ||
| "name": "id", | ||
| "in": "path", | ||
| "description": "ID of primate to return", | ||
| "required": true, | ||
| "schema": { | ||
| "type": "integer", | ||
| "format": "int64" | ||
| } | ||
| } | ||
| ], | ||
| "responses": { | ||
| "200": { | ||
| "description": "successful operation", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/Primate" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "400": { | ||
| "description": "Invalid ID supplied" | ||
| }, | ||
| "404": { | ||
| "description": "Primate not found" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "components": { | ||
| "schemas": { | ||
| "Animal": { | ||
| "type": "object", | ||
| "properties": { | ||
| "born": { | ||
| "type": "string", | ||
| "description": "Dated Base extension.", | ||
| "format": "date-time" | ||
| }, | ||
| "deceased": { | ||
| "type": "string", | ||
| "description": "Dated Base extension.", | ||
| "format": "date-time" | ||
| }, | ||
| "animal_name": { | ||
| "type": "string", | ||
| "description": "Animal name" | ||
| } | ||
| }, | ||
| "xml": { | ||
| "name": "animal" | ||
| } | ||
| }, | ||
| "Mammal": { | ||
| "type": "object", | ||
| "allOf": [ { | ||
| "$ref": "#/components/schemas/Animal" | ||
| } ], | ||
| "properties": { | ||
| "gender": { | ||
| "type": "string", | ||
| "enum": [ | ||
| "female", | ||
| "male" | ||
| ] | ||
| } | ||
| }, | ||
| "xml": { | ||
| "name": "mammal" | ||
| } | ||
| }, | ||
| "Primate": { | ||
| "required": [ | ||
| "name" | ||
| ], | ||
| "type": "object", | ||
| "allOf": [ | ||
| { | ||
| "$ref": "#/components/schemas/Mammal" | ||
| } | ||
| ], | ||
| "properties": { | ||
| "id": { | ||
| "type": "integer", | ||
| "format": "int64", | ||
| "example": 10 | ||
| }, | ||
| "name": { | ||
| "type": "string", | ||
| "example": "jane doe" | ||
| } | ||
| }, | ||
| "xml": { | ||
| "name": "primate" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...ntegration-tests/jsonproperty-getter-and-setter/src/main/resources/application.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| quarkus.openapi-generator.codegen.spec.jsonproperty_openapi_yaml.base-package=org.acme.jsonproperty.gettersetter |
145 changes: 145 additions & 0 deletions
145
...etter/src/test/java/io/quarkiverse/openapi/generator/it/JsonPropertyGetterSetterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package io.quarkiverse.openapi.generator.it; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.format.DateTimeFormatterBuilder; | ||
|
|
||
| import jakarta.json.Json; | ||
| import jakarta.json.JsonObjectBuilder; | ||
|
|
||
| import org.acme.jsonproperty.gettersetter.model.Animal; | ||
| import org.acme.jsonproperty.gettersetter.model.Mammal; | ||
| import org.acme.jsonproperty.gettersetter.model.Primate; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
|
||
| import io.quarkus.test.junit.QuarkusTest; | ||
|
|
||
| @QuarkusTest | ||
| class JsonPropertyGetterSetterTest { | ||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| @BeforeAll | ||
| static void setup() { | ||
| OBJECT_MAPPER.findAndRegisterModules(); | ||
| } | ||
|
|
||
| @Test | ||
| void verifyGetterSetterWorksOnSnakeCasedFields() { | ||
| JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder(); | ||
| jsonObjectBuilder.add("animal_name", "Lion"); | ||
|
|
||
| Animal animal; | ||
| try { | ||
| animal = OBJECT_MAPPER.readValue(jsonObjectBuilder.build().toString(), Animal.class); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| assertEquals(Animal.class, animal.getClass()); | ||
| assertEquals("Lion", animal.getAnimalName()); | ||
| } | ||
|
|
||
| @Test | ||
| void verifyGetterSetterWorksOnNonSnakeCasedFields() { | ||
| JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder(); | ||
| // OffsetDateTime field to verify that non-snake-cased fields also work | ||
| jsonObjectBuilder.add("born", "2020-01-01T00:00:00Z"); | ||
|
|
||
| Animal animal; | ||
| try { | ||
| animal = OBJECT_MAPPER.readValue(jsonObjectBuilder.build().toString(), Animal.class); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| assertEquals(Animal.class, animal.getClass()); | ||
| DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendInstant().toFormatter(); | ||
| assertEquals("2020-01-01T00:00:00Z", animal.getBorn().format(formatter)); | ||
| } | ||
|
|
||
| @Test | ||
| void verifyJavaReflectionIndicatesJsonPropertyOnSettersAndGetters() { | ||
| try { | ||
| var getter = Animal.class.getMethod("getAnimalName"); | ||
| var setter = Animal.class.getMethod("setAnimalName", String.class); | ||
|
|
||
| var getterAnnotation = getter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
ameerabdallah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var setterAnnotation = setter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
|
|
||
| assertEquals("animal_name", getterAnnotation.value()); | ||
| assertEquals("animal_name", setterAnnotation.value()); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| try { | ||
| var getter = Primate.class.getMethod("getAnimalName"); | ||
| var setter = Primate.class.getMethod("setAnimalName", String.class); | ||
|
|
||
| var getterAnnotation = getter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
| var setterAnnotation = setter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
|
|
||
| assertEquals("animal_name", getterAnnotation.value()); | ||
| assertEquals("animal_name", setterAnnotation.value()); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| try { | ||
| var getter = Mammal.class.getMethod("getAnimalName"); | ||
| var setter = Mammal.class.getMethod("setAnimalName", String.class); | ||
|
|
||
| var getterAnnotation = getter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
| var setterAnnotation = setter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
|
|
||
| assertEquals("animal_name", getterAnnotation.value()); | ||
| assertEquals("animal_name", setterAnnotation.value()); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void verifyJavaReflectionIndicatesJsonPropertyOnSettersAndGettersQueryParam() { | ||
| try { | ||
| var getter = Animal.AnimalQueryParam.class.getMethod("getAnimalName"); | ||
| var setter = Animal.AnimalQueryParam.class.getMethod("setAnimalName", String.class); | ||
|
|
||
| var getterAnnotation = getter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
| var setterAnnotation = setter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
|
|
||
| assertEquals("animal_name", getterAnnotation.value()); | ||
| assertEquals("animal_name", setterAnnotation.value()); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| try { | ||
| var getter = Mammal.MammalQueryParam.class.getMethod("getAnimalName"); | ||
| var setter = Mammal.MammalQueryParam.class.getMethod("setAnimalName", String.class); | ||
|
|
||
| var getterAnnotation = getter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
| var setterAnnotation = setter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
|
|
||
| assertEquals("animal_name", getterAnnotation.value()); | ||
| assertEquals("animal_name", setterAnnotation.value()); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| try { | ||
| var getter = Primate.PrimateQueryParam.class.getMethod("getAnimalName"); | ||
| var setter = Primate.PrimateQueryParam.class.getMethod("setAnimalName", String.class); | ||
|
|
||
| var getterAnnotation = getter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
| var setterAnnotation = setter.getAnnotation(com.fasterxml.jackson.annotation.JsonProperty.class); | ||
|
|
||
| assertEquals("animal_name", getterAnnotation.value()); | ||
| assertEquals("animal_name", setterAnnotation.value()); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.