From e93c8c96cd4c1bfe8ff1b8022d8bdc1ec606cebf Mon Sep 17 00:00:00 2001 From: Dmitry Shohov Date: Thu, 16 May 2024 13:43:09 +0300 Subject: [PATCH 1/2] BigDecimal value fix in enums (#715) --- .../libraries/microprofile/enumClass.qute | 2 +- .../src/main/openapi/enum-property.yaml | 28 ++++++++++++++++++- .../generator/it/EnumPropertyTest.java | 13 +++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute b/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute index 6720cf67..e6718550 100644 --- a/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute +++ b/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute @@ -7,7 +7,7 @@ {#if e.withXml} {#for v in e.allowableValues.enumVars}@XmlEnumValue({#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}{v.value}{#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}) {v.name}({#if e.isEnum}{e.items.dataType}{#else}{e.dataType}{/if}.valueOf({v.value})){#if v_hasNext}, {#else}; {/if}{/for} {#else} - {#for v in e.allowableValues.enumVars}{v.name}({#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if}.valueOf({v.value})){#if v_hasNext}, {#else};{/if}{/for} + {#for v in e.allowableValues.enumVars}{v.name}({#if eq e.dataType "BigDecimal"}{v.value}{#else}{#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if}.valueOf({v.value}){/if}){#if v_hasNext}, {#else};{/if}{/for} {/if} {/if} diff --git a/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml b/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml index fedc438f..6797e214 100644 --- a/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml +++ b/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml @@ -20,6 +20,22 @@ paths: application/json: schema: $ref: '#/components/schemas/Echo' + /echo/num: + post: + summary: Echo Number + operationId: echo_num + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/MessageNum" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Echo' components: schemas: Echo: @@ -35,4 +51,14 @@ components: msgType: type: string enum: - - 'text' \ No newline at end of file + - 'text' + MessageNum: + type: object + required: + - msgType + properties: + msgType: + type: number + enum: + - 1 + - 2 \ No newline at end of file diff --git a/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java b/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java index 1bc3085b..3b98e413 100644 --- a/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java +++ b/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java @@ -15,6 +15,7 @@ import org.openapi.quarkus.enum_property_yaml.api.DefaultApi; import org.openapi.quarkus.enum_property_yaml.model.Echo; import org.openapi.quarkus.enum_property_yaml.model.Message; +import org.openapi.quarkus.enum_property_yaml.model.MessageNum; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; @@ -36,11 +37,16 @@ class EnumPropertyTest { void apiIsBeingGenerated() { var message = new Message(); message.setMsgType(Message.MsgTypeEnum.TEXT); + var messageNum = new MessageNum(); + messageNum.setMsgType(MessageNum.MsgTypeEnum.NUMBER_1); Echo echo = api.echo(message); + Echo echoNum = api.echoNum(messageNum); assertThat(echo.getEchoedMsgType()) .isEqualTo("text"); + assertThat(echoNum.getEchoedMsgType()) + .isEqualTo("1"); } public static class EchoMockServer implements QuarkusTestResourceLifecycleManager { @@ -66,6 +72,13 @@ private void configureWiremockServer() { .withHeader("Content-Type", "application/json") .withBody("{ \"echoedMsgType\": \"{{jsonPath request.body '$.msgType'}}\"}") .withTransformers("response-template"))); + + wireMockServer.stubFor(post(urlEqualTo("/echo/num")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody("{ \"echoedMsgType\": \"{{jsonPath request.body '$.msgType'}}\"}") + .withTransformers("response-template"))); } @Override From b2fd3d408dab324798f27eda70250097b58767c0 Mon Sep 17 00:00:00 2001 From: Dmitry Shohov Date: Fri, 19 Jul 2024 13:26:55 +0300 Subject: [PATCH 2/2] use isNumeric instead of dataType "BigDecimal" --- .../libraries/microprofile/enumClass.qute | 2 +- .../src/main/openapi/enum-property.yaml | 28 ++++++++++++++++++- .../generator/it/EnumPropertyTest.java | 17 +++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute b/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute index e6718550..f1c17382 100644 --- a/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute +++ b/client/deployment/src/main/resources/templates/libraries/microprofile/enumClass.qute @@ -7,7 +7,7 @@ {#if e.withXml} {#for v in e.allowableValues.enumVars}@XmlEnumValue({#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}{v.value}{#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}) {v.name}({#if e.isEnum}{e.items.dataType}{#else}{e.dataType}{/if}.valueOf({v.value})){#if v_hasNext}, {#else}; {/if}{/for} {#else} - {#for v in e.allowableValues.enumVars}{v.name}({#if eq e.dataType "BigDecimal"}{v.value}{#else}{#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if}.valueOf({v.value}){/if}){#if v_hasNext}, {#else};{/if}{/for} + {#for v in e.allowableValues.enumVars}{v.name}({#if eq e.isNumeric}{v.value}{#else}{#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if}.valueOf({v.value}){/if}){#if v_hasNext}, {#else};{/if}{/for} {/if} {/if} diff --git a/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml b/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml index 6797e214..5cd335aa 100644 --- a/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml +++ b/client/integration-tests/enum-property/src/main/openapi/enum-property.yaml @@ -36,6 +36,22 @@ paths: application/json: schema: $ref: '#/components/schemas/Echo' + /echo/int: + post: + summary: Echo Integer + operationId: echo_int + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/MessageInt" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Echo' components: schemas: Echo: @@ -59,6 +75,16 @@ components: properties: msgType: type: number + enum: + - 1.1 + - 2.3 + MessageInt: + type: object + required: + - msgType + properties: + msgType: + type: integer enum: - 1 - - 2 \ No newline at end of file + - 2 diff --git a/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java b/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java index 3b98e413..b3f79f40 100644 --- a/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java +++ b/client/integration-tests/enum-property/src/test/java/io/quarkiverse/openapi/generator/it/EnumPropertyTest.java @@ -15,6 +15,7 @@ import org.openapi.quarkus.enum_property_yaml.api.DefaultApi; import org.openapi.quarkus.enum_property_yaml.model.Echo; import org.openapi.quarkus.enum_property_yaml.model.Message; +import org.openapi.quarkus.enum_property_yaml.model.MessageInt; import org.openapi.quarkus.enum_property_yaml.model.MessageNum; import com.github.tomakehurst.wiremock.WireMockServer; @@ -38,15 +39,20 @@ void apiIsBeingGenerated() { var message = new Message(); message.setMsgType(Message.MsgTypeEnum.TEXT); var messageNum = new MessageNum(); - messageNum.setMsgType(MessageNum.MsgTypeEnum.NUMBER_1); + messageNum.setMsgType(MessageNum.MsgTypeEnum.NUMBER_1_DOT_1); + var messageInt = new MessageInt(); + messageInt.setMsgType(MessageInt.MsgTypeEnum.NUMBER_2); Echo echo = api.echo(message); Echo echoNum = api.echoNum(messageNum); + Echo echoInt = api.echoInt(messageInt); assertThat(echo.getEchoedMsgType()) .isEqualTo("text"); assertThat(echoNum.getEchoedMsgType()) - .isEqualTo("1"); + .isEqualTo("1.1"); + assertThat(echoInt.getEchoedMsgType()) + .isEqualTo("2"); } public static class EchoMockServer implements QuarkusTestResourceLifecycleManager { @@ -79,6 +85,13 @@ private void configureWiremockServer() { .withHeader("Content-Type", "application/json") .withBody("{ \"echoedMsgType\": \"{{jsonPath request.body '$.msgType'}}\"}") .withTransformers("response-template"))); + + wireMockServer.stubFor(post(urlEqualTo("/echo/int")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody("{ \"echoedMsgType\": \"{{jsonPath request.body '$.msgType'}}\"}") + .withTransformers("response-template"))); } @Override