Skip to content

Commit

Permalink
Merge branch 'master' into feature/2901-integrate-property-to-remove-…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
jimschubert committed Aug 31, 2020
2 parents 3ea0019 + d5a680e commit 82a56e7
Show file tree
Hide file tree
Showing 369 changed files with 11,192 additions and 5,192 deletions.
6 changes: 6 additions & 0 deletions bin/configs/go-experimental-extensions-x-auth-id-alias.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: go-experimental
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/go-experimental
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
templateDir: modules/openapi-generator/src/main/resources/go-experimental
additionalProperties:
packageName: x_auth_id_alias
7 changes: 7 additions & 0 deletions bin/configs/java-jersey2-extensions-x-auth-id-alias.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
generatorName: java
outputDir: samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8
library: jersey2
inputSpec: modules/openapi-generator/src/test/resources/3_0/extensions/x-auth-id-alias.yaml
additionalProperties:
artifactId: openapi3-extensions-x-auth-id-alias-jersey2-java8
hideGenerationTimestamp: true
2 changes: 1 addition & 1 deletion bin/configs/spring-boot-beanvalidation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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:
java8: "false"
java8: true
useBeanValidation: true
artifactId: spring-boot-beanvalidation
hideGenerationTimestamp: "true"
2 changes: 1 addition & 1 deletion bin/configs/spring-boot-delegate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
artifactId: springboot-delegate
hideGenerationTimestamp: "true"
java8: "false"
java8: true
delegatePattern: "true"
2 changes: 1 addition & 1 deletion bin/configs/spring-mvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ library: spring-mvc
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:
java8: "false"
java8: true
booleanGetterPrefix: get
artifactId: spring-mvc-server
hideGenerationTimestamp: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1971,14 +1971,18 @@ public String toOneOfName(List<String> names, ComposedSchema composedSchema) {
return "oneOf<" + String.join(",", names) + ">";
}

protected Schema unaliasSchema(Schema schema, Map<String, String> usedImportMappings) {
return ModelUtils.unaliasSchema(this.openAPI, schema, usedImportMappings);
}

/**
* Return a string representation of the schema type, resolving aliasing and references if necessary.
*
* @param schema input
* @return the string representation of the schema type.
*/
protected String getSingleSchemaType(Schema schema) {
Schema unaliasSchema = ModelUtils.unaliasSchema(this.openAPI, schema, importMapping);
Schema unaliasSchema = unaliasSchema(schema, importMapping);

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

// unalias schema
schema = ModelUtils.unaliasSchema(this.openAPI, schema, importMapping);
schema = unaliasSchema(schema, importMapping);
if (schema == null) {
LOGGER.warn("Schema {} not found", name);
return null;
Expand Down Expand Up @@ -2330,7 +2334,7 @@ public CodegenModel fromModel(String name, Schema schema) {
m.interfaces = new ArrayList<String>();

for (Schema interfaceSchema : interfaces) {
interfaceSchema = ModelUtils.unaliasSchema(this.openAPI, interfaceSchema, importMapping);
interfaceSchema = unaliasSchema(interfaceSchema, importMapping);

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

// unalias schema
p = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
p = unaliasSchema(p, importMapping);

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

Expand Down Expand Up @@ -3168,10 +3172,9 @@ public CodegenProperty fromProperty(String name, Schema p) {
} else if (ModelUtils.isArraySchema(p)) {
// default to string if inner item is undefined
ArraySchema arraySchema = (ArraySchema) p;
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getSchemaItems(arraySchema), importMapping);
Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), importMapping);
} else if (ModelUtils.isMapSchema(p)) {
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getAdditionalProperties(p),
importMapping);
Schema innerSchema = unaliasSchema(getAdditionalProperties(p), importMapping);
if (innerSchema == null) {
LOGGER.error("Undefined map inner type for `{}`. Default to String.", p.getName());
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
Expand Down Expand Up @@ -3251,7 +3254,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
itemName = property.name;
}
ArraySchema arraySchema = (ArraySchema) p;
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getSchemaItems(arraySchema), importMapping);
Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), importMapping);
CodegenProperty cp = fromProperty(itemName, innerSchema);
updatePropertyForArray(property, cp);
} else if (ModelUtils.isMapSchema(p)) {
Expand All @@ -3263,8 +3266,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
property.maxItems = p.getMaxProperties();

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

if (responseSchema != null) {
CodegenProperty cm = fromProperty("response", responseSchema);
Expand Down Expand Up @@ -3908,8 +3910,7 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
}
Schema responseSchema;
if (this.openAPI != null && this.openAPI.getComponents() != null) {
responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(response),
importMapping);
responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(response), importMapping);
} else { // no model/alias defined
responseSchema = ModelUtils.getSchemaFromResponse(response);
}
Expand Down Expand Up @@ -4150,7 +4151,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
}

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

}
}
Expand Down Expand Up @@ -5815,7 +5816,7 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
return codegenParameter;
}

