Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -615,10 +615,6 @@ public void processOpts() {
additionalProperties.put(USE_FEIGN_CLIENT, "true");
} else if (SPRING_BOOT.equals(library)) {
apiTemplateFiles.put("apiController.mustache", "Controller.java");
if (containsEnums()) {
supportingFiles.add(new SupportingFile("converter.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "EnumConverterConfiguration.java"));
}
supportingFiles.add(new SupportingFile("application.mustache",
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
supportingFiles.add(new SupportingFile("homeController.mustache",
Expand Down Expand Up @@ -786,6 +782,12 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);

if (!interfaceOnly && SPRING_BOOT.equals(library) && containsEnums()) {
supportingFiles.add(new SupportingFile("converter.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "EnumConverterConfiguration.java"));
}

/*
* TODO the following logic should not need anymore in OAS 3.0 if
* ("/".equals(swagger.getBasePath())) { swagger.setBasePath(""); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,26 @@ public void contractWithEnumContainsEnumConverter() throws IOException {
.assertMethod("typeConverter");
}

@Test
public void contractWithResolvedInnerEnumContainsEnumConverter() throws IOException {
File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("spring")
.setInputSpec("src/test/resources/3_0/inner_enum.yaml")
.addInlineSchemaOption("RESOLVE_INLINE_ENUMS", "true")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator();
Map<String, File> files = generator.opts(clientOptInput).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert.assertThat(files.get("EnumConverterConfiguration.java"))
.assertMethod("ponyTypeConverter");
}

@Test
public void shouldUseTheSameTagNameForTheInterfaceAndTheMethod_issue11570() throws IOException {
final Map<String, File> output = generateFromContract("src/test/resources/bugs/issue_11570.yml", SPRING_BOOT);
Expand Down
30 changes: 30 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/inner_enum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
openapi: 3.0.0
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
paths:
/ponies:
get:
summary: Returns all animals.
description: Optional extended description in Markdown.
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pony'
components:
schemas:
Pony:
type: object
properties:
type:
type: string
enum:
- Earth
- Pegasi
- Unicorn