Skip to content

Commit d195e2c

Browse files
renato-tvrenatomameli
authored andcommitted
fix(java-spring): add missing imports for converter (#23325)
1 parent e6ef8ee commit d195e2c

41 files changed

Lines changed: 260 additions & 2196 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/JavaSpring/converter.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package {{configPackage}};
22

3+
import java.math.BigDecimal;
4+
import java.net.URI;
5+
import java.util.UUID;
6+
37
{{#models}}
48
{{#model}}
59
{{#isEnum}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,6 +3057,36 @@ public void shouldHandleSeparatelyInterfaceAndModelAdditionalAnnotations() throw
30573057
.containsWithName("marker.Common");
30583058
}
30593059

3060+
@Test
3061+
public void contractWithUriEnumContainsEnumConverterWithUriImport() throws IOException {
3062+
Map<String, File> output = generateFromContract("src/test/resources/3_0/enum_uri.yaml", SPRING_BOOT);
3063+
3064+
JavaFileAssert.assertThat(output.get("EnumConverterConfiguration.java"))
3065+
.hasImports("java.net.URI")
3066+
.fileContains("Converter<URI, ExampleUriEnum>")
3067+
.assertMethod("exampleUriEnumConverter");
3068+
}
3069+
3070+
@Test
3071+
public void contractWithUuidEnumContainsEnumConverterWithUuidImport() throws IOException {
3072+
Map<String, File> output = generateFromContract("src/test/resources/3_0/enum_uuid.yaml", SPRING_BOOT);
3073+
3074+
JavaFileAssert.assertThat(output.get("EnumConverterConfiguration.java"))
3075+
.hasImports("java.util.UUID")
3076+
.fileContains("Converter<UUID, ExampleUuidEnum>")
3077+
.assertMethod("exampleUuidEnumConverter");
3078+
}
3079+
3080+
@Test
3081+
public void contractWithNumberEnumContainsEnumConverterWithBigDecimalImport() throws IOException {
3082+
Map<String, File> output = generateFromContract("src/test/resources/3_0/enum_number.yaml", SPRING_BOOT);
3083+
3084+
JavaFileAssert.assertThat(output.get("EnumConverterConfiguration.java"))
3085+
.hasImports("java.math.BigDecimal")
3086+
.fileContains("Converter<BigDecimal, ExampleNumberEnum>")
3087+
.assertMethod("exampleNumberEnumConverter");
3088+
}
3089+
30603090
@Test
30613091
public void contractWithoutEnumDoesNotContainEnumConverter() throws IOException {
30623092
Map<String, File> output = generateFromContract("src/test/resources/3_0/generic.yaml", SPRING_BOOT);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Sample API
4+
description: API with number enum.
5+
version: 1.0.0
6+
paths:
7+
/resources:
8+
get:
9+
summary: Returns resources.
10+
responses:
11+
200:
12+
description: OK
13+
content:
14+
application/json:
15+
schema:
16+
type: array
17+
items:
18+
$ref: '#/components/schemas/Resource'
19+
components:
20+
schemas:
21+
Resource:
22+
type: object
23+
properties:
24+
source:
25+
$ref: '#/components/schemas/ExampleNumberEnum'
26+
ExampleNumberEnum:
27+
type: number
28+
description: Example of an Enum with number values
29+
enum:
30+
- 1.1
31+
- 2.2
32+
- 3.3
33+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Sample API
4+
description: API with URI enum.
5+
version: 1.0.0
6+
paths:
7+
/resources:
8+
get:
9+
summary: Returns resources.
10+
responses:
11+
200:
12+
description: OK
13+
content:
14+
application/json:
15+
schema:
16+
type: array
17+
items:
18+
$ref: '#/components/schemas/Resource'
19+
components:
20+
schemas:
21+
Resource:
22+
type: object
23+
properties:
24+
source:
25+
$ref: '#/components/schemas/ExampleUriEnum'
26+
ExampleUriEnum:
27+
type: string
28+
format: uri
29+
description: Example of an Enum with URI values
30+
enum:
31+
- "https://another-example.com"
32+
- "https://example.com"
33+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Sample API
4+
description: API with UUID enum.
5+
version: 1.0.0
6+
paths:
7+
/resources:
8+
get:
9+
summary: Returns resources.
10+
responses:
11+
200:
12+
description: OK
13+
content:
14+
application/json:
15+
schema:
16+
type: array
17+
items:
18+
$ref: '#/components/schemas/Resource'
19+
components:
20+
schemas:
21+
Resource:
22+
type: object
23+
properties:
24+
source:
25+
$ref: '#/components/schemas/ExampleUuidEnum'
26+
ExampleUuidEnum:
27+
type: string
28+
format: uuid
29+
description: Example of an Enum with UUID values
30+
enum:
31+
- "d6a8f2b0-1c34-4e56-a789-0abcdef12345"
32+
- "e7b9c3d1-2d45-5f67-b890-1bcdef023456"
33+

samples/client/others/typescript/builds/null-types-simple/.openapi-generator/FILES

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/models/ObjectSerializer.ts

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/models/all.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/types/ObjectParamAPI.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/types/ObservableAPI.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)