Skip to content

Commit 0461331

Browse files
authored
Merge branch 'OpenAPITools:master' into master
2 parents f9db653 + d318752 commit 0461331

252 files changed

Lines changed: 38837 additions & 119 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/samples-jaxrs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- samples/server/petstore/jaxrs-cxf-cdi
3535
- samples/server/petstore/jaxrs-cxf-non-spring-app
3636
- samples/server/petstore/jaxrs-spec-microprofile-openapi-annotations
37+
- samples/server/petstore/jaxrs-spec-swagger-annotations
38+
- samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta
39+
- samples/server/petstore/jaxrs-spec-swagger-v3-annotations
3740
steps:
3841
- uses: actions/checkout@v5
3942
- uses: actions/setup-java@v5
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
generatorName: jaxrs-spec
2+
outputDir: samples/server/petstore/jaxrs-spec-swagger-annotations
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/petstore-with-fake-endpoints-models-for-testing.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/spec
5+
additionalProperties:
6+
artifactId: jaxrs-spec-petstore-server
7+
serializableModel: "true"
8+
hideGenerationTimestamp: "true"
9+
implicitHeadersRegex: (api_key|enum_header_string)
10+
generateBuilders: "true"
11+
useSwaggerAnnotations: "true"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
generatorName: jaxrs-spec
2+
outputDir: samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/petstore-with-fake-endpoints-models-for-testing.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/spec
5+
additionalProperties:
6+
artifactId: jaxrs-spec-petstore-server-jakarta-swagger-v3
7+
serializableModel: "true"
8+
hideGenerationTimestamp: "true"
9+
implicitHeadersRegex: (api_key|enum_header_string)
10+
generateBuilders: "true"
11+
useSwaggerV3Annotations: "true"
12+
useJakartaEe: "true"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
generatorName: jaxrs-spec
2+
outputDir: samples/server/petstore/jaxrs-spec-swagger-v3-annotations
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/petstore-with-fake-endpoints-models-for-testing.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/JavaJaxRS/spec
5+
additionalProperties:
6+
artifactId: jaxrs-spec-petstore-server
7+
serializableModel: "true"
8+
hideGenerationTimestamp: "true"
9+
implicitHeadersRegex: (api_key|enum_header_string)
10+
generateBuilders: "true"
11+
useSwaggerV3Annotations: "true"

docs/generators/jaxrs-cxf-cdi.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8484
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8585
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
8686
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
87+
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
8788
|useTags|use tags for creating interface and controller classnames| |false|
8889
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
8990

docs/generators/jaxrs-spec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8585
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8686
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
8787
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
88+
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
8889
|useTags|use tags for creating interface and controller classnames| |false|
8990
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
9091

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
4242
public static final String GENERATE_POM = "generatePom";
4343
public static final String USE_SWAGGER_ANNOTATIONS = "useSwaggerAnnotations";
4444
public static final String USE_MICROPROFILE_OPENAPI_ANNOTATIONS = "useMicroProfileOpenAPIAnnotations";
45+
public static final String USE_SWAGGER_V3_ANNOTATIONS = "useSwaggerV3Annotations";
4546
public static final String USE_MUTINY = "useMutiny";
4647
public static final String OPEN_API_SPEC_FILE_LOCATION = "openApiSpecFileLocation";
4748
public static final String GENERATE_JSON_CREATOR = "generateJsonCreator";
@@ -57,6 +58,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
5758
private boolean returnJbossResponse = false;
5859
private boolean generatePom = true;
5960
private boolean useSwaggerAnnotations = true;
61+
private boolean useSwaggerV3Annotations = false;
6062
private boolean useMicroProfileOpenAPIAnnotations = false;
6163
private boolean useMutiny = false;
6264