private void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set<String> imports, String bodyParameterName, boolean forceSimpleRef) {
protected void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set<String> imports, String bodyParameterName, boolean forceSimpleRef) {
CodegenModel codegenModel = null;
if (StringUtils.isNotBlank(name)) {
schema.setName(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,56 +779,82 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
boolean addImports = false;

if (this.openApiNullable) {
for (CodegenProperty var : cm.vars) {
boolean isOptionalNullable = Boolean.FALSE.equals(var.required) && Boolean.TRUE.equals(var.isNullable);
// only add JsonNullable and related imports to optional and nullable values
addImports |= isOptionalNullable;
var.getVendorExtensions().put("x-is-jackson-optional-nullable", isOptionalNullable);

if (Boolean.TRUE.equals(var.getVendorExtensions().get("x-enum-as-string"))) {
// treat enum string as just string
var.datatypeWithEnum = var.dataType;

if (StringUtils.isNotEmpty(var.defaultValue)) { // has default value
String defaultValue = var.defaultValue.substring(var.defaultValue.lastIndexOf('.') + 1);
for (Map<String, Object> enumVars : (List<Map<String, Object>>) var.getAllowableValues().get("enumVars")) {
if (defaultValue.equals(enumVars.get("name"))) {
// update default to use the string directly instead of enum string
var.defaultValue = (String) enumVars.get("value");
}
}
}

// add import for Set, HashSet
cm.imports.add("Set");
Map<String, String> importsSet = new HashMap<String, String>();
importsSet.put("import", "java.util.Set");
imports.add(importsSet);
Map<String, String> importsHashSet = new HashMap<String, String>();
importsHashSet.put("import", "java.util.HashSet");
imports.add(importsHashSet);
}
}
}
if (addImports) {
Map<String, String> imports2Classnames = new HashMap<String, String>() {{
put("JsonNullable", "org.openapitools.jackson.nullable.JsonNullable");
put("NoSuchElementException", "java.util.NoSuchElementException");
put("JsonIgnore", "com.fasterxml.jackson.annotation.JsonIgnore");
}};
for (Map.Entry<String, String> entry : imports2Classnames.entrySet()) {
cm.imports.add(entry.getKey());
Map<String, String> importsItem = new HashMap<String, String>();
importsItem.put("import", entry.getValue());
imports.add(importsItem);

if (addImports) {
Map<String, String> imports2Classnames = new HashMap<String, String>() {{
put("JsonNullable", "org.openapitools.jackson.nullable.JsonNullable");
put("NoSuchElementException", "java.util.NoSuchElementException");
put("JsonIgnore", "com.fasterxml.jackson.annotation.JsonIgnore");
}};
for (Map.Entry<String, String> entry : imports2Classnames.entrySet()) {
cm.imports.add(entry.getKey());
Map<String, String> importsItem = new HashMap<String, String>();
importsItem.put("import", entry.getValue());
imports.add(importsItem);
}
}
}
}
}

// add implements for serializable/parcelable to all models
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
// add implements for serializable/parcelable to all models
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");

cm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
if (JERSEY2.equals(getLibrary())) {
cm.getVendorExtensions().put("x-implements", new ArrayList<String>());

cm.getVendorExtensions().putIfAbsent("x-implements", new ArrayList<String>());
if (JERSEY2.equals(getLibrary())) {
cm.getVendorExtensions().put("x-implements", new ArrayList<String>());
if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {
// if oneOf contains "null" type
cm.isNullable = true;
cm.oneOf.remove("ModelNull");
}

if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {
// if oneOf contains "null" type
cm.isNullable = true;
cm.oneOf.remove("ModelNull");
if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.contains("ModelNull")) {
// if anyOf contains "null" type
cm.isNullable = true;
cm.anyOf.remove("ModelNull");
}
}

if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.contains("ModelNull")) {
// if anyOf contains "null" type
cm.isNullable = true;
cm.anyOf.remove("ModelNull");
if (this.parcelableModel) {
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Parcelable");
}
if (this.serializableModel) {
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Serializable");
}
}
if (this.parcelableModel) {
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Parcelable");
}
if (this.serializableModel) {
((ArrayList<String>) cm.getVendorExtensions().get("x-implements")).add("Serializable");
}
}

Expand Down Expand Up @@ -928,8 +954,6 @@ public void forceSerializationLibrary(String serializationLibrary) {
setSerializationLibrary(serializationLibrary);
}



@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
generateYAMLSpecFile(objs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public void processOpts() {

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

0 comments on commit 82a56e7

Please sign in to comment.