Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 6.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jan 3, 2022
2 parents 6c3cdee + 15b228c commit d17a472
Show file tree
Hide file tree
Showing 904 changed files with 97,952 additions and 10,236 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: java-play-framework
outputDir: samples/server/petstore/java-play-framework-fake-endpoints-with-security
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-for-testing-playframework-with-security.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaPlayFramework
additionalProperties:
hideGenerationTimestamp: "true"
13 changes: 13 additions & 0 deletions bin/configs/spring-boot-beanvalidation-no-nullable-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
generatorName: spring
outputDir: samples/openapi3/server/petstore/springboot-beanvalidation-no-nullable
library: spring-boot
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
oas3: "true"
java8: "false"
useBeanValidation: true
artifactId: spring-boot-beanvalidation-no-nullable
hideGenerationTimestamp: "true"
openApiNullable: "false"
11 changes: 11 additions & 0 deletions bin/configs/spring-boot-delegate-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: spring
outputDir: samples/openapi3/server/petstore/springboot-delegate
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
oas3: "true"
artifactId: springboot-delegate
hideGenerationTimestamp: "true"
java8: true
delegatePattern: "true"
10 changes: 10 additions & 0 deletions bin/configs/spring-boot-implicitHeaders-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: spring
outputDir: samples/openapi3/server/petstore/springboot-implicitHeaders
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
oas3: "true"
artifactId: springboot-implicitHeaders
hideGenerationTimestamp: "true"
implicitHeaders: true
10 changes: 10 additions & 0 deletions bin/configs/spring-boot-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: spring
outputDir: samples/openapi3/server/petstore/springboot
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
artifactId: springboot
snapshotVersion: "true"
oas3: "true"
hideGenerationTimestamp: "true"
11 changes: 11 additions & 0 deletions bin/configs/spring-boot-reactive-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: spring
outputDir: samples/openapi3/server/petstore/springboot-reactive
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
oas3: "true"
artifactId: springboot-reactive
reactive: "true"
hideGenerationTimestamp: "true"
delegatePattern: "true"
10 changes: 10 additions & 0 deletions bin/configs/spring-boot-useoptional-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: spring
outputDir: samples/openapi3/server/petstore/springboot-useoptional
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
oas3: "true"
useOptional: true
artifactId: spring-boot-useoptional
hideGenerationTimestamp: "true"
12 changes: 12 additions & 0 deletions bin/configs/spring-cloud-async-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: spring
outputDir: samples/openapi3/client/petstore/spring-cloud-async
library: spring-cloud
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
oas3: "true"
async: "true"
java8: "true"
artifactId: petstore-spring-cloud
hideGenerationTimestamp: "true"
12 changes: 12 additions & 0 deletions bin/configs/spring-cloud-date-time-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: spring
library: spring-cloud
outputDir: samples/openapi3/client/petstore/spring-cloud-date-time
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/date-time-parameter-types-for-testing.yml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
artifactId: spring-cloud-date-time-oas3
interfaceOnly: "true"
singleContentTypes: "true"
hideGenerationTimestamp: "true"
oas3: "true"
10 changes: 10 additions & 0 deletions bin/configs/spring-cloud-date-time.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: spring
library: spring-cloud
outputDir: samples/client/petstore/spring-cloud-date-time
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/date-time-parameter-types-for-testing.yml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
artifactId: spring-cloud-date-time
interfaceOnly: "true"
singleContentTypes: "true"
hideGenerationTimestamp: "true"
12 changes: 12 additions & 0 deletions bin/configs/spring-cloud-oas3-fakeapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: spring
library: spring-cloud
outputDir: samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
artifactId: spring-cloud-oas3
interfaceOnly: "true"
singleContentTypes: "true"
hideGenerationTimestamp: "true"
oas3: "true"
12 changes: 12 additions & 0 deletions bin/configs/spring-cloud-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
generatorName: spring
library: spring-cloud
outputDir: samples/openapi3/client/petstore/spring-cloud
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
artifactId: spring-cloud-oas3
interfaceOnly: "true"
singleContentTypes: "true"
hideGenerationTimestamp: "true"
oas3: "true"
10 changes: 10 additions & 0 deletions bin/configs/spring-cloud-petstore-feign-spring-pageable-oas3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: spring
outputDir: samples/openapi3/client/petstore/spring-cloud-spring-pageable
library: spring-cloud
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-spring-pageable.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
groupId: org.openapitools.openapi3
oas3: "true"
artifactId: spring-cloud-spring-pageable
hideGenerationTimestamp: 'true'
1 change: 1 addition & 0 deletions docs/generators/jaxrs-cxf-cdi.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src/gen/java|
|supportAsync|Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).| |false|
|title|a title describing the application| |OpenAPI Server|
|useBeanValidation|Use BeanValidation API annotations| |true|
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src/main/java|
|supportAsync|Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).| |false|
|title|a title describing the application| |OpenAPI Server|
|useBeanValidation|Use BeanValidation API annotations| |true|
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4103,7 +4103,7 @@ public CodegenOperation fromOperation(String path,
}