@@ -133,6 +135,7 @@ public JavaJAXRSSpecServerCodegen() {
133135
cliOptions.add(CliOption.newBoolean(RETURN_RESPONSE, "Whether generate API interface should return javax.ws.rs.core.Response instead of a deserialized entity. Only useful if interfaceOnly is true.").defaultValue(String.valueOf(returnResponse)));
134136
cliOptions.add(CliOption.newBoolean(RETURN_JBOSS_RESPONSE, "Whether generate API interface should return `org.jboss.resteasy.reactive.RestResponse` instead of a deserialized entity. This flag cannot be combined with `returnResponse` flag. It requires the flag `interfaceOnly` and `useJakartaEE` set to true, because `org.jboss.resteasy.reactive.RestResponse` was introduced in Quarkus 2.x").defaultValue(String.valueOf(returnJbossResponse)));
135137
cliOptions.add(CliOption.newBoolean(USE_SWAGGER_ANNOTATIONS, "Whether to generate Swagger annotations.", useSwaggerAnnotations));
138+
cliOptions.add(CliOption.newBoolean(USE_SWAGGER_V3_ANNOTATIONS, "Whether to generate Swagger v3 (OpenAPI v3) annotations.", useSwaggerV3Annotations));
136139
cliOptions.add(CliOption.newBoolean(USE_MICROPROFILE_OPENAPI_ANNOTATIONS, "Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.", useMicroProfileOpenAPIAnnotations));
137140
cliOptions.add(CliOption.newString(OPEN_API_SPEC_FILE_LOCATION, "Location where the file containing the spec will be generated in the output folder. No file generated when set to null or empty string."));
138141
cliOptions.add(CliOption.newBoolean(SUPPORT_ASYNC, "Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).", supportAsync));
@@ -149,14 +152,28 @@ public void processOpts() {
149152
convertPropertyToBooleanAndWriteBack(RETURN_JBOSS_RESPONSE, value -> returnJbossResponse = value);
150153
convertPropertyToBooleanAndWriteBack(SUPPORT_ASYNC, this::setSupportAsync);
151154
if (QUARKUS_LIBRARY.equals(library) || THORNTAIL_LIBRARY.equals(library) || HELIDON_LIBRARY.equals(library) || OPEN_LIBERTY_LIBRARY.equals(library) || KUMULUZEE_LIBRARY.equals(library)) {
155+
// disable Swagger v2 annotations in library modes; MicroProfile or Swagger v3 may be used instead
152156
useSwaggerAnnotations = false;
153157
} else {
154158
convertPropertyToBooleanAndWriteBack(USE_SWAGGER_ANNOTATIONS, value -> useSwaggerAnnotations = value);
155159
}
160+
// Swagger v3 can be used regardless of library
161+
convertPropertyToBooleanAndWriteBack(USE_SWAGGER_V3_ANNOTATIONS, value -> useSwaggerV3Annotations = value);
162+
// prefer v3 when requested
163+
if (useSwaggerV3Annotations) {
164+
useSwaggerAnnotations = false;
165+
}
156166
if (KUMULUZEE_LIBRARY.equals(library)) {
157167
super.setSourceFolder("src/main/java");
158168
}
159169

170+
if (useSwaggerAnnotations && useSwaggerV3Annotations) {
171+
throw new IllegalArgumentException("Flags 'useSwaggerAnnotations' (v2) and 'useSwaggerV3Annotations' (v3) are mutually exclusive. Please enable only one.");
172+
}
173+
if (useSwaggerV3Annotations && useMicroProfileOpenAPIAnnotations) {
174+
throw new IllegalArgumentException("Flags 'useSwaggerV3Annotations' and 'useMicroProfileOpenAPIAnnotations' are mutually exclusive. Please enable only one.");
175+
}
176+
160177
if (QUARKUS_LIBRARY.equals(library)) {
161178
convertPropertyToBooleanAndWriteBack(USE_MICROPROFILE_OPENAPI_ANNOTATIONS, value -> useMicroProfileOpenAPIAnnotations = value);
162179
}
@@ -184,6 +201,11 @@ public void processOpts() {
184201

185202
super.processOpts();
186203

204+
// expose flags to templates
205+
additionalProperties.put(USE_SWAGGER_ANNOTATIONS, useSwaggerAnnotations);
206+
additionalProperties.put(USE_SWAGGER_V3_ANNOTATIONS, useSwaggerV3Annotations);
207+
additionalProperties.put(USE_MICROPROFILE_OPENAPI_ANNOTATIONS, useMicroProfileOpenAPIAnnotations);
208+
187209
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
188210
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")
189211
.doNotOverwrite());

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
188188
for (CodegenOperation operation : operations.getOperation()) {
189189
Set<String> phpReturnTypeOptions = new LinkedHashSet<>();
190190
Set<String> docReturnTypeOptions = new LinkedHashSet<>();
191+
boolean hasEmptyResponse = false;
191192

192193
for (CodegenResponse response : operation.responses) {
193194
if (response.dataType != null) {
@@ -200,6 +201,8 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
200201

201202
phpReturnTypeOptions.add(returnType);
202203
docReturnTypeOptions.add(response.dataType);
204+
} else {
205+
hasEmptyResponse = true;
203206
}
204207
}
205208

@@ -208,9 +211,16 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
208211
operation.vendorExtensions.putIfAbsent("x-php-return-type", "void");
209212
operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", "void");
210213
} else {
214+
String phpReturnType = String.join("|", phpReturnTypeOptions);
215+
String docReturnType = String.join("|", docReturnTypeOptions);
216+
if (hasEmptyResponse) {
217+
phpReturnType = "?" + phpReturnType;
218+
docReturnType = docReturnType + "|null";
219+
}
220+
211221
operation.vendorExtensions.putIfAbsent("x-php-return-type-is-void", false);
212-
operation.vendorExtensions.putIfAbsent("x-php-return-type", String.join("|", phpReturnTypeOptions));
213-
operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", String.join("|", docReturnTypeOptions));
222+
operation.vendorExtensions.putIfAbsent("x-php-return-type", phpReturnType);
223+
operation.vendorExtensions.putIfAbsent("x-php-doc-return-type", docReturnType);
214224
}
215225

216226
for (CodegenParameter param : operation.allParams) {

modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,6 @@ end:
188188

189189
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, {{^isEnum}}{{paramName}}{{/isEnum}}{{#isEnum}}{{{operationId}}}_{{enumName}}_ToString({{paramName}}){{/isEnum}});
190190
{{/isString}}
191-
{{#isUuid}}
192-
if({{paramName}} == NULL) {
193-
goto end;
194-
}
195-
char* localVarToReplace_{{paramName}} = malloc(sizeOfPathParams_{{paramName}});
196-
sprintf(localVarToReplace_{{paramName}}, "{%s}", "{{baseName}}");
197-
198-
localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, {{paramName}});
199-
{{/isUuid}}
200191
{{/pathParams}}
201192

202193

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/api.mustache

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import {{javaxPackage}}.ws.rs.core.Response;
99
{{#useSwaggerAnnotations}}
1010
import io.swagger.annotations.*;
1111
{{/useSwaggerAnnotations}}
12+
{{#useSwaggerV3Annotations}}
13+
import io.swagger.v3.oas.annotations.*;
14+
import io.swagger.v3.oas.annotations.media.*;
15+
import io.swagger.v3.oas.annotations.responses.*;
16+
import io.swagger.v3.oas.annotations.tags.Tag;
17+
{{/useSwaggerV3Annotations}}
1218
{{#supportAsync}}
1319
import java.util.concurrent.CompletionStage;
1420
import java.util.concurrent.CompletableFuture;
@@ -23,11 +29,9 @@ import {{javaxPackage}}.validation.Valid;{{/useBeanValidation}}
2329
/**
2430
* Represents a collection of functions to interact with the API endpoints.
2531
*/
26-
{{^interfaceOnly}}
27-
@Path("{{commonPath}}")
28-
{{/interfaceOnly}}
29-
{{#useSwaggerAnnotations}}
30-
@Api(description = "the {{{baseName}}} API"){{/useSwaggerAnnotations}}{{#hasConsumes}}
32+
@Path("{{commonPath}}"){{#useSwaggerAnnotations}}
33+
@Api(description = "the {{{baseName}}} API"){{/useSwaggerAnnotations}}{{#useSwaggerV3Annotations}}
34+
@Tag(name = "{{{baseName}}}"){{/useSwaggerV3Annotations}}{{#hasConsumes}}
3135
@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}}
3236
@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}}
3337
{{>generatedAnnotation}}

0 commit comments

Comments
 (0)