-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Microprofile] Add option to use tags a client keys and server genera…
…tor (#16673) * [Java/Microprofile] Add support for Jackson serialization & async interfaces using Mutiny in Java Microprofile library * Regenerate samples & docs * Add server generator * Update client to set configKey by classname * Remove debug remains and comments * Adapt method override to upstream changes * Regenerate samples * Revert "Regenerate samples" This reverts commit b5bcbde. * Move additional 2xx response to dedicated OpenAPI document Some other generators than those for Micronaut don't seem to be able to handle this case, so we don't add it to the general pet store document. * Make filename consistent with other files in the folder * Regenerate Microprofile client and server samples * Generate samples * Update documentation * Generate samples * Remove left-over `*.orig` files from Git merges * Regenerate samples * Regenerated samples * changed generator name to "java-microprofile" * added the new folder to .github/workflows/samples-java-server-jdk8.yaml so that CI will test it moving forward * Renamed JavaMicroprofileServerCodegen.java * regenerated samples * only enable configKeyFromClassName if configKey is not set * Updated documentation * Change samples to use junit 4 * Fix junit 4 test classes * run ensure up-to-date script * fix kotlin test errors --------- Co-authored-by: pravussum <[email protected]> Co-authored-by: frank <[email protected]> Co-authored-by: Oscar <[email protected]> Co-authored-by: oscarobr <[email protected]>
- Loading branch information
1 parent
dc63444
commit dec8a43
Showing
120 changed files
with
7,336 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
generatorName: java | ||
outputDir: samples/client/petstore/java/microprofile-rest-client | ||
library: microprofile | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/Java | ||
additionalProperties: | ||
artifactId: microprofile-rest-client | ||
configKey: petstore | ||
configKeyFromClassName: true |
8 changes: 8 additions & 0 deletions
8
bin/configs/java-microprofile-server-multiple-2xx-responses.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
generatorName: java-microprofile | ||
outputDir: samples/server/petstore/java-microprofile | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-multiple-2xx-responses.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/Java | ||
additionalProperties: | ||
hideGenerationTimestamp: "true" | ||
microprofileMutiny: "true" | ||
serializationLibrary: "jackson" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | |
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false| | ||
|caseInsensitiveResponseHeaders|Make API response's headers case-insensitive. Available on okhttp-gson, jersey2 libraries| |false| | ||
|configKey|Config key in @RegisterRestClient. Default to none. Only `microprofile` supports this option.| |null| | ||
|configKeyFromClassName|If true, set tag as key in @RegisterRestClient. Default to false. Only `microprofile` supports this option.| |null| | ||
|containerDefaultToNull|Set containers (array, set, map) default to null| |false| | ||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8| | ||
|developerEmail|developer email in generated pom.xml| |[email protected]| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...rator/src/main/java/org/openapitools/codegen/languages/JavaMicroprofileServerCodegen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.openapitools.codegen.languages; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import org.openapitools.codegen.CodegenOperation; | ||
import org.openapitools.codegen.CodegenResponse; | ||
import org.openapitools.codegen.CodegenType; | ||
import org.openapitools.codegen.model.ModelMap; | ||
import org.openapitools.codegen.model.OperationMap; | ||
import org.openapitools.codegen.model.OperationsMap; | ||
|
||
public class JavaMicroprofileServerCodegen extends JavaClientCodegen { | ||
public static final String PROJECT_NAME = "projectName"; | ||
public static final String MICROPROFILE_SERVER = "microprofileServer"; | ||
protected boolean microprofileServer = true; | ||
|
||
public JavaMicroprofileServerCodegen() { | ||
super(); | ||
|
||
outputFolder = "generated-code" + File.separator + "microprofile"; | ||
invokerPackage = "org.openapitools.server"; | ||
artifactId = "openapi-microprofile-server"; | ||
apiPackage = "org.openapitools.server.api"; | ||
modelPackage = "org.openapitools.server.model"; | ||
setLibrary("microprofile"); | ||
} | ||
|
||
public CodegenType getTag() { | ||
return CodegenType.SERVER; | ||
} | ||
|
||
public String getName() { | ||
return "java-microprofile"; | ||
} | ||
|
||
public String getHelp() { | ||
return "Generates a microprofile server."; | ||
} | ||
@Override | ||
public void processOpts() { | ||
super.processOpts(); | ||
additionalProperties.put(MICROPROFILE_SERVER, microprofileServer); | ||
} | ||
|
||
@Override | ||
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) { | ||
super.postProcessOperationsWithModels(objs, allModels); | ||
OperationMap operations = objs.getOperations(); | ||
if (operations != null) { | ||
List<CodegenOperation> ops = operations.getOperation(); | ||
for (CodegenOperation operation : ops) { | ||
List<CodegenResponse> responses = operation.responses; | ||
if (multiple2xxResponsesSpecified(responses)) { | ||
operation.vendorExtensions.put("x-multiple-2xx-response-operation", true); | ||
} | ||
} | ||
} | ||
return objs; | ||
} | ||
|
||
private boolean multiple2xxResponsesSpecified(List<CodegenResponse> responses) { | ||
int responseIs2xxCount = 0; | ||
for (CodegenResponse response : responses) { | ||
if (response.is2xx) { | ||
responseIs2xxCount++; | ||
} | ||
} | ||
return responseIs2xxCount > 1; | ||
} | ||
} |
11 changes: 10 additions & 1 deletion
11
modules/openapi-generator/src/main/resources/Java/libraries/microprofile/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
# {{appName}} - MicroProfile Rest Client | ||
# {{appName}} - MicroProfile Rest Client & MicroProfile Server | ||
|
||
{{#appDescriptionWithNewLines}} | ||
{{{.}}} | ||
|
||
{{/appDescriptionWithNewLines}} | ||
{{^microprofileServer}} | ||
## Overview | ||
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. | ||
[MicroProfile Rest Client](https://github.com/eclipse/microprofile-rest-client) is a type-safe way of calling | ||
REST services. The generated client contains an interface which acts as the client, you can inject it into dependent classes. | ||
{{/microprofileServer}} | ||
|
||
{{#microprofileServer}} | ||
## Overview | ||
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. | ||
The generated server contains an interface which acts as the server, you can inject it into the controller class. | ||
This module is intended to provide additional server features, like accessing an operations response object, when multiple responses where specified. | ||
{{/microprofileServer}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...penapi-generator/src/main/resources/Java/libraries/microprofile/client_operation.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{#microprofileMutiny}}Uni<{{{returnType}}}>{{/microprofileMutiny}}{{^microprofileMutiny}}{{{returnType}}}{{/microprofileMutiny}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...penapi-generator/src/main/resources/Java/libraries/microprofile/server_operation.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{#vendorExtensions.x-multiple-2xx-response-operation}}{{#microprofileMutiny}}Uni<Response>{{/microprofileMutiny}}{{^microprofileMutiny}}Response{{/microprofileMutiny}}{{/vendorExtensions.x-multiple-2xx-response-operation}}{{^vendorExtensions.x-multiple-2xx-response-operation}}{{#microprofileMutiny}}Uni<{{{returnType}}}>{{/microprofileMutiny}}{{^microprofileMutiny}}{{{returnType}}}{{/microprofileMutiny}}{{/vendorExtensions.x-multiple-2xx-response-operation}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.