-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Microprofile] Add option to use tags a client keys and server generator #16673
Changes from 31 commits
3abefee
c5de775
7983f0d
e41a2ff
09e441f
a7b4f70
9ef4f6a
7e8fd05
b5bcbde
5429144
095d22f
60475f0
58655da
f9138a2
6219586
e66f96b
aa89d82
160831e
b72f09b
9db4a4e
ce52f7c
ac0d143
f2284bd
c508b3c
e425da1
a6f4d57
a58b998
f16fba2
e564440
707545b
8e25428
db381f1
74f6b04
2b6f9b3
f123bab
a066de5
e82cac2
1fa87ec
f9ce785
31f8340
f8c20b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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" |
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]| | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.openapitools.codegen.languages; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
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; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class MicroprofileServerCodegen extends JavaClientCodegen { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. personally I would suggest NOT to extend a java server with JavaClientCodegen as most options available in JavaClientCodegen won't make sense in the server generator if I understand it correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The java generator, using the microprofile library, generates an interface that could be used for either client or server. This is what is being extended. I understand that it seems odd to have a server code generator inherit from a client generator. But we would have to re write the functionality of the java generator. Do you have a suggestion of how to proceed with this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right seems odd but to me but it's not a showstopper. if this way is a good starting point to add the server generator for microprofile, i'm totally ok with that. |
||
public static final String PROJECT_NAME = "projectName"; | ||
public static final String MICROPROFILE_SERVER = "microprofileServer"; | ||
protected boolean microprofileServer = true; | ||
|
||
public MicroprofileServerCodegen() { | ||
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; | ||
} | ||
} |
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}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{#microprofileMutiny}}Uni<{{{returnType}}}>{{/microprofileMutiny}}{{^microprofileMutiny}}{{{returnType}}}{{/microprofileMutiny}} |
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}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
configKeyFromClassName
is set tofalse
? Then the expectation is to still use the value ofconfigKey
, but it's set tonull
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated this to be conditional on CONFIG_KEY being null. So that the CONFIG_KEY option takes precedence