Add oneOfProps, allOfProps, anyOfProps to Codegen model (#10231)

* add oneOfProps, allOfProps, anyOfProps to codegen model

* remove commented code
This commit is contained in:
William Cheng
2021-08-23 12:03:34 +08:00
committed by GitHub
parent bcd2459a8d
commit 158649aff9
2 changed files with 15 additions and 4 deletions

View File

@@ -49,6 +49,11 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
public Set<String> oneOf = new TreeSet<String>();
public Set<String> allOf = new TreeSet<String>();
// anyOf, oneOf, allOf with full properties/tags (e.g. isString, etc)
public List<CodegenProperty> anyOfProps = new ArrayList<>();
public List<CodegenProperty> allOfProps = new ArrayList<>();
public List<CodegenProperty> oneOfProps = new ArrayList<>();
// The schema name as written in the OpenAPI document.
public String name;
// The language-specific name of the class that implements this schema.
@@ -825,6 +830,9 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
Objects.equals(parentModel, that.parentModel) &&
Objects.equals(interfaceModels, that.interfaceModels) &&
Objects.equals(children, that.children) &&
Objects.equals(anyOf, that.anyOfProps) &&
Objects.equals(oneOf, that.oneOfProps) &&
Objects.equals(allOf, that.allOfProps) &&
Objects.equals(anyOf, that.anyOf) &&
Objects.equals(oneOf, that.oneOf) &&
Objects.equals(allOf, that.allOf) &&
@@ -887,7 +895,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(),
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
getMaximum(), getPattern(), getMultipleOf(), getItems(), getAdditionalProperties(), getIsModel(),
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping);
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping, anyOfProps, oneOfProps, allOfProps);
}
@Override
@@ -903,6 +911,9 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
sb.append(", anyOf=").append(anyOf);
sb.append(", oneOf=").append(oneOf);
sb.append(", allOf=").append(allOf);
sb.append(", anyOf=").append(anyOfProps);
sb.append(", oneOf=").append(oneOfProps);
sb.append(", allOf=").append(allOfProps);
sb.append(", name='").append(name).append('\'');
sb.append(", classname='").append(classname).append('\'');
sb.append(", title='").append(title).append('\'');

View File

@@ -2572,9 +2572,9 @@ public class DefaultCodegen implements CodegenConfig {
}
}
m.vendorExtensions.put("x-oneOf-as-properties", oneOfProps);
m.vendorExtensions.put("x-allOf-as-properties", allOfProps);
m.vendorExtensions.put("x-anyOf-as-properties", anyOfProps);
m.oneOfProps = oneOfProps;
m.allOfProps = allOfProps;
m.anyOfProps = anyOfProps;
if (parent != null && composed.getAllOf() != null) { // set parent for allOf only
m.parentSchema = parentName;