Skip to content

Commit

Permalink
Add openapi.yaml file to Java clients (OpenAPITools#5765)
Browse files Browse the repository at this point in the history
* Add openapi.yaml file to Java client

* Move supporting template file to Java root

* Update petstore clients
  • Loading branch information
nmuesch authored and michaelpro1 committed May 7, 2020
1 parent 3b1d83a commit d8d4d22
Show file tree
Hide file tree
Showing 26 changed files with 50,223 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
supportingFiles.add(new SupportingFile("ServerConfiguration.mustache", invokerFolder, "ServerConfiguration.java"));
supportingFiles.add(new SupportingFile("ServerVariable.mustache", invokerFolder, "ServerVariable.java"));
supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml"));


if (!(RESTTEMPLATE.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()) || NATIVE.equals(getLibrary()) || MICROPROFILE.equals(getLibrary()))) {
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
Expand Down Expand Up @@ -883,6 +885,12 @@ static boolean isJsonVendorMimeType(String mime) {
return mime != null && JSON_VENDOR_MIME_PATTERN.matcher(mime).matches();
}

@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
generateYAMLSpecFile(objs);
return super.postProcessSupportingFileData(objs);
}

@Override
public String toApiVarName(String name) {
String apiVarName = super.toApiVarName(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{openapi-yaml}}}
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testGeneratePing() throws Exception {
generator.opts(clientOptInput).generate();

Map<String, String> generatedFiles = generator.getFiles();
Assert.assertEquals(generatedFiles.size(), 36);
Assert.assertEquals(generatedFiles.size(), 37);
TestUtils.ensureContainsFile(generatedFiles, output, ".gitignore");
TestUtils.ensureContainsFile(generatedFiles, output, ".openapi-generator-ignore");
TestUtils.ensureContainsFile(generatedFiles, output, ".openapi-generator/VERSION");
Expand All @@ -284,6 +284,7 @@ public void testGeneratePing() throws Exception {
TestUtils.ensureContainsFile(generatedFiles, output, "pom.xml");
TestUtils.ensureContainsFile(generatedFiles, output, "README.md");
TestUtils.ensureContainsFile(generatedFiles, output, "settings.gradle");
TestUtils.ensureContainsFile(generatedFiles, output, "api/openapi.yaml");
TestUtils.ensureContainsFile(generatedFiles, output, "src/main/AndroidManifest.xml");
TestUtils.ensureContainsFile(generatedFiles, output, "src/main/java/xyz/abcdef/api/DefaultApi.java");
TestUtils.ensureContainsFile(generatedFiles, output, "src/main/java/xyz/abcdef/ApiCallback.java");
Expand Down Expand Up @@ -342,7 +343,7 @@ public void testGeneratePingSomeObj() throws Exception {
generator.opts(clientOptInput).generate();

Map<String, String> generatedFiles = generator.getFiles();
Assert.assertEquals(generatedFiles.size(), 39);
Assert.assertEquals(generatedFiles.size(), 40);
TestUtils.ensureContainsFile(generatedFiles, output, ".gitignore");
TestUtils.ensureContainsFile(generatedFiles, output, ".openapi-generator-ignore");
TestUtils.ensureContainsFile(generatedFiles, output, ".openapi-generator/VERSION");
Expand All @@ -360,6 +361,7 @@ public void testGeneratePingSomeObj() throws Exception {
TestUtils.ensureContainsFile(generatedFiles, output, "pom.xml");
TestUtils.ensureContainsFile(generatedFiles, output, "README.md");
TestUtils.ensureContainsFile(generatedFiles, output, "settings.gradle");
TestUtils.ensureContainsFile(generatedFiles, output, "api/openapi.yaml");
TestUtils.ensureContainsFile(generatedFiles, output, "src/main/AndroidManifest.xml");
TestUtils.ensureContainsFile(generatedFiles, output, "src/main/java/zz/yyyy/api/xxxx/PingApi.java");
TestUtils.ensureContainsFile(generatedFiles, output, "src/main/java/zz/yyyy/invoker/xxxx/ApiCallback.java");
Expand Down Expand Up @@ -414,7 +416,7 @@ public void testJdkHttpClient() throws Exception {
generator.opts(clientOptInput).generate();

Map<String, String> generatedFiles = generator.getFiles();
Assert.assertEquals(generatedFiles.size(), 25);
Assert.assertEquals(generatedFiles.size(), 26);
validateJavaSourceFiles(generatedFiles);

String defaultApiFilename = new File(output, "src/main/java/xyz/abcdef/api/DefaultApi.java").getAbsolutePath().replace("\\", "/");
Expand Down
Loading

0 comments on commit d8d4d22

Please sign in to comment.