// add example
if (schemas != null) {
if (schemas != null && !isSkipOperationExample()) {
op.requestBodyExamples = new ExampleGenerator(schemas, this.openAPI).generate(null, new ArrayList<>(getConsumesInfo(this.openAPI, operation)), bodyParam.baseType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public String getTypeDeclaration(String name) {
if (languageSpecificPrimitives.contains(name)) {
return name;
} else {
return name;
return super.getTypeDeclaration(name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public JavaJAXRSSpecServerCodegen() {
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)));
cliOptions.add(CliOption.newBoolean(USE_SWAGGER_ANNOTATIONS, "Whether to generate Swagger annotations.", useSwaggerAnnotations));
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."));
cliOptions.add(CliOption.newBoolean(SUPPORT_ASYNC, "Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).", supportAsync));
}

@Override
Expand All @@ -121,6 +122,14 @@ public void processOpts() {
additionalProperties.remove(RETURN_RESPONSE);
}
}
if (additionalProperties.containsKey(SUPPORT_ASYNC)) {
supportAsync = Boolean.parseBoolean(additionalProperties.get(SUPPORT_ASYNC).toString());
if (!supportAsync) {
additionalProperties.remove(SUPPORT_ASYNC);
} else {
setJava8ModeAndAdditionalProperties(true);
}
}
if (QUARKUS_LIBRARY.equals(library) || THORNTAIL_LIBRARY.equals(library) || HELIDON_LIBRARY.equals(library) || OPEN_LIBERTY_LIBRARY.equals(library) || KUMULUZEE_LIBRARY.equals(library)) {
useSwaggerAnnotations = false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import static org.openapitools.codegen.CodegenConstants.INVOKER_PACKAGE;

Expand Down Expand Up @@ -97,18 +98,18 @@ public JavaMicronautClientCodegen() {
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations", useBeanValidation));

CliOption buildToolOption = new CliOption(OPT_BUILD, "Specify for which build tool to generate files").defaultValue(buildTool);
buildToolOption.setEnum(new HashMap<String, String>() {{
put(OPT_BUILD_GRADLE, "Gradle configuration is generated for the project");
put(OPT_BUILD_MAVEN, "Maven configuration is generated for the project");
put(OPT_BUILD_ALL, "Both Gradle and Maven configurations are generated");
}});
Map buildToolOptionMap = new HashMap();
buildToolOptionMap.put(OPT_BUILD_GRADLE, "Gradle configuration is generated for the project");
buildToolOptionMap.put(OPT_BUILD_MAVEN, "Maven configuration is generated for the project");
buildToolOptionMap.put(OPT_BUILD_ALL, "Both Gradle and Maven configurations are generated");
buildToolOption.setEnum(buildToolOptionMap);
cliOptions.add(buildToolOption);

CliOption testToolOption = new CliOption(OPT_TEST, "Specify which test tool to generate files for").defaultValue(testTool);
testToolOption.setEnum(new HashMap<String, String>() {{
put(OPT_TEST_JUNIT, "Use JUnit as test tool");
put(OPT_TEST_SPOCK, "Use Spock as test tool");
}});
Map testToolOptionMap = new HashMap();
testToolOptionMap.put(OPT_TEST_JUNIT, "Use JUnit as test tool");
testToolOptionMap.put(OPT_TEST_SPOCK, "Use Spock as test tool");
testToolOption.setEnum(testToolOptionMap);
cliOptions.add(testToolOption);

// Remove the date library option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
package org.openapitools.codegen.languages;

import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.openapitools.codegen.utils.StringUtils.camelize;

Expand All @@ -45,6 +45,10 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
public static final String USE_SWAGGER_UI = "useSwaggerUI";
public static final String SUPPORT_ASYNC = "supportAsync";

private static final String X_JWKS_URL = "x-jwksUrl";
private static final String X_TOKEN_INTROSPECT_URL = "x-tokenIntrospectUrl";


protected String title = "openapi-java-playframework";
protected String configPackage = "org.openapitools.configuration";
protected String basePackage = "org.openapitools";
Expand Down Expand Up @@ -197,6 +201,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("module.mustache", "app", "Module.java"));
}
supportingFiles.add(new SupportingFile("openapiUtils.mustache", "app/openapitools", "OpenAPIUtils.java"));
supportingFiles.add(new SupportingFile("securityApiUtils.mustache", "app/openapitools", "SecurityAPIUtils.java"));
if (this.handleExceptions) {
supportingFiles.add(new SupportingFile("errorHandler.mustache", "app/openapitools", "ErrorHandler.java"));
}
Expand Down Expand Up @@ -376,4 +381,98 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
generateJSONSpecFile(objs);
return super.postProcessSupportingFileData(objs);
}

@Override
public List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> securitySchemeMap) {
List<? extends CodegenSecurity> securities = super.fromSecurity(securitySchemeMap);
List<CodegenSecurity> extendedSecurities = new ArrayList<>();

for (CodegenSecurity codegenSecurity : securities) {
ExtendedCodegenSecurity extendedCodegenSecurity = new ExtendedCodegenSecurity(codegenSecurity);
Object jwksUrl = extendedCodegenSecurity.vendorExtensions.get(X_JWKS_URL);

if (jwksUrl instanceof String) {
extendedCodegenSecurity.jwksUrl = (String) jwksUrl;
}

Object tokenIntrospectUrl = extendedCodegenSecurity.vendorExtensions.get(X_TOKEN_INTROSPECT_URL);

if (tokenIntrospectUrl instanceof String) {
extendedCodegenSecurity.tokenIntrospectUrl = (String) tokenIntrospectUrl;
}
extendedSecurities.add(extendedCodegenSecurity);
}

return extendedSecurities;
}


