Skip to content

Commit

Permalink
fixed bug where nullApi.java would be generated. Instead, generated D…
Browse files Browse the repository at this point in the history
…efaultApi.java to match the default path /{pathParam} (#3821)
  • Loading branch information
bensimpson-ch authored and wing328 committed Sep 4, 2019
1 parent 2a2eefe commit ec7f2a0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public String getHelp() {
public String toApiName(final String name) {
String computed = name;
if (computed.length() == 0) {
if (primaryResourceName == null) {
return "DefaultApi";
}
return primaryResourceName + "Api";
}
computed = sanitizeName(computed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,30 @@ public void testGeneratePingAlternativeLocation2() throws Exception {

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();
}
}
25 changes: 25 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue_1347.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ec7f2a0

Please sign in to comment.