forked from loafle/openapi-generator-original
Adds hasValidation to all java core Schema classes (#8474)
* Adds hasValidation to IJsonSchemaValidationProperties * Adds model validation examples for maxItems, minItems, minProperties, maxProperties, minLength, maxLength, multipleOf * Adds schemas with pattern validation * Adds minimum example schemas * Adds maximum example schemas * Adds ArrayWithUniqueItems * Adds exclusiveMinimum schemas * Adds exclusiveMaximum examples * adds testModelGetHasValidation * Adds testPropertyGetHasValidation * Adds testQueryParametersGetHasValidation * Uncomments out query parameters * Adds testHeaderParametersGetHasValidation * Adds testCookieParametersGetHasValidation * Adds length assertions for properties and marameters * Adds testBodyAndResponseGetHasValidation * Improves validation setting * Only sets exclusiveMinimum when minimum is set, only set exclusiveMaximum when maximum is set * Adds fix for rust * Fixes min and max setting for integers * Regenerates python samples * Updates code so python sample does not change
This commit is contained in:
parent
3d23b99242
commit
2331432cc0
@ -79,7 +79,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
|
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
|
||||||
|
|
||||||
public Set<String> imports = new TreeSet<String>();
|
public Set<String> imports = new TreeSet<String>();
|
||||||
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum;
|
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasValidation;
|
||||||
/**
|
/**
|
||||||
* Indicates the OAS schema specifies "nullable: true".
|
* Indicates the OAS schema specifies "nullable: true".
|
||||||
*/
|
*/
|
||||||
@ -612,12 +612,11 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
this.additionalProperties = additionalProperties;
|
this.additionalProperties = additionalProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
// indicates if the model component has validation on the root level schema
|
@Override
|
||||||
// this will be true when minItems or minProperties is set
|
public boolean getHasValidation() { return hasValidation; }
|
||||||
public boolean hasValidation() {
|
|
||||||
boolean val = (maxItems != null || minItems != null || minProperties != null || maxProperties != null || minLength != null || maxLength != null || multipleOf != null || pattern != null || minimum != null || maximum != null || Boolean.TRUE.equals(uniqueItems) || Boolean.TRUE.equals(exclusiveMaximum) || Boolean.TRUE.equals(exclusiveMinimum));
|
@Override
|
||||||
return val;
|
public void setHasValidation(boolean hasValidation) { this.hasValidation = hasValidation; }
|
||||||
}
|
|
||||||
|
|
||||||
public List<CodegenProperty> getReadOnlyVars() {
|
public List<CodegenProperty> getReadOnlyVars() {
|
||||||
return readOnlyVars;
|
return readOnlyVars;
|
||||||
@ -742,6 +741,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
isDeprecated == that.isDeprecated &&
|
isDeprecated == that.isDeprecated &&
|
||||||
hasOnlyReadOnly == that.hasOnlyReadOnly &&
|
hasOnlyReadOnly == that.hasOnlyReadOnly &&
|
||||||
isNull == that.isNull &&
|
isNull == that.isNull &&
|
||||||
|
hasValidation == that.hasValidation &&
|
||||||
getUniqueItems() == that.getUniqueItems() &&
|
getUniqueItems() == that.getUniqueItems() &&
|
||||||
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
||||||
getExclusiveMaximum() == that.getExclusiveMaximum() &&
|
getExclusiveMaximum() == that.getExclusiveMaximum() &&
|
||||||
@ -806,7 +806,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
getDescription(), getClassVarName(), getModelJson(), getDataType(), getXmlPrefix(), getXmlNamespace(),
|
getDescription(), getClassVarName(), getModelJson(), getDataType(), getXmlPrefix(), getXmlNamespace(),
|
||||||
getXmlName(), getClassFilename(), getUnescapedDescription(), getDiscriminator(), getDefaultValue(),
|
getXmlName(), getClassFilename(), getUnescapedDescription(), getDiscriminator(), getDefaultValue(),
|
||||||
getArrayModelType(), isAlias, isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble,
|
getArrayModelType(), isAlias, isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble,
|
||||||
isDate, isDateTime, isNull,
|
isDate, isDateTime, isNull, hasValidation,
|
||||||
getVars(), getAllVars(), getRequiredVars(), getOptionalVars(), getReadOnlyVars(), getReadWriteVars(),
|
getVars(), getAllVars(), getRequiredVars(), getOptionalVars(), getReadOnlyVars(), getReadWriteVars(),
|
||||||
getParentVars(), getAllowableValues(), getMandatory(), getAllMandatory(), getImports(), hasVars,
|
getParentVars(), getAllowableValues(), getMandatory(), getAllMandatory(), getImports(), hasVars,
|
||||||
isEmptyVars(), hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArray,
|
isEmptyVars(), hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArray,
|
||||||
@ -898,6 +898,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
sb.append(", additionalProperties='").append(additionalProperties).append('\'');
|
sb.append(", additionalProperties='").append(additionalProperties).append('\'');
|
||||||
sb.append(", isModel='").append(isModel).append('\'');
|
sb.append(", isModel='").append(isModel).append('\'');
|
||||||
sb.append(", isNull='").append(isNull);
|
sb.append(", isNull='").append(isNull);
|
||||||
|
sb.append(", hasValidation='").append(hasValidation);
|
||||||
sb.append('}');
|
sb.append('}');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -582,5 +582,11 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
public void setIsNull(boolean isNull) {
|
public void setIsNull(boolean isNull) {
|
||||||
this.isNull = isNull;
|
this.isNull = isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getHasValidation() { return hasValidation; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHasValidation(boolean hasValidation) { this.hasValidation = hasValidation; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -687,6 +687,12 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
|||||||
this.isNull = isNull;
|
this.isNull = isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getHasValidation() { return hasValidation; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHasValidation(boolean hasValidation) { this.hasValidation = hasValidation; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder("CodegenProperty{");
|
final StringBuilder sb = new StringBuilder("CodegenProperty{");
|
||||||
|
@ -78,6 +78,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
public CodegenProperty additionalProperties;
|
public CodegenProperty additionalProperties;
|
||||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>(); // all properties (without parent's properties)
|
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>(); // all properties (without parent's properties)
|
||||||
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>();
|
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>();
|
||||||
|
private boolean hasValidation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
@ -85,7 +86,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBoolean, isDate,
|
isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBoolean, isDate,
|
||||||
isDateTime, isUuid, isEmail, isModel, isFreeFormObject, isAnyType, isDefault, simpleType, primitiveType,
|
isDateTime, isUuid, isEmail, isModel, isFreeFormObject, isAnyType, isDefault, simpleType, primitiveType,
|
||||||
isMap, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
|
isMap, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
|
||||||
vars, requiredVars, isNull,
|
vars, requiredVars, isNull, hasValidation,
|
||||||
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
|
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
|
||||||
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
|
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
|
||||||
is1xx, is2xx, is3xx, is4xx, is5xx);
|
is1xx, is2xx, is3xx, is4xx, is5xx);
|
||||||
@ -124,6 +125,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
items == that.items &&
|
items == that.items &&
|
||||||
additionalProperties == that.additionalProperties &&
|
additionalProperties == that.additionalProperties &&
|
||||||
isNull == that.isNull &&
|
isNull == that.isNull &&
|
||||||
|
hasValidation == that.hasValidation &&
|
||||||
is1xx == that.is1xx &&
|
is1xx == that.is1xx &&
|
||||||
is2xx == that.is2xx &&
|
is2xx == that.is2xx &&
|
||||||
is3xx == that.is3xx &&
|
is3xx == that.is3xx &&
|
||||||
@ -426,6 +428,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
sb.append(", vars='").append(vars).append('\'');
|
sb.append(", vars='").append(vars).append('\'');
|
||||||
sb.append(", requiredVars='").append(requiredVars).append('\'');
|
sb.append(", requiredVars='").append(requiredVars).append('\'');
|
||||||
sb.append(", isNull='").append(isNull);
|
sb.append(", isNull='").append(isNull);
|
||||||
|
sb.append(", hasValidation='").append(hasValidation);
|
||||||
sb.append('}');
|
sb.append('}');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
@ -456,4 +459,10 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
|||||||
public void setIsNull(boolean isNull) {
|
public void setIsNull(boolean isNull) {
|
||||||
this.isNull = isNull;
|
this.isNull = isNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getHasValidation() { return hasValidation; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHasValidation(boolean hasValidation) { this.hasValidation = hasValidation; }
|
||||||
}
|
}
|
||||||
|
@ -2258,6 +2258,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
|
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
|
||||||
|
ModelUtils.syncValidationProperties(schema, m);
|
||||||
|
|
||||||
if (reservedWords.contains(name)) {
|
if (reservedWords.contains(name)) {
|
||||||
m.name = escapeReservedWord(name);
|
m.name = escapeReservedWord(name);
|
||||||
@ -2305,7 +2306,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
m.setItems(arrayProperty.items);
|
m.setItems(arrayProperty.items);
|
||||||
m.arrayModelType = arrayProperty.complexType;
|
m.arrayModelType = arrayProperty.complexType;
|
||||||
addParentContainer(m, name, schema);
|
addParentContainer(m, name, schema);
|
||||||
ModelUtils.syncValidationProperties(schema, m);
|
|
||||||
} else if (ModelUtils.isNullType(schema)) {
|
} else if (ModelUtils.isNullType(schema)) {
|
||||||
m.isNull = true;
|
m.isNull = true;
|
||||||
} else if (schema instanceof ComposedSchema) {
|
} else if (schema instanceof ComposedSchema) {
|
||||||
@ -2500,8 +2500,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
m.isMap = true;
|
m.isMap = true;
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) { // integer type
|
} else if (ModelUtils.isIntegerSchema(schema)) { // integer type
|
||||||
// NOTE: Integral schemas as CodegenModel is a rare use case and may be removed at a later date.
|
// NOTE: Integral schemas as CodegenModel is a rare use case and may be removed at a later date.
|
||||||
// Sync of properties is done for consistency with other data types like CodegenParameter/CodegenProperty.
|
|
||||||
ModelUtils.syncValidationProperties(schema, m);
|
|
||||||
|
|
||||||
m.isNumeric = Boolean.TRUE;
|
m.isNumeric = Boolean.TRUE;
|
||||||
if (ModelUtils.isLongSchema(schema)) { // int64/long format
|
if (ModelUtils.isLongSchema(schema)) { // int64/long format
|
||||||
@ -2511,23 +2509,15 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
} else if (ModelUtils.isDateTimeSchema(schema)) {
|
||||||
// NOTE: DateTime schemas as CodegenModel is a rare use case and may be removed at a later date.
|
// NOTE: DateTime schemas as CodegenModel is a rare use case and may be removed at a later date.
|
||||||
// Sync of properties is done for consistency with other data types like CodegenParameter/CodegenProperty.
|
|
||||||
ModelUtils.syncValidationProperties(schema, m);
|
|
||||||
m.isDateTime = Boolean.TRUE;
|
m.isDateTime = Boolean.TRUE;
|
||||||
} else if (ModelUtils.isDateSchema(schema)) {
|
} else if (ModelUtils.isDateSchema(schema)) {
|
||||||
// NOTE: Date schemas as CodegenModel is a rare use case and may be removed at a later date.
|
// NOTE: Date schemas as CodegenModel is a rare use case and may be removed at a later date.
|
||||||
// Sync of properties is done for consistency with other data types like CodegenParameter/CodegenProperty.
|
|
||||||
ModelUtils.syncValidationProperties(schema, m);
|
|
||||||
m.isDate = Boolean.TRUE;
|
m.isDate = Boolean.TRUE;
|
||||||
} else if (ModelUtils.isStringSchema(schema)) {
|
} else if (ModelUtils.isStringSchema(schema)) {
|
||||||
// NOTE: String schemas as CodegenModel is a rare use case and may be removed at a later date.
|
// NOTE: String schemas as CodegenModel is a rare use case and may be removed at a later date.
|
||||||
// Sync of properties is done for consistency with other data types like CodegenParameter/CodegenProperty.
|
|
||||||
ModelUtils.syncValidationProperties(schema, m);
|
|
||||||
m.isString = Boolean.TRUE;
|
m.isString = Boolean.TRUE;
|
||||||
} else if (ModelUtils.isNumberSchema(schema)) {
|
} else if (ModelUtils.isNumberSchema(schema)) {
|
||||||
// NOTE: Number schemas as CodegenModel is a rare use case and may be removed at a later date.
|
// NOTE: Number schemas as CodegenModel is a rare use case and may be removed at a later date.
|
||||||
// Sync of properties is done for consistency with other data types like CodegenParameter/CodegenProperty.
|
|
||||||
ModelUtils.syncValidationProperties(schema, m);
|
|
||||||
m.isNumeric = Boolean.TRUE;
|
m.isNumeric = Boolean.TRUE;
|
||||||
if (ModelUtils.isFloatSchema(schema)) { // float
|
if (ModelUtils.isFloatSchema(schema)) { // float
|
||||||
m.isFloat = Boolean.TRUE;
|
m.isFloat = Boolean.TRUE;
|
||||||
@ -2538,7 +2528,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
} else if (ModelUtils.isFreeFormObject(openAPI, schema)) {
|
} else if (ModelUtils.isFreeFormObject(openAPI, schema)) {
|
||||||
addAdditionPropertiesToCodeGenModel(m, schema);
|
addAdditionPropertiesToCodeGenModel(m, schema);
|
||||||
ModelUtils.syncValidationProperties(schema, m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Boolean.TRUE.equals(schema.getNullable())) {
|
if (Boolean.TRUE.equals(schema.getNullable())) {
|
||||||
@ -3077,7 +3066,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
p = unaliasSchema(p, importMapping);
|
p = unaliasSchema(p, importMapping);
|
||||||
|
|
||||||
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
||||||
|
|
||||||
ModelUtils.syncValidationProperties(p, property);
|
ModelUtils.syncValidationProperties(p, property);
|
||||||
|
|
||||||
property.name = toVarName(name);
|
property.name = toVarName(name);
|
||||||
@ -3144,27 +3132,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
property.isInteger = Boolean.TRUE;
|
property.isInteger = Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.getMinimum() != null) {
|
|
||||||
property.minimum = String.valueOf(p.getMinimum().longValue());
|
|
||||||
}
|
|
||||||
if (p.getMaximum() != null) {
|
|
||||||
property.maximum = String.valueOf(p.getMaximum().longValue());
|
|
||||||
}
|
|
||||||
if (p.getExclusiveMinimum() != null) {
|
|
||||||
property.exclusiveMinimum = p.getExclusiveMinimum();
|
|
||||||
}
|
|
||||||
if (p.getExclusiveMaximum() != null) {
|
|
||||||
property.exclusiveMaximum = p.getExclusiveMaximum();
|
|
||||||
}
|
|
||||||
if (p.getMultipleOf() != null) {
|
|
||||||
property.multipleOf = p.getMultipleOf();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if any validation rule defined
|
|
||||||
// exclusive* are noop without corresponding min/max
|
|
||||||
if (property.minimum != null || property.maximum != null || p.getMultipleOf() != null)
|
|
||||||
property.hasValidation = true;
|
|
||||||
|
|
||||||
} else if (ModelUtils.isBooleanSchema(p)) { // boolean type
|
} else if (ModelUtils.isBooleanSchema(p)) { // boolean type
|
||||||
property.isBoolean = true;
|
property.isBoolean = true;
|
||||||
property.getter = toBooleanGetter(name);
|
property.getter = toBooleanGetter(name);
|
||||||
@ -3177,27 +3144,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
property.isDateTime = true;
|
property.isDateTime = true;
|
||||||
} else if (ModelUtils.isDecimalSchema(p)) { // type: string, format: number
|
} else if (ModelUtils.isDecimalSchema(p)) { // type: string, format: number
|
||||||
property.isDecimal = true;
|
property.isDecimal = true;
|
||||||
if (p.getMinimum() != null) {
|
|
||||||
property.minimum = String.valueOf(p.getMinimum());
|
|
||||||
}
|
|
||||||
if (p.getMaximum() != null) {
|
|
||||||
property.maximum = String.valueOf(p.getMaximum());
|
|
||||||
}
|
|
||||||
if (p.getExclusiveMinimum() != null) {
|
|
||||||
property.exclusiveMinimum = p.getExclusiveMinimum();
|
|
||||||
}
|
|
||||||
if (p.getExclusiveMaximum() != null) {
|
|
||||||
property.exclusiveMaximum = p.getExclusiveMaximum();
|
|
||||||
}
|
|
||||||
if (p.getMultipleOf() != null) {
|
|
||||||
property.multipleOf = p.getMultipleOf();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if any validation rule defined
|
|
||||||
// exclusive* are noop without corresponding min/max
|
|
||||||
if (property.minimum != null || property.maximum != null || p.getMultipleOf() != null) {
|
|
||||||
property.hasValidation = true;
|
|
||||||
}
|
|
||||||
} else if (ModelUtils.isStringSchema(p)) {
|
} else if (ModelUtils.isStringSchema(p)) {
|
||||||
if (ModelUtils.isByteArraySchema(p)) {
|
if (ModelUtils.isByteArraySchema(p)) {
|
||||||
property.isByteArray = true;
|
property.isByteArray = true;
|
||||||
@ -3219,15 +3165,8 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
} else {
|
} else {
|
||||||
property.isString = true;
|
property.isString = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
property.maxLength = p.getMaxLength();
|
|
||||||
property.minLength = p.getMinLength();
|
|
||||||
property.pattern = toRegularExpression(p.getPattern());
|
property.pattern = toRegularExpression(p.getPattern());
|
||||||
|
|
||||||
// check if any validation rule defined
|
|
||||||
if (property.pattern != null || property.minLength != null || property.maxLength != null)
|
|
||||||
property.hasValidation = true;
|
|
||||||
|
|
||||||
} else if (ModelUtils.isNumberSchema(p)) {
|
} else if (ModelUtils.isNumberSchema(p)) {
|
||||||
property.isNumeric = Boolean.TRUE;
|
property.isNumeric = Boolean.TRUE;
|
||||||
if (ModelUtils.isFloatSchema(p)) { // float
|
if (ModelUtils.isFloatSchema(p)) { // float
|
||||||
@ -3238,28 +3177,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
property.isNumber = Boolean.TRUE;
|
property.isNumber = Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.getMinimum() != null) {
|
|
||||||
property.minimum = String.valueOf(p.getMinimum());
|
|
||||||
}
|
|
||||||
if (p.getMaximum() != null) {
|
|
||||||
property.maximum = String.valueOf(p.getMaximum());
|
|
||||||
}
|
|
||||||
if (p.getExclusiveMinimum() != null) {
|
|
||||||
property.exclusiveMinimum = p.getExclusiveMinimum();
|
|
||||||
}
|
|
||||||
if (p.getExclusiveMaximum() != null) {
|
|
||||||
property.exclusiveMaximum = p.getExclusiveMaximum();
|
|
||||||
}
|
|
||||||
if (p.getMultipleOf() != null) {
|
|
||||||
property.multipleOf = p.getMultipleOf();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if any validation rule defined
|
|
||||||
// exclusive* are noop without corresponding min/max
|
|
||||||
if (property.minimum != null || property.maximum != null || p.getMultipleOf() != null) {
|
|
||||||
property.hasValidation = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (isFreeFormObject(p)) {
|
} else if (isFreeFormObject(p)) {
|
||||||
property.isFreeFormObject = true;
|
property.isFreeFormObject = true;
|
||||||
} else if (isAnyTypeSchema(p)) {
|
} else if (isAnyTypeSchema(p)) {
|
||||||
@ -3347,8 +3264,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle inner property
|
// handle inner property
|
||||||
property.maxItems = p.getMaxItems();
|
|
||||||
property.minItems = p.getMinItems();
|
|
||||||
String itemName = null;
|
String itemName = null;
|
||||||
if (p.getExtensions() != null && p.getExtensions().get("x-item-name") != null) {
|
if (p.getExtensions() != null && p.getExtensions().get("x-item-name") != null) {
|
||||||
itemName = p.getExtensions().get("x-item-name").toString();
|
itemName = p.getExtensions().get("x-item-name").toString();
|
||||||
@ -3365,6 +3280,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
property.isMap = true;
|
property.isMap = true;
|
||||||
property.containerType = "map";
|
property.containerType = "map";
|
||||||
property.baseType = getSchemaType(p);
|
property.baseType = getSchemaType(p);
|
||||||
|
// TODO remove this hack in the future, code should use minProperties and maxProperties for object schemas
|
||||||
property.minItems = p.getMinProperties();
|
property.minItems = p.getMinProperties();
|
||||||
property.maxItems = p.getMaxProperties();
|
property.maxItems = p.getMaxProperties();
|
||||||
|
|
||||||
@ -3983,20 +3899,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
|
public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
|
||||||
CodegenResponse r = CodegenModelFactory.newInstance(CodegenModelType.RESPONSE);
|
CodegenResponse r = CodegenModelFactory.newInstance(CodegenModelType.RESPONSE);
|
||||||
|
|
||||||
if (response.getContent() != null && response.getContent().size() > 0) {
|
|
||||||
// Ensure validation properties from a target schema are persisted on CodegenResponse.
|
|
||||||
// This ignores any edge case where different schemas have different validations because we don't
|
|
||||||
// have a way to indicate a preference for response schema and are effective 1:1.
|
|
||||||
Schema contentSchema = null;
|
|
||||||
for (MediaType mt : response.getContent().values()) {
|
|
||||||
if (contentSchema != null) break;
|
|
||||||
contentSchema = mt.getSchema();
|
|
||||||
}
|
|
||||||
if (contentSchema != null) {
|
|
||||||
ModelUtils.syncValidationProperties(contentSchema, r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("default".equals(responseCode) || "defaultResponse".equals(responseCode)) {
|
if ("default".equals(responseCode) || "defaultResponse".equals(responseCode)) {
|
||||||
r.code = "0";
|
r.code = "0";
|
||||||
r.isDefault = true;
|
r.isDefault = true;
|
||||||
@ -4030,8 +3932,11 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
responseSchema = ModelUtils.getSchemaFromResponse(response);
|
responseSchema = ModelUtils.getSchemaFromResponse(response);
|
||||||
}
|
}
|
||||||
r.schema = responseSchema;
|
r.schema = responseSchema;
|
||||||
if (responseSchema != null && responseSchema.getPattern() != null) {
|
if (responseSchema != null) {
|
||||||
r.setPattern(toRegularExpression(responseSchema.getPattern()));
|
ModelUtils.syncValidationProperties(responseSchema, r);
|
||||||
|
if (responseSchema.getPattern() != null) {
|
||||||
|
r.setPattern(toRegularExpression(responseSchema.getPattern()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.message = escapeText(response.getDescription());
|
r.message = escapeText(response.getDescription());
|
||||||
@ -4219,20 +4124,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
public CodegenParameter fromParameter(Parameter parameter, Set<String> imports) {
|
public CodegenParameter fromParameter(Parameter parameter, Set<String> imports) {
|
||||||
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
|
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
|
||||||
|
|
||||||
if (parameter.getContent() != null && parameter.getContent().size() > 0) {
|
|
||||||
// Ensure validation properties from a target schema are persisted on CodegenParameter.
|
|
||||||
// This ignores any edge case where different schemas have different validations because we don't
|
|
||||||
// have a way to indicate a preference for parameter schema and are effective 1:1.
|
|
||||||
Schema contentSchema = null;
|
|
||||||
for (MediaType mt : parameter.getContent().values()) {
|
|
||||||
if (contentSchema != null) break;
|
|
||||||
contentSchema = mt.getSchema();
|
|
||||||
}
|
|
||||||
if (contentSchema != null) {
|
|
||||||
ModelUtils.syncValidationProperties(contentSchema, codegenParameter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
codegenParameter.baseName = parameter.getName();
|
codegenParameter.baseName = parameter.getName();
|
||||||
codegenParameter.description = escapeText(parameter.getDescription());
|
codegenParameter.description = escapeText(parameter.getDescription());
|
||||||
codegenParameter.unescapedDescription = parameter.getDescription();
|
codegenParameter.unescapedDescription = parameter.getDescription();
|
||||||
@ -4271,6 +4162,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
LOGGER.warn("warning! Schema not found for parameter \"" + parameter.getName() + "\", using String");
|
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.");
|
parameterSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to missing type definition.");
|
||||||
}
|
}
|
||||||
|
ModelUtils.syncValidationProperties(parameterSchema, codegenParameter);
|
||||||
|
|
||||||
if (Boolean.TRUE.equals(parameterSchema.getNullable())) { // use nullable defined in the spec
|
if (Boolean.TRUE.equals(parameterSchema.getNullable())) { // use nullable defined in the spec
|
||||||
codegenParameter.isNullable = true;
|
codegenParameter.isNullable = true;
|
||||||
@ -6029,9 +5921,10 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
if (StringUtils.isNotBlank(schema.get$ref())) {
|
if (StringUtils.isNotBlank(schema.get$ref())) {
|
||||||
name = ModelUtils.getSimpleRef(schema.get$ref());
|
name = ModelUtils.getSimpleRef(schema.get$ref());
|
||||||
}
|
}
|
||||||
|
Schema validationSchema = unaliasSchema(schema, importMapping);
|
||||||
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
|
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
|
||||||
|
|
||||||
ModelUtils.syncValidationProperties(schema, codegenParameter);
|
ModelUtils.syncValidationProperties(validationSchema, codegenParameter);
|
||||||
|
|
||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (ModelUtils.isMapSchema(schema)) {
|
||||||
// Schema with additionalproperties: true (including composed schemas with additionalproperties: true)
|
// Schema with additionalproperties: true (including composed schemas with additionalproperties: true)
|
||||||
@ -6159,12 +6052,6 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
codegenParameter.dataType = codegenProperty.dataType;
|
codegenParameter.dataType = codegenProperty.dataType;
|
||||||
codegenParameter.description = codegenProperty.description;
|
codegenParameter.description = codegenProperty.description;
|
||||||
codegenParameter.paramName = toParamName(codegenParameter.baseName);
|
codegenParameter.paramName = toParamName(codegenParameter.baseName);
|
||||||
codegenParameter.minimum = codegenProperty.minimum;
|
|
||||||
codegenParameter.maximum = codegenProperty.maximum;
|
|
||||||
codegenParameter.exclusiveMinimum = codegenProperty.exclusiveMinimum;
|
|
||||||
codegenParameter.exclusiveMaximum = codegenProperty.exclusiveMaximum;
|
|
||||||
codegenParameter.minLength = codegenProperty.minLength;
|
|
||||||
codegenParameter.maxLength = codegenProperty.maxLength;
|
|
||||||
codegenParameter.pattern = codegenProperty.pattern;
|
codegenParameter.pattern = codegenProperty.pattern;
|
||||||
codegenParameter.isNullable = codegenProperty.isNullable;
|
codegenParameter.isNullable = codegenProperty.isNullable;
|
||||||
|
|
||||||
|
@ -94,4 +94,8 @@ public interface IJsonSchemaValidationProperties {
|
|||||||
boolean getIsNull();
|
boolean getIsNull();
|
||||||
|
|
||||||
void setIsNull(boolean isNull);
|
void setIsNull(boolean isNull);
|
||||||
|
|
||||||
|
boolean getHasValidation();
|
||||||
|
|
||||||
|
void setHasValidation(boolean hasValidation);
|
||||||
}
|
}
|
||||||
|
@ -1489,30 +1489,89 @@ public class ModelUtils {
|
|||||||
|
|
||||||
public static void syncValidationProperties(Schema schema, IJsonSchemaValidationProperties target) {
|
public static void syncValidationProperties(Schema schema, IJsonSchemaValidationProperties target) {
|
||||||
if (schema != null && target != null) {
|
if (schema != null && target != null) {
|
||||||
target.setPattern(schema.getPattern());
|
if (isNullType(schema) || schema.get$ref() != null || isBooleanSchema(schema)) {
|
||||||
BigDecimal minimum = schema.getMinimum();
|
return;
|
||||||
BigDecimal maximum = schema.getMaximum();
|
}
|
||||||
Boolean exclusiveMinimum = schema.getExclusiveMinimum();
|
boolean isAnyType = (schema.getClass().equals(Schema.class) && schema.get$ref() == null && schema.getType() == null &&
|
||||||
Boolean exclusiveMaximum = schema.getExclusiveMaximum();
|
(schema.getProperties() == null || schema.getProperties().isEmpty()) &&
|
||||||
Integer minLength = schema.getMinLength();
|
schema.getAdditionalProperties() == null && schema.getNot() == null &&
|
||||||
Integer maxLength = schema.getMaxLength();
|
schema.getEnum() == null);
|
||||||
|
if (isAnyType) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Integer minItems = schema.getMinItems();
|
Integer minItems = schema.getMinItems();
|
||||||
Integer maxItems = schema.getMaxItems();
|
Integer maxItems = schema.getMaxItems();
|
||||||
Boolean uniqueItems = schema.getUniqueItems();
|
Boolean uniqueItems = schema.getUniqueItems();
|
||||||
Integer minProperties = schema.getMinProperties();
|
Integer minProperties = schema.getMinProperties();
|
||||||
Integer maxProperties = schema.getMaxProperties();
|
Integer maxProperties = schema.getMaxProperties();
|
||||||
|
Integer minLength = schema.getMinLength();
|
||||||
|
Integer maxLength = schema.getMaxLength();
|
||||||
|
String pattern = schema.getPattern();
|
||||||
|
BigDecimal multipleOf = schema.getMultipleOf();
|
||||||
|
BigDecimal minimum = schema.getMinimum();
|
||||||
|
BigDecimal maximum = schema.getMaximum();
|
||||||
|
Boolean exclusiveMinimum = schema.getExclusiveMinimum();
|
||||||
|
Boolean exclusiveMaximum = schema.getExclusiveMaximum();
|
||||||
|
|
||||||
if (minimum != null) target.setMinimum(String.valueOf(minimum));
|
if (isArraySchema(schema)) {
|
||||||
if (maximum != null) target.setMaximum(String.valueOf(maximum));
|
setArrayValidations(minItems, maxItems, uniqueItems, target);
|
||||||
|
} else if (isMapSchema(schema) || isObjectSchema(schema)) {
|
||||||
|
setObjectValidations(minProperties, maxProperties, target);
|
||||||
|
} else if (isStringSchema(schema)) {
|
||||||
|
setStringValidations(minLength, maxLength, pattern, target);
|
||||||
|
if (isDecimalSchema(schema)) {
|
||||||
|
setNumericValidations(schema, multipleOf, minimum, maximum, exclusiveMinimum, exclusiveMaximum, target);
|
||||||
|
}
|
||||||
|
} else if (isNumberSchema(schema) || isIntegerSchema(schema)) {
|
||||||
|
setNumericValidations(schema, multipleOf, minimum, maximum, exclusiveMinimum, exclusiveMaximum, target);
|
||||||
|
} else if (isComposedSchema(schema)) {
|
||||||
|
// this could be composed out of anything so set all validations here
|
||||||
|
setArrayValidations(minItems, maxItems, uniqueItems, target);
|
||||||
|
setObjectValidations(minProperties, maxProperties, target);
|
||||||
|
setStringValidations(minLength, maxLength, pattern, target);
|
||||||
|
setNumericValidations(schema, multipleOf, minimum, maximum, exclusiveMinimum, exclusiveMaximum, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxItems != null || minItems != null || minProperties != null || maxProperties != null || minLength != null || maxLength != null || multipleOf != null || pattern != null || minimum != null || maximum != null || exclusiveMinimum != null || exclusiveMaximum != null || uniqueItems != null) {
|
||||||
|
target.setHasValidation(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setArrayValidations(Integer minItems, Integer maxItems, Boolean uniqueItems, IJsonSchemaValidationProperties target) {
|
||||||
|
if (minItems != null) target.setMinItems(minItems);
|
||||||
|
if (maxItems != null) target.setMaxItems(maxItems);
|
||||||
|
if (uniqueItems != null) target.setUniqueItems(uniqueItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setObjectValidations(Integer minProperties, Integer maxProperties, IJsonSchemaValidationProperties target) {
|
||||||
|
if (minProperties != null) target.setMinProperties(minProperties);
|
||||||
|
if (maxProperties != null) target.setMaxProperties(maxProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setStringValidations(Integer minLength, Integer maxLength, String pattern, IJsonSchemaValidationProperties target) {
|
||||||
|
if (minLength != null) target.setMinLength(minLength);
|
||||||
|
if (maxLength != null) target.setMaxLength(maxLength);
|
||||||
|
if (pattern != null) target.setPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setNumericValidations(Schema schema, BigDecimal multipleOf, BigDecimal minimum, BigDecimal maximum, Boolean exclusiveMinimum, Boolean exclusiveMaximum, IJsonSchemaValidationProperties target) {
|
||||||
|
if (multipleOf != null) target.setMultipleOf(multipleOf);
|
||||||
|
if (minimum != null) {
|
||||||
|
if (isIntegerSchema(schema)) {
|
||||||
|
target.setMinimum(String.valueOf(minimum.longValue()));
|
||||||
|
} else {
|
||||||
|
target.setMinimum(String.valueOf(minimum));
|
||||||
|
}
|
||||||
if (exclusiveMinimum != null) target.setExclusiveMinimum(exclusiveMinimum);
|
if (exclusiveMinimum != null) target.setExclusiveMinimum(exclusiveMinimum);
|
||||||
|
}
|
||||||
|
if (maximum != null) {
|
||||||
|
if (isIntegerSchema(schema)) {
|
||||||
|
target.setMaximum(String.valueOf(maximum.longValue()));
|
||||||
|
} else {
|
||||||
|
target.setMaximum(String.valueOf(maximum));
|
||||||
|
}
|
||||||
if (exclusiveMaximum != null) target.setExclusiveMaximum(exclusiveMaximum);
|
if (exclusiveMaximum != null) target.setExclusiveMaximum(exclusiveMaximum);
|
||||||
if (minLength != null) target.setMinLength(minLength);
|
|
||||||
if (maxLength != null) target.setMaxLength(maxLength);
|
|
||||||
if (minItems != null) target.setMinItems(minItems);
|
|
||||||
if (maxItems != null) target.setMaxItems(maxItems);
|
|
||||||
if (uniqueItems != null) target.setUniqueItems(uniqueItems);
|
|
||||||
if (minProperties != null) target.setMinProperties(minProperties);
|
|
||||||
if (maxProperties != null) target.setMaxProperties(maxProperties);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2651,6 +2651,227 @@ public class DefaultCodegenTest {
|
|||||||
assertEquals(co.responses.get(0).isNull, true);
|
assertEquals(co.responses.get(0).isNull, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModelGetHasValidation() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7651.yaml");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
|
Schema sc;
|
||||||
|
CodegenModel cm;
|
||||||
|
|
||||||
|
List<String> modelNames = Arrays.asList(
|
||||||
|
"ArrayWithMaxItems",
|
||||||
|
"ArrayWithMinItems",
|
||||||
|
"ArrayWithUniqueItems",
|
||||||
|
"ObjectWithMinProperties",
|
||||||
|
"ObjectWithMaxProperties",
|
||||||
|
"StringWithMinLength",
|
||||||
|
"DateWithMinLength",
|
||||||
|
"DateTimeWithMinLength",
|
||||||
|
"ByteWithMinLength",
|
||||||
|
"BinaryWithMinLength",
|
||||||
|
"StringWithMaxLength",
|
||||||
|
"DateWithMaxLength",
|
||||||
|
"DateTimeWithMaxLength",
|
||||||
|
"ByteWithMaxLength",
|
||||||
|
"BinaryWithMaxLength",
|
||||||
|
"IntegerWithMultipleOf",
|
||||||
|
"Integer32WithMultipleOf",
|
||||||
|
"Integer64WithMultipleOf",
|
||||||
|
"NumberWithMultipleOf",
|
||||||
|
"NumberFloatWithMultipleOf",
|
||||||
|
"NumberDoubleWithMultipleOf",
|
||||||
|
"StringWithPattern",
|
||||||
|
"DateWithPattern",
|
||||||
|
"DateTimeWithPattern",
|
||||||
|
"ByteWithPattern",
|
||||||
|
"BinaryWithPattern",
|
||||||
|
"IntegerWithMinimum",
|
||||||
|
"Integer32WithMinimum",
|
||||||
|
"Integer64WithMinimum",
|
||||||
|
"NumberWithMinimum",
|
||||||
|
"NumberFloatWithMinimum",
|
||||||
|
"NumberDoubleWithMinimum",
|
||||||
|
"IntegerWithMaximum",
|
||||||
|
"Integer32WithMaximum",
|
||||||
|
"Integer64WithMaximum",
|
||||||
|
"NumberWithMaximum",
|
||||||
|
"NumberFloatWithMaximum",
|
||||||
|
"NumberDoubleWithMaximum",
|
||||||
|
"IntegerWithExclusiveMaximum",
|
||||||
|
"Integer32WithExclusiveMaximum",
|
||||||
|
"Integer64WithExclusiveMaximum",
|
||||||
|
"NumberWithExclusiveMaximum",
|
||||||
|
"NumberFloatWithExclusiveMaximum",
|
||||||
|
"NumberDoubleWithExclusiveMaximum",
|
||||||
|
"IntegerWithExclusiveMinimum",
|
||||||
|
"Integer32WithExclusiveMinimum",
|
||||||
|
"Integer64WithExclusiveMinimum",
|
||||||
|
"NumberWithExclusiveMinimum",
|
||||||
|
"NumberFloatWithExclusiveMinimum",
|
||||||
|
"NumberDoubleWithExclusiveMinimum"
|
||||||
|
);
|
||||||
|
for (String modelName : modelNames) {
|
||||||
|
sc = openAPI.getComponents().getSchemas().get(modelName);
|
||||||
|
cm = codegen.fromModel(modelName, sc);
|
||||||
|
assertEquals(cm.getHasValidation(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPropertyGetHasValidation() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7651.yaml");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
|
String modelName = "ObjectWithPropertiesThatHaveValidations";
|
||||||
|
Schema sc = openAPI.getComponents().getSchemas().get(modelName);;
|
||||||
|
CodegenModel cm = codegen.fromModel(modelName, sc);
|
||||||
|
|
||||||
|
List<CodegenProperty> props = cm.getVars();
|
||||||
|
assertEquals(props.size(), 50);
|
||||||
|
for (CodegenProperty prop : props) {
|
||||||
|
assertEquals(prop.getHasValidation(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQueryParametersGetHasValidation() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7651.yaml");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
|
String path = "/queryParametersWithValidation";
|
||||||
|
Operation operation = openAPI.getPaths().get(path).getPost();
|
||||||
|
CodegenOperation co = codegen.fromOperation(path, "POST", operation, null);
|
||||||
|
List<CodegenParameter> params = co.queryParams;
|
||||||
|
assertEquals(params.size(), 50);
|
||||||
|
for (CodegenParameter param : params) {
|
||||||
|
assertEquals(param.getHasValidation(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHeaderParametersGetHasValidation() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7651.yaml");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
|
String path = "/headerParametersWithValidation";
|
||||||
|
Operation operation = openAPI.getPaths().get(path).getPost();
|
||||||
|
CodegenOperation co = codegen.fromOperation(path, "POST", operation, null);
|
||||||
|
List<CodegenParameter> params = co.headerParams;
|
||||||
|
assertEquals(params.size(), 50);
|
||||||
|
for (CodegenParameter param : params) {
|
||||||
|
assertEquals(param.getHasValidation(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCookieParametersGetHasValidation() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7651.yaml");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
|
String path = "/cookieParametersWithValidation";
|
||||||
|
Operation operation = openAPI.getPaths().get(path).getPost();
|
||||||
|
CodegenOperation co = codegen.fromOperation(path, "POST", operation, null);
|
||||||
|
List<CodegenParameter> params = co.cookieParams;
|
||||||
|
assertEquals(params.size(), 50);
|
||||||
|
for (CodegenParameter param : params) {
|
||||||
|
assertEquals(param.getHasValidation(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPathParametersGetHasValidation() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7651.yaml");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
|
String path = "/pathParametersWithValidation";
|
||||||
|
Operation operation = openAPI.getPaths().get(path).getPost();
|
||||||
|
CodegenOperation co = codegen.fromOperation(path, "POST", operation, null);
|
||||||
|
List<CodegenParameter> params = co.pathParams;
|
||||||
|
assertEquals(params.size(), 50);
|
||||||
|
for (CodegenParameter param : params) {
|
||||||
|
assertEquals(param.getHasValidation(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBodyAndResponseGetHasValidation() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7651.yaml");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
codegen.setOpenAPI(openAPI);
|
||||||
|
|
||||||
|
List<String> modelNames = Arrays.asList(
|
||||||
|
"ArrayWithMaxItems",
|
||||||
|
"ArrayWithMinItems",
|
||||||
|
"ArrayWithUniqueItems",
|
||||||
|
"ObjectWithMinProperties",
|
||||||
|
"ObjectWithMaxProperties",
|
||||||
|
"StringWithMinLength",
|
||||||
|
"DateWithMinLength",
|
||||||
|
"DateTimeWithMinLength",
|
||||||
|
"ByteWithMinLength",
|
||||||
|
"BinaryWithMinLength",
|
||||||
|
"StringWithMaxLength",
|
||||||
|
"DateWithMaxLength",
|
||||||
|
"DateTimeWithMaxLength",
|
||||||
|
"ByteWithMaxLength",
|
||||||
|
"BinaryWithMaxLength",
|
||||||
|
"StringWithPattern",
|
||||||
|
"DateWithPattern",
|
||||||
|
"DateTimeWithPattern",
|
||||||
|
"ByteWithPattern",
|
||||||
|
"BinaryWithPattern",
|
||||||
|
"IntegerWithMultipleOf",
|
||||||
|
"Integer32WithMultipleOf",
|
||||||
|
"Integer64WithMultipleOf",
|
||||||
|
"NumberWithMultipleOf",
|
||||||
|
"NumberFloatWithMultipleOf",
|
||||||
|
"NumberDoubleWithMultipleOf",
|
||||||
|
"IntegerWithMinimum",
|
||||||
|
"Integer32WithMinimum",
|
||||||
|
"Integer64WithMinimum",
|
||||||
|
"NumberWithMinimum",
|
||||||
|
"NumberFloatWithMinimum",
|
||||||
|
"NumberDoubleWithMinimum",
|
||||||
|
"IntegerWithMaximum",
|
||||||
|
"Integer32WithMaximum",
|
||||||
|
"Integer64WithMaximum",
|
||||||
|
"NumberWithMaximum",
|
||||||
|
"NumberFloatWithMaximum",
|
||||||
|
"NumberDoubleWithMaximum",
|
||||||
|
"IntegerWithExclusiveMaximum",
|
||||||
|
"Integer32WithExclusiveMaximum",
|
||||||
|
"Integer64WithExclusiveMaximum",
|
||||||
|
"NumberWithExclusiveMaximum",
|
||||||
|
"NumberFloatWithExclusiveMaximum",
|
||||||
|
"NumberDoubleWithExclusiveMaximum",
|
||||||
|
"IntegerWithExclusiveMinimum",
|
||||||
|
"Integer32WithExclusiveMinimum",
|
||||||
|
"Integer64WithExclusiveMinimum",
|
||||||
|
"NumberWithExclusiveMinimum",
|
||||||
|
"NumberFloatWithExclusiveMinimum",
|
||||||
|
"NumberDoubleWithExclusiveMinimum"
|
||||||
|
);
|
||||||
|
|
||||||
|
String path;
|
||||||
|
Operation operation;
|
||||||
|
CodegenOperation co;
|
||||||
|
|
||||||
|
for (String modelName : modelNames) {
|
||||||
|
path = "/"+modelName;
|
||||||
|
operation = openAPI.getPaths().get(path).getPost();
|
||||||
|
co = codegen.fromOperation(path, "POST", operation, null);
|
||||||
|
assertEquals(co.bodyParam.getHasValidation(), true);
|
||||||
|
assertEquals(co.responses.get(0).getHasValidation(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVarsAndRequiredVarsPresent() {
|
public void testVarsAndRequiredVarsPresent() {
|
||||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7613.yaml");
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7613.yaml");
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user