class ExtendedCodegenSecurity extends CodegenSecurity {
public String jwksUrl;
public String tokenIntrospectUrl;

public ExtendedCodegenSecurity(CodegenSecurity cm) {
super();

this.name = cm.name;
this.type = cm.type;
this.scheme = cm.scheme;
this.isBasic = cm.isBasic;
this.isOAuth = cm.isOAuth;
this.isApiKey = cm.isApiKey;
this.isBasicBasic = cm.isBasicBasic;
this.isBasicBearer = cm.isBasicBearer;
this.isHttpSignature = cm.isHttpSignature;
this.bearerFormat = cm.bearerFormat;
this.vendorExtensions = new HashMap<String, Object>(cm.vendorExtensions);
this.keyParamName = cm.keyParamName;
this.isKeyInQuery = cm.isKeyInQuery;
this.isKeyInHeader = cm.isKeyInHeader;
this.isKeyInCookie = cm.isKeyInCookie;
this.flow = cm.flow;
this.authorizationUrl = cm.authorizationUrl;
this.tokenUrl = cm.tokenUrl;
this.refreshUrl = cm.refreshUrl;
this.scopes = cm.scopes;
this.isCode = cm.isCode;
this.isPassword = cm.isPassword;
this.isApplication = cm.isApplication;
this.isImplicit = cm.isImplicit;
}

@Override
public CodegenSecurity filterByScopeNames(List<String> filterScopes) {
CodegenSecurity codegenSecurity = super.filterByScopeNames(filterScopes);
ExtendedCodegenSecurity extendedCodegenSecurity = new ExtendedCodegenSecurity(codegenSecurity);
extendedCodegenSecurity.jwksUrl = this.jwksUrl;
extendedCodegenSecurity.tokenIntrospectUrl = this.tokenIntrospectUrl;
return extendedCodegenSecurity;
}

@Override
public boolean equals(Object o) {
boolean result = super.equals(o);
JavaPlayFrameworkCodegen.ExtendedCodegenSecurity that = (JavaPlayFrameworkCodegen.ExtendedCodegenSecurity) o;
return result &&
Objects.equals(jwksUrl, that.jwksUrl) &&
Objects.equals(tokenIntrospectUrl, that.tokenIntrospectUrl);

}

@Override
public int hashCode() {
int superHash = super.hashCode();
return Objects.hash(superHash, tokenIntrospectUrl, jwksUrl);
}

@Override
public String toString() {
String superString = super.toString();
final StringBuilder sb = new StringBuilder(superString);
sb.append(", jwksUrl='").append(jwksUrl).append('\'');
sb.append(", tokenIntrospectUrl='").append(tokenIntrospectUrl).append('\'');
return sb.toString();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ private boolean shouldHideOperationResponse(ApiResponse resp) {
Map<?, ?> respExtensions = (Map<?, ?>) resp.getExtensions().get(X_OPERATION_RESPONSE);
Entry<?, ?> entry = respExtensions.entrySet().stream().findFirst().orElse(null);

if (entry.getKey().equals(X_OPERATION_RESPONSE_HIDE)) {
if (entry != null && entry.getKey().equals(X_OPERATION_RESPONSE_HIDE)) {
return Boolean.parseBoolean(String.valueOf(entry.getValue()));
}
}
Expand Down
Loading

0 comments on commit d17a472

Please sign in to comment.