Skip to content

Commit

Permalink
BigDecimal value fix in enums (quarkiverse#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Shohov committed May 16, 2024
1 parent 7d691cd commit e93c8c9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -35,4 +51,14 @@ components:
msgType:
type: string
enum:
- 'text'
- 'text'
MessageNum:
type: object
required:
- msgType
properties:
msgType:
type: number
enum:
- 1
- 2
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit e93c8c9

Please sign in to comment.