Skip to content

Commit 82a56e7

Browse files
committed
Merge branch 'master' into feature/2901-integrate-property-to-remove-json-nullable
* master: [Extensions][Go][Java] Test x-auth-id-alias (OpenAPITools#6642) [php-slim4] Move config to a separate file (OpenAPITools#6971) [C][Client][Clang Static Analyzer] Remove the useless free operation for (OpenAPITools#7309) Fix typescript-node generation when only models are generated (OpenAPITools#7127) update spring config to use java8 (OpenAPITools#7308) [C][Client][Clang Static Analyzer] Fix uninitialized argument value (OpenAPITools#7305) [Java] remove deprecated jackson classes (OpenAPITools#7304) Adds generator unaliasSchema method, uses it to refactor python-experimental (OpenAPITools#7274) [Rust][reqwest] prefix local variables with "local_var" (OpenAPITools#7299) [Java][jersey2]Support enum discriminator value in child objects (OpenAPITools#7267) [C][Client][Clang Static Analyzer] Fix memory leak before function returnning (OpenAPITools#7302)
2 parents 3ea0019 + d5a680e commit 82a56e7

File tree

369 files changed

+11192
-5192
lines changed

Some content is hidden

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

369 files changed

+11192
-5192
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: go-experimental
2+
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/go-experimental
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/go-experimental
5+
additionalProperties:
6+
packageName: x_auth_id_alias
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: java
2+
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8
3+
library: jersey2
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
5+
additionalProperties:
6+
artifactId: openapi3-extensions-x-auth-id-alias-jersey2-java8
7+
hideGenerationTimestamp: true

bin/configs/spring-boot-beanvalidation.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ library: spring-boot
44
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
55
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
66
additionalProperties:
7-
java8: "false"
7+
java8: true
88
useBeanValidation: true
99
artifactId: spring-boot-beanvalidation
1010
hideGenerationTimestamp: "true"

bin/configs/spring-boot-delegate.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ templateDir: modules/openapi-generator/src/main/resources/JavaSpring
55
additionalProperties:
66
artifactId: springboot-delegate
77
hideGenerationTimestamp: "true"
8-
java8: "false"
8+
java8: true
99
delegatePattern: "true"

bin/configs/spring-mvc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ library: spring-mvc
44
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
55
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
66
additionalProperties:
7-
java8: "false"
7+
java8: true
88
booleanGetterPrefix: get
99
artifactId: spring-mvc-server
1010
hideGenerationTimestamp: "true"

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

+17-16
Original file line numberDiff line numberDiff line change
@@ -1971,14 +1971,18 @@ public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
19711971
return "oneOf<" + String.join(",", names) + ">";
19721972
}
19731973

1974+
protected Schema unaliasSchema(Schema schema, Map<String, String> usedImportMappings) {
1975+
return ModelUtils.unaliasSchema(this.openAPI, schema, usedImportMappings);
1976+
}
1977+
19741978
/**
19751979
* Return a string representation of the schema type, resolving aliasing and references if necessary.
19761980
*
19771981
* @param schema input
19781982
* @return the string representation of the schema type.
19791983
*/
19801984
protected String getSingleSchemaType(Schema schema) {
1981-
Schema unaliasSchema = ModelUtils.unaliasSchema(this.openAPI, schema, importMapping);
1985+
Schema unaliasSchema = unaliasSchema(schema, importMapping);
19821986

19831987
if (StringUtils.isNotBlank(unaliasSchema.get$ref())) { // reference to another definition/schema
19841988
// get the schema/model name from $ref
@@ -2216,7 +2220,7 @@ public CodegenModel fromModel(String name, Schema schema) {
22162220
}
22172221

22182222
// unalias schema
2219-
schema = ModelUtils.unaliasSchema(this.openAPI, schema, importMapping);
2223+
schema = unaliasSchema(schema, importMapping);
22202224
if (schema == null) {
22212225
LOGGER.warn("Schema {} not found", name);
22222226
return null;
@@ -2330,7 +2334,7 @@ public CodegenModel fromModel(String name, Schema schema) {
23302334
m.interfaces = new ArrayList<String>();
23312335

23322336
for (Schema interfaceSchema : interfaces) {
2333-
interfaceSchema = ModelUtils.unaliasSchema(this.openAPI, interfaceSchema, importMapping);
2337+
interfaceSchema = unaliasSchema(interfaceSchema, importMapping);
23342338

23352339
if (StringUtils.isBlank(interfaceSchema.get$ref())) {
23362340
// primitive type
@@ -2991,7 +2995,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
29912995
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
29922996

29932997
// unalias schema
2994-
p = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
2998+
p = unaliasSchema(p, importMapping);
29952999

29963000
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
29973001

@@ -3168,10 +3172,9 @@ public CodegenProperty fromProperty(String name, Schema p) {
31683172
} else if (ModelUtils.isArraySchema(p)) {
31693173
// default to string if inner item is undefined
31703174
ArraySchema arraySchema = (ArraySchema) p;
3171-
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getSchemaItems(arraySchema), importMapping);
3175+
Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), importMapping);
31723176
} else if (ModelUtils.isMapSchema(p)) {
3173-
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getAdditionalProperties(p),
3174-
importMapping);
3177+
Schema innerSchema = unaliasSchema(getAdditionalProperties(p), importMapping);
31753178
if (innerSchema == null) {
31763179
LOGGER.error("Undefined map inner type for `{}`. Default to String.", p.getName());
31773180
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
@@ -3251,7 +3254,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
32513254
itemName = property.name;
32523255
}
32533256
ArraySchema arraySchema = (ArraySchema) p;
3254-
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getSchemaItems(arraySchema), importMapping);
3257+
Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), importMapping);
32553258
CodegenProperty cp = fromProperty(itemName, innerSchema);
32563259
updatePropertyForArray(property, cp);
32573260
} else if (ModelUtils.isMapSchema(p)) {
@@ -3263,8 +3266,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
32633266
property.maxItems = p.getMaxProperties();
32643267

32653268
// handle inner property
3266-
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getAdditionalProperties(p),
3267-
importMapping);
3269+
Schema innerSchema = unaliasSchema(getAdditionalProperties(p), importMapping);
32683270
if (innerSchema == null) {
32693271
LOGGER.error("Undefined map inner type for `{}`. Default to String.", p.getName());
32703272
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
@@ -3504,7 +3506,7 @@ protected void handleMethodResponse(Operation operation,
35043506
CodegenOperation op,
35053507
ApiResponse methodResponse,
35063508
Map<String, String> importMappings) {
3507-
Schema responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(methodResponse), importMappings);
3509+
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(methodResponse), importMapping);
35083510

