fixed bug where nullApi.java would be generated. Instead, generated DefaultApi.java to match the default path /{pathParam} (#3821)

This commit is contained in:
Benjamin Simpson 2019-09-04 11:15:04 +02:00 committed by William Cheng
parent 2a2eefe93d
commit ec7f2a0450
3 changed files with 54 additions and 0 deletions

View File

@ -239,6 +239,9 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
public String toApiName(final String name) { public String toApiName(final String name) {
String computed = name; String computed = name;
if (computed.length() == 0) { if (computed.length() == 0) {
if (primaryResourceName == null) {
return "DefaultApi";
}
return primaryResourceName + "Api"; return primaryResourceName + "Api";
} }
computed = sanitizeName(computed); computed = sanitizeName(computed);

View File

@ -286,4 +286,30 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest {
output.deleteOnExit(); output.deleteOnExit();
} }
@Test
public void testGenerateApiWithPreceedingPathParameter_issue1347() throws Exception {
Map<String, Object> properties = new HashMap<>();
properties.put(JavaClientCodegen.JAVA8_MODE, true);
properties.put(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, "openapi.yml");
File output = Files.createTempDirectory("test").toFile();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("jaxrs-spec")
.setAdditionalProperties(properties)
.setInputSpec("src/test/resources/3_0/issue_1347.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
final ClientOptInput clientOptInput = configurator.toClientOptInput();
MockDefaultGenerator generator = new MockDefaultGenerator();
generator.opts(clientOptInput).generate();
Map<String, String> generatedFiles = generator.getFiles();
validateJavaSourceFiles(generatedFiles);
TestUtils.ensureContainsFile(generatedFiles, output, "openapi.yml");
TestUtils.ensureContainsFile(generatedFiles, output, "src/gen/java/org/openapitools/api/DefaultApi.java");
output.deleteOnExit();
}
} }

View File

@ -0,0 +1,25 @@
openapi: 3.0.2
info:
title: Name demo
version: 1.0
paths:
/{country}/document:
get:
summary: Get a document
tags:
- document
operationId: getDocument
parameters:
- name: country
in: path
required: true
schema:
type: string
responses:
"201":
description: The document
"500":
description: Server error
tags:
- name: document
description: Document tag