forked from loafle/openapi-generator-original
Adds ComposedSchema to store schema composed schemas (#10653)
* Adds ComposedSchema and the ability to set it in CodegenModel and CodegenProperty * Adds ComposedSchemas class and adds getters and setters for it in schema implementors * Adds and uses getComposedSchemas * Makes method private * Uses setComposedSchemas for CodegenParameter and CodegenResponse * Samples regeneratoed, tweaked string representation * Removes null default * Removes anyOfProps, oneOfProps, allOfProps * Removes unneeded line
This commit is contained in:
parent
8d490835b7
commit
3a667784ac
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenComposedSchemas {
|
||||
private List<CodegenProperty> allOf;
|
||||
private List<CodegenProperty> oneOf;
|
||||
private List<CodegenProperty> anyOf;
|
||||
|
||||
public CodegenComposedSchemas(List<CodegenProperty> allOf, List<CodegenProperty> oneOf, List<CodegenProperty> anyOf) {
|
||||
this.allOf = allOf;
|
||||
this.oneOf = oneOf;
|
||||
this.anyOf = anyOf;
|
||||
}
|
||||
|
||||
public List<CodegenProperty> getAllOf() {
|
||||
return allOf;
|
||||
}
|
||||
|
||||
public List<CodegenProperty> getOneOf() {
|
||||
return oneOf;
|
||||
}
|
||||
|
||||
public List<CodegenProperty> getAnyOf() {
|
||||
return anyOf;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("CodegenComposedSchemas{");
|
||||
sb.append("oneOf=").append(oneOf);
|
||||
sb.append(", anyOf=").append(anyOf);
|
||||
sb.append(", allOf=").append(allOf);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CodegenComposedSchemas that = (CodegenComposedSchemas) o;
|
||||
return Objects.equals(oneOf, that.oneOf) &&
|
||||
Objects.equals(anyOf, that.anyOf) &&
|
||||
Objects.equals(allOf, that.allOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(oneOf, anyOf, allOf);
|
||||
}
|
||||
}
|
@ -49,11 +49,6 @@ 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.
|
||||
@ -110,6 +105,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
public ExternalDocumentation externalDocumentation;
|
||||
|
||||
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
|
||||
private CodegenComposedSchemas composedSchemas;
|
||||
|
||||
/**
|
||||
* The type of the value for the additionalProperties keyword in the OAS document.
|
||||
@ -810,6 +806,16 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
this.isAnyType = isAnyType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComposedSchemas(CodegenComposedSchemas composedSchemas) {
|
||||
this.composedSchemas = composedSchemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenComposedSchemas getComposedSchemas() {
|
||||
return composedSchemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -849,6 +855,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
getUniqueItems() == that.getUniqueItems() &&
|
||||
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
||||
getExclusiveMaximum() == that.getExclusiveMaximum() &&
|
||||
Objects.equals(composedSchemas, that.composedSchemas) &&
|
||||
Objects.equals(parent, that.parent) &&
|
||||
Objects.equals(parentSchema, that.parentSchema) &&
|
||||
Objects.equals(interfaces, that.interfaces) &&
|
||||
@ -856,9 +863,6 @@ 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) &&
|
||||
@ -921,8 +925,8 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(),
|
||||
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
|
||||
getMaximum(), getPattern(), getMultipleOf(), getItems(), getAdditionalProperties(), getIsModel(),
|
||||
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping, anyOfProps, oneOfProps, allOfProps,
|
||||
isAnyType);
|
||||
getAdditionalPropertiesIsAnyType(), hasDiscriminatorWithNonEmptyMapping,
|
||||
isAnyType, getComposedSchemas());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -938,9 +942,6 @@ 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('\'');
|
||||
@ -1017,6 +1018,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
sb.append(", getAdditionalPropertiesIsAnyType=").append(getAdditionalPropertiesIsAnyType());
|
||||
sb.append(", getHasDiscriminatorWithNonEmptyMapping=").append(hasDiscriminatorWithNonEmptyMapping);
|
||||
sb.append(", getIsAnyType=").append(getIsAnyType());
|
||||
sb.append(", composedSchemas=").append(composedSchemas);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
||||
public boolean isNull;
|
||||
private boolean hasRequired;
|
||||
private boolean hasDiscriminatorWithNonEmptyMapping;
|
||||
private CodegenComposedSchemas composedSchemas;
|
||||
|
||||
public CodegenParameter copy() {
|
||||
CodegenParameter output = new CodegenParameter();
|
||||
@ -159,6 +160,9 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
||||
output.setHasRequired(this.hasRequired);
|
||||
output.setHasDiscriminatorWithNonEmptyMapping(this.hasDiscriminatorWithNonEmptyMapping);
|
||||
|
||||
if (this.composedSchemas != null) {
|
||||
output.setComposedSchemas(this.getComposedSchemas());
|
||||
}
|
||||
if (this._enum != null) {
|
||||
output._enum = new ArrayList<String>(this._enum);
|
||||
}
|
||||
@ -216,7 +220,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping);
|
||||
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -271,6 +275,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
||||
getExclusiveMaximum() == that.getExclusiveMaximum() &&
|
||||
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
||||
getUniqueItems() == that.getUniqueItems() &&
|
||||
Objects.equals(composedSchemas, that.getComposedSchemas()) &&
|
||||
Objects.equals(baseName, that.baseName) &&
|
||||
Objects.equals(paramName, that.paramName) &&
|
||||
Objects.equals(dataType, that.dataType) &&
|
||||
@ -393,6 +398,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
||||
sb.append(", getHasVars=").append(hasVars);
|
||||
sb.append(", getHasRequired=").append(hasRequired);
|
||||
sb.append(", getHasDiscriminatorWithNonEmptyMapping=").append(hasDiscriminatorWithNonEmptyMapping);
|
||||
sb.append(", composedSchemas=").append(composedSchemas);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@ -706,5 +712,15 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
||||
public void setIsAnyType(boolean isAnyType) {
|
||||
this.isAnyType = isAnyType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComposedSchemas(CodegenComposedSchemas composedSchemas) {
|
||||
this.composedSchemas = composedSchemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenComposedSchemas getComposedSchemas() {
|
||||
return composedSchemas;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,6 +191,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
private boolean hasVars;
|
||||
private boolean hasRequired;
|
||||
private boolean hasDiscriminatorWithNonEmptyMapping;
|
||||
private CodegenComposedSchemas composedSchemas = null;
|
||||
|
||||
public String getBaseName() {
|
||||
return baseName;
|
||||
@ -614,6 +615,16 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
this.xmlNamespace = xmlNamespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComposedSchemas(CodegenComposedSchemas composedSchemas) {
|
||||
this.composedSchemas = composedSchemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenComposedSchemas getComposedSchemas() {
|
||||
return composedSchemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty clone() {
|
||||
try {
|
||||
@ -642,6 +653,9 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
if (this.vendorExtensions != null) {
|
||||
cp.vendorExtensions = new HashMap<String, Object>(this.vendorExtensions);
|
||||
}
|
||||
if (this.composedSchemas != null) {
|
||||
cp.composedSchemas = this.composedSchemas;
|
||||
}
|
||||
|
||||
return cp;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
@ -882,6 +896,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
sb.append(", getHasVars=").append(getHasVars());
|
||||
sb.append(", getHasRequired=").append(getHasRequired());
|
||||
sb.append(", getHasDiscriminatorWithNonEmptyMapping=").append(hasDiscriminatorWithNonEmptyMapping);
|
||||
sb.append(", composedSchemas=").append(composedSchemas);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@ -937,6 +952,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
|
||||
getHasVars() == that.getHasVars() &&
|
||||
getHasRequired() ==that.getHasRequired() &&
|
||||
Objects.equals(composedSchemas, that.composedSchemas) &&
|
||||
Objects.equals(openApiType, that.openApiType) &&
|
||||
Objects.equals(baseName, that.baseName) &&
|
||||
Objects.equals(complexType, that.complexType) &&
|
||||
@ -999,6 +1015,6 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
|
||||
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
|
||||
xmlNamespace, isXmlWrapped, isNull, additionalPropertiesIsAnyType, hasVars, hasRequired,
|
||||
hasDiscriminatorWithNonEmptyMapping);
|
||||
hasDiscriminatorWithNonEmptyMapping, composedSchemas);
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
private boolean hasVars;
|
||||
private boolean hasRequired;
|
||||
private boolean hasDiscriminatorWithNonEmptyMapping;
|
||||
private CodegenComposedSchemas composedSchemas;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@ -96,7 +97,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
|
||||
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
|
||||
is1xx, is2xx, is3xx, is4xx, is5xx, additionalPropertiesIsAnyType, hasVars, hasRequired,
|
||||
hasDiscriminatorWithNonEmptyMapping);
|
||||
hasDiscriminatorWithNonEmptyMapping, composedSchemas);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -144,6 +145,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
getAdditionalPropertiesIsAnyType() == that.getAdditionalPropertiesIsAnyType() &&
|
||||
getHasVars() == that.getHasVars() &&
|
||||
getHasRequired() == that.getHasRequired() &&
|
||||
Objects.equals(composedSchemas, that.getComposedSchemas()) &&
|
||||
Objects.equals(vars, that.vars) &&
|
||||
Objects.equals(requiredVars, that.requiredVars) &&
|
||||
Objects.equals(headers, that.headers) &&
|
||||
@ -482,6 +484,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
sb.append(", getHasVars=").append(hasVars);
|
||||
sb.append(", getHasRequired=").append(hasRequired);
|
||||
sb.append(", getHasDiscriminatorWithNonEmptyMapping=").append(hasDiscriminatorWithNonEmptyMapping);
|
||||
sb.append(", composedSchemas=").append(composedSchemas);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@ -570,4 +573,14 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
public void setIsAnyType(boolean isAnyType) {
|
||||
this.isAnyType = isAnyType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComposedSchemas(CodegenComposedSchemas composedSchemas) {
|
||||
this.composedSchemas = composedSchemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenComposedSchemas getComposedSchemas() {
|
||||
return composedSchemas;
|
||||
}
|
||||
}
|
||||
|
@ -2440,9 +2440,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// interfaces (schemas defined in allOf, anyOf, oneOf)
|
||||
List<Schema> interfaces = ModelUtils.getInterfaces(composed);
|
||||
List<CodegenProperty> anyOfProps = new ArrayList<>();
|
||||
List<CodegenProperty> allOfProps = new ArrayList<>();
|
||||
List<CodegenProperty> oneOfProps = new ArrayList<>();
|
||||
if (!interfaces.isEmpty()) {
|
||||
// m.interfaces is for backward compatibility
|
||||
if (m.interfaces == null)
|
||||
@ -2467,7 +2464,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
LOGGER.warn("{} (anyOf schema) already has `{}` defined and therefore it's skipped.", m.name, languageType);
|
||||
} else {
|
||||
m.anyOf.add(languageType);
|
||||
anyOfProps.add(interfaceProperty);
|
||||
|
||||
}
|
||||
} else if (composed.getOneOf() != null) {
|
||||
@ -2475,7 +2471,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
LOGGER.warn("{} (oneOf schema) already has `{}` defined and therefore it's skipped.", m.name, languageType);
|
||||
} else {
|
||||
m.oneOf.add(languageType);
|
||||
oneOfProps.add(interfaceProperty);
|
||||
}
|
||||
} else if (composed.getAllOf() != null) {
|
||||
// no need to add primitive type to allOf, which should comprise of schemas (models) only
|
||||
@ -2511,23 +2506,16 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
if (composed.getAnyOf() != null) {
|
||||
m.anyOf.add(modelName);
|
||||
anyOfProps.add(interfaceProperty);
|
||||
} else if (composed.getOneOf() != null) {
|
||||
m.oneOf.add(modelName);
|
||||
oneOfProps.add(interfaceProperty);
|
||||
} else if (composed.getAllOf() != null) {
|
||||
m.allOf.add(modelName);
|
||||
allOfProps.add(interfaceProperty);
|
||||
} else {
|
||||
LOGGER.error("Composed schema has incorrect anyOf, allOf, oneOf defined: {}", composed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m.oneOfProps = oneOfProps;
|
||||
m.allOfProps = allOfProps;
|
||||
m.anyOfProps = anyOfProps;
|
||||
|
||||
if (parent != null && composed.getAllOf() != null) { // set parent for allOf only
|
||||
m.parentSchema = parentName;
|
||||
m.parent = toModelName(parentName);
|
||||
@ -2696,6 +2684,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
m.setTypeProperties(schema);
|
||||
m.setComposedSchemas(getComposedSchemas(schema));
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
CodegenProperty arrayProperty = fromProperty(name, schema);
|
||||
m.setItems(arrayProperty.items);
|
||||
@ -3514,6 +3503,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
property.setTypeProperties(p);
|
||||
property.setComposedSchemas(getComposedSchemas(p));
|
||||
if (ModelUtils.isIntegerSchema(p)) { // integer type
|
||||
property.isNumeric = Boolean.TRUE;
|
||||
if (ModelUtils.isLongSchema(p)) { // int64/long format
|
||||
@ -4265,6 +4255,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
r.setTypeProperties(responseSchema);
|
||||
r.setComposedSchemas(getComposedSchemas(responseSchema));
|
||||
if (ModelUtils.isArraySchema(responseSchema)) {
|
||||
r.simpleType = false;
|
||||
r.containerType = cp.containerType;
|
||||
@ -4547,6 +4538,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
ModelUtils.syncValidationProperties(parameterSchema, codegenParameter);
|
||||
codegenParameter.setTypeProperties(parameterSchema);
|
||||
codegenParameter.setComposedSchemas(getComposedSchemas(parameterSchema));
|
||||
|
||||
if (Boolean.TRUE.equals(parameterSchema.getNullable())) { // use nullable defined in the spec
|
||||
codegenParameter.isNullable = true;
|
||||
@ -6156,6 +6148,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
Schema ps = unaliasSchema(propertySchema, importMapping);
|
||||
ModelUtils.syncValidationProperties(ps, codegenParameter);
|
||||
codegenParameter.setTypeProperties(ps);
|
||||
codegenParameter.setComposedSchemas(getComposedSchemas(ps));
|
||||
if (ps.getPattern() != null) {
|
||||
codegenParameter.pattern = toRegularExpression(ps.getPattern());
|
||||
}
|
||||
@ -6590,6 +6583,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
ModelUtils.syncValidationProperties(unaliasedSchema, codegenParameter);
|
||||
codegenParameter.setTypeProperties(unaliasedSchema);
|
||||
codegenParameter.setComposedSchemas(getComposedSchemas(unaliasedSchema));
|
||||
// TODO in the future switch al the below schema usages to unaliasedSchema
|
||||
// because it keeps models as refs and will not get their referenced schemas
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
@ -7154,4 +7148,30 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
protected String getCollectionFormat(CodegenParameter codegenParameter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private CodegenComposedSchemas getComposedSchemas(Schema schema) {
|
||||
if (!(schema instanceof ComposedSchema)) {
|
||||
return null;
|
||||
}
|
||||
ComposedSchema cs = (ComposedSchema) schema;
|
||||
return new CodegenComposedSchemas(
|
||||
getComposedProperties(cs.getAllOf(), "allOf"),
|
||||
getComposedProperties(cs.getOneOf(), "oneOf"),
|
||||
getComposedProperties(cs.getAnyOf(), "anyOf")
|
||||
);
|
||||
}
|
||||
|
||||
private List<CodegenProperty> getComposedProperties(List<Schema> xOfCollection, String collectionName) {
|
||||
if (xOfCollection == null) {
|
||||
return null;
|
||||
}
|
||||
List<CodegenProperty> xOf = new ArrayList<>();
|
||||
int i = 0;
|
||||
for (Schema xOfSchema: xOfCollection) {
|
||||
CodegenProperty cp = fromProperty(collectionName + "_" + String.valueOf(i), xOfSchema);
|
||||
xOf.add(cp);
|
||||
i += 1;
|
||||
}
|
||||
return xOf;
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,11 @@ public interface IJsonSchemaValidationProperties {
|
||||
|
||||
void setIsAnyType(boolean isAnyType);
|
||||
|
||||
CodegenComposedSchemas getComposedSchemas();
|
||||
|
||||
void setComposedSchemas(CodegenComposedSchemas composedSchemas);
|
||||
|
||||
|
||||
/**
|
||||
* Syncs all the schema's type properties into the IJsonSchemaValidationProperties instance
|
||||
* for now this only supports types without format information
|
||||
|
@ -539,10 +539,10 @@ public interface PathHandlerInterface {
|
||||
* <p><b>Response headers</b>: [CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', title='null', unescapedDescription='calls per hour allowed by the user', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
|
||||
"type" : "integer",
|
||||
"format" : "int32"
|
||||
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
|
||||
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
|
||||
"type" : "string",
|
||||
"format" : "date-time"
|
||||
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false}]</p>
|
||||
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null}]</p>
|
||||
*
|
||||
* <p><b>Produces</b>: [{mediaType=application/xml}, {mediaType=application/json}]</p>
|
||||
* <p><b>Returns</b>: {@link String}</p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user