35093511
if (responseSchema != null) {
35103512
CodegenProperty cm = fromProperty("response", responseSchema);
@@ -3908,8 +3910,7 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
39083910
}
39093911
Schema responseSchema;
39103912
if (this.openAPI != null && this.openAPI.getComponents() != null) {
3911-
responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(response),
3912-
importMapping);
3913+
responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(response), importMapping);
39133914
} else { // no model/alias defined
39143915
responseSchema = ModelUtils.getSchemaFromResponse(response);
39153916
}
@@ -4150,7 +4151,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
41504151
}
41514152

41524153
if (parameterSchema != null) {
4153-
parameterSchema = ModelUtils.unaliasSchema(this.openAPI, parameterSchema);
4154+
parameterSchema = unaliasSchema(parameterSchema, Collections.<String, String>emptyMap());
41544155
if (parameterSchema == null) {
41554156
LOGGER.warn("warning! Schema not found for parameter \"" + parameter.getName() + "\", using String");
41564157
parameterSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to missing type definition.");
@@ -4690,7 +4691,7 @@ protected void addImport(CodegenModel m, String type) {
46904691
private Map<String, Schema> unaliasPropertySchema(Map<String, Schema> properties) {
46914692
if (properties != null) {
46924693
for (String key : properties.keySet()) {
4693-
properties.put(key, ModelUtils.unaliasSchema(this.openAPI, properties.get(key), importMapping()));
4694+
properties.put(key, unaliasSchema(properties.get(key), importMapping()));
46944695

46954696
}
46964697
}
@@ -5815,7 +5816,7 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
58155816
return codegenParameter;
58165817
}
58175818

5818-
private void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set<String> imports, String bodyParameterName, boolean forceSimpleRef) {
5819+
protected void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set<String> imports, String bodyParameterName, boolean forceSimpleRef) {
58195820
CodegenModel codegenModel = null;
58205821
if (StringUtils.isNotBlank(name)) {
58215822
schema.setName(name);

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

+61-37
Original file line numberDiff line numberDiff line change
@@ -779,56 +779,82 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
779779
Map<String, Object> mo = (Map<String, Object>) _mo;
780780
CodegenModel cm = (CodegenModel) mo.get("model");
781781
boolean addImports = false;
782+
782783
if (this.openApiNullable) {
783784
for (CodegenProperty var : cm.vars) {
784785
boolean isOptionalNullable = Boolean.FALSE.equals(var.required) && Boolean.TRUE.equals(var.isNullable);
785786
// only add JsonNullable and related imports to optional and nullable values
786787
addImports |= isOptionalNullable;
787788
var.getVendorExtensions().put("x-is-jackson-optional-nullable", isOptionalNullable);
789+
790+
if (Boolean.TRUE.equals(var.getVendorExtensions().get("x-enum-as-string"))) {
791+
// treat enum string as just string
792+
var.datatypeWithEnum = var.dataType;
793+
794+
if (StringUtils.isNotEmpty(var.defaultValue)) { // has default value
795+
String defaultValue = var.defaultValue.substring(var.defaultValue.lastIndexOf('.') + 1);
796+
for (Map<String, Object> enumVars : (List<Map<String, Object>>) var.getAllowableValues().get("enumVars")) {
797+
if (defaultValue.equals(enumVars.get("name"))) {
798+
// update default to use the string directly instead of enum string
799+
var.defaultValue = (String) enumVars.get("value");
800+
}
801+
}
802+
}
803+
804+
// add import for Set, HashSet
805+
cm.imports.add("Set");
806+
Map<String, String> importsSet = new HashMap<String, String>();
807+
importsSet.put("import", "java.util.Set");
808+
imports.add(importsSet);
809+
Map<String, String> importsHashSet = new HashMap<String, String>();
810+
importsHashSet.put("import", "java.util.HashSet");
811+
imports.add(importsHashSet);
812+
}
788813
}
789-
}
790-
if (addImports) {
791-
Map<String, String> imports2Classnames = new HashMap<String, String>() {{
792-
put("JsonNullable", "org.openapitools.jackson.nullable.JsonNullable");
793-
put("NoSuchElementException", "java.util.NoSuchElementException");
794-
put("JsonIgnore", "com.fasterxml.jackson.annotation.JsonIgnore");
795-
}};
796-
for (Map.Entry<String, String> entry : imports2Classnames.entrySet()) {
797-
cm.imports.add(entry.getKey());
798-
Map<String, String> importsItem = new HashMap<String, String>();
799-
importsItem.put("import", entry.getValue());
800-
imports.add(importsItem);
814+
815+
if (addImports) {
816+
Map<String, String> imports2Classnames = new HashMap<String, String>() {{
817+
put("JsonNullable", "org.openapitools.jackson.nullable.JsonNullable");
818+
put("NoSuchElementException", "java.util.NoSuchElementException");
819+
put("JsonIgnore", "com.fasterxml.jackson.annotation.JsonIgnore");
820+
}};
821+
for (Map.Entry<String, String> entry : imports2Classnames.entrySet()) {
822+
cm.imports.add(entry.getKey());
823+
Map<String, String> importsItem = new HashMap<String, String>();
824+
importsItem.put("import", entry.getValue());
825+
imports.add(importsItem);
826+
}
801827
}
802828
}
803829
}
804-
}
805830

806-
// add implements for serializable/parcelable to all models
807-
for (Object _mo : models) {
808-
Map<String, Object> mo = (Map<String, Object>) _mo;
809-
CodegenModel cm = (CodegenModel) mo.get("model");
831+
// add implements for serializable/parcelable to all models
832+
for (Object _mo : models) {
833+
Map<String, Object> mo = (Map<String, Object>) _mo;
834+
CodegenModel cm = (CodegenModel) mo.get("model");
835+
836+
cm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
837+
if (JERSEY2.equals(getLibrary())) {
838+
cm.getVendorExtensions().put("x-implements", new ArrayList<String>());
810839

811-
cm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
812-
if (JERSEY2.equals(getLibrary())) {
813-
cm.getVendorExtensions().put("x-implements", new ArrayList<String>());
840+
if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {
841+
// if oneOf contains "null" type
842+
cm.isNullable = true;
843+
cm.oneOf.remove("ModelNull");
844+
}
814845

815-
if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {
816-
// if oneOf contains "null" type
817-
cm.isNullable = true;
818-
cm.oneOf.remove("ModelNull");
846+
if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.contains("ModelNull")) {
847+
// if anyOf contains "null" type
848+
cm.isNullable = true;
849+
cm.anyOf.remove("ModelNull");
850+
}
819851
}
820-
821-
if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.contains("ModelNull")) {
822-
// if anyOf contains "null" type
823-
cm.isNullable = true;
824-
cm.anyOf.remove("ModelNull");
852+
if (this.parcelableModel) {
853+
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Parcelable");
854+
}
855+
if (this.serializableModel) {
856+
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Serializable");
825857
}
826-
}
827-
if (this.parcelableModel) {
828-
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Parcelable");
829-
}
830-
if (this.serializableModel) {
831-
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Serializable");
832858
}
833859
}
834860

@@ -928,8 +954,6 @@ public void forceSerializationLibrary(String serializationLibrary) {
928954
setSerializationLibrary(serializationLibrary);
929955
}
930956

931-
932-
933957
@Override
934958
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
935959
generateYAMLSpecFile(objs);

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

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public void processOpts() {
123123

124124
// Slim 4 doesn't parse JSON body anymore we need to add suggested middleware
125125
// ref: https://www.slimframework.com/docs/v4/objects/request.html#the-request-body
126+
supportingFiles.add(new SupportingFile("htaccess_deny_all", "config", ".htaccess"));
127+
supportingFiles.add(new SupportingFile("config_example.mustache", "config" + File.separator + "dev", "example.inc.php"));
128+
supportingFiles.add(new SupportingFile("config_example.mustache", "config" + File.separator + "prod", "example.inc.php"));
126129
supportingFiles.add(new SupportingFile("json_body_parser_middleware.mustache", toSrcPath(invokerPackage + "\\Middleware", srcBasePath), "JsonBodyParserMiddleware.php"));
127130
supportingFiles.add(new SupportingFile("base_model.mustache", toSrcPath(invokerPackage, srcBasePath), "BaseModel.php"));
128131
supportingFiles.add(new SupportingFile("base_model_test.mustache", toSrcPath(invokerPackage, testBasePath), "BaseModelTest.php"));

0 commit comments

Comments
 (0)