Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,8 @@ public String toEnumValue(String value, String datatype) {
return "new BigDecimal(\"" + value + "\")";
} else if ("URI".equals(datatype)) {
return "URI.create(\"" + escapeText(value) + "\")";
} else if ("UUID".equals(datatype)) {
return "UUID.fromString(\"" + escapeText(value) + "\")";
} else {
return "\"" + escapeText(value) + "\"";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3094,6 +3094,16 @@ public void contractWithResolvedInnerEnumContainsEnumConverter() throws IOExcept
.assertMethod("ponyTypeConverter");
}

@Test
public void contractWithUuidEnumShouldGenerateValidEnum() throws IOException {
Map<String, File> output = generateFromContract("src/test/resources/3_0/enum_uuid.yaml", SPRING_BOOT);

JavaFileAssert.assertThat(output.get("ExampleUuidEnum.java"))
.fileContains("UUID.fromString(\"d6a8f2b0-1c34-4e56-a789-0abcdef12345\")")
.fileContains("UUID.fromString(\"e7b9c3d1-2d45-5f67-b890-1bcdef023456\")")
.fileContains("private final UUID value");
}

@Test
public void shouldUseTheSameTagNameForTheInterfaceAndTheMethod_issue11570() throws IOException {
final Map<String, File> output = generateFromContract(
Expand Down
32 changes: 32 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/enum_uuid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.0
info:
title: Sample API
description: API with UUID enum.
version: 1.0.0
paths:
/resources:
get:
summary: Returns resources.
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Resource'
components:
schemas:
Resource:
type: object
properties:
source:
$ref: '#/components/schemas/ExampleUuidEnum'
ExampleUuidEnum:
type: string
format: uuid
description: Example of an Enum with UUID values
enum:
- "d6a8f2b0-1c34-4e56-a789-0abcdef12345"
- "e7b9c3d1-2d45-5f67-b890-1bcdef023456"
Loading