forked from loafle/openapi-generator-original
Adds codegenParameter.schema to allow referenced schemas in parameters (#10934)
* Removes python-experimental folder * Sets schema in fromParameter * Sets schema in codegenParameter * Adds tests of schema
This commit is contained in:
parent
a620853216
commit
06faa289bd
@ -52,6 +52,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
public boolean hasValidation;
|
public boolean hasValidation;
|
||||||
public boolean isNullable;
|
public boolean isNullable;
|
||||||
public boolean isDeprecated;
|
public boolean isDeprecated;
|
||||||
|
private CodegenProperty schema;
|
||||||
/**
|
/**
|
||||||
* Determines whether this parameter is mandatory. If the parameter is in "path",
|
* Determines whether this parameter is mandatory. If the parameter is in "path",
|
||||||
* this property is required and its value MUST be true. Otherwise, the property
|
* this property is required and its value MUST be true. Otherwise, the property
|
||||||
@ -162,6 +163,9 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
output.setHasDiscriminatorWithNonEmptyMapping(this.hasDiscriminatorWithNonEmptyMapping);
|
output.setHasDiscriminatorWithNonEmptyMapping(this.hasDiscriminatorWithNonEmptyMapping);
|
||||||
output.setHasMultipleTypes(this.hasMultipleTypes);
|
output.setHasMultipleTypes(this.hasMultipleTypes);
|
||||||
|
|
||||||
|
if (this.schema != null) {
|
||||||
|
output.setSchema(this.schema);
|
||||||
|
}
|
||||||
if (this.composedSchemas != null) {
|
if (this.composedSchemas != null) {
|
||||||
output.setComposedSchemas(this.getComposedSchemas());
|
output.setComposedSchemas(this.getComposedSchemas());
|
||||||
}
|
}
|
||||||
@ -222,7 +226,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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, composedSchemas, hasMultipleTypes);
|
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, hasMultipleTypes, schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -278,6 +282,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
getExclusiveMaximum() == that.getExclusiveMaximum() &&
|
getExclusiveMaximum() == that.getExclusiveMaximum() &&
|
||||||
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
||||||
getUniqueItems() == that.getUniqueItems() &&
|
getUniqueItems() == that.getUniqueItems() &&
|
||||||
|
Objects.equals(schema, that.getSchema()) &&
|
||||||
Objects.equals(composedSchemas, that.getComposedSchemas()) &&
|
Objects.equals(composedSchemas, that.getComposedSchemas()) &&
|
||||||
Objects.equals(baseName, that.baseName) &&
|
Objects.equals(baseName, that.baseName) &&
|
||||||
Objects.equals(paramName, that.paramName) &&
|
Objects.equals(paramName, that.paramName) &&
|
||||||
@ -403,6 +408,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
sb.append(", getHasDiscriminatorWithNonEmptyMapping=").append(hasDiscriminatorWithNonEmptyMapping);
|
sb.append(", getHasDiscriminatorWithNonEmptyMapping=").append(hasDiscriminatorWithNonEmptyMapping);
|
||||||
sb.append(", composedSchemas=").append(composedSchemas);
|
sb.append(", composedSchemas=").append(composedSchemas);
|
||||||
sb.append(", hasMultipleTypes=").append(hasMultipleTypes);
|
sb.append(", hasMultipleTypes=").append(hasMultipleTypes);
|
||||||
|
sb.append(", schema=").append(schema);
|
||||||
sb.append('}');
|
sb.append('}');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
@ -732,5 +738,10 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHasMultipleTypes(boolean hasMultipleTypes) { this.hasMultipleTypes = hasMultipleTypes; }
|
public void setHasMultipleTypes(boolean hasMultipleTypes) { this.hasMultipleTypes = hasMultipleTypes; }
|
||||||
|
|
||||||
|
public CodegenProperty getSchema() {return schema; }
|
||||||
|
|
||||||
|
public void setSchema(CodegenProperty schema) { this.schema = schema; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4499,6 +4499,8 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
Schema parameterSchema;
|
Schema parameterSchema;
|
||||||
if (parameter.getSchema() != null) {
|
if (parameter.getSchema() != null) {
|
||||||
parameterSchema = parameter.getSchema();
|
parameterSchema = parameter.getSchema();
|
||||||
|
CodegenProperty prop = fromProperty(parameter.getName(), parameterSchema);
|
||||||
|
codegenParameter.setSchema(prop);
|
||||||
} else if (parameter.getContent() != null) {
|
} else if (parameter.getContent() != null) {
|
||||||
Content content = parameter.getContent();
|
Content content = parameter.getContent();
|
||||||
if (content.size() > 1) {
|
if (content.size() > 1) {
|
||||||
|
@ -222,6 +222,7 @@ public class DefaultCodegenTest {
|
|||||||
CodegenParameter codegenParameter = codegen.fromFormProperty("enum_form_string", (Schema) requestBodySchema.getProperties().get("enum_form_string"), new HashSet<String>());
|
CodegenParameter codegenParameter = codegen.fromFormProperty("enum_form_string", (Schema) requestBodySchema.getProperties().get("enum_form_string"), new HashSet<String>());
|
||||||
|
|
||||||
Assert.assertEquals(codegenParameter.defaultValue, "-efg");
|
Assert.assertEquals(codegenParameter.defaultValue, "-efg");
|
||||||
|
Assert.assertEquals(codegenParameter.getSchema(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -2035,6 +2036,9 @@ public class DefaultCodegenTest {
|
|||||||
Assert.assertEquals(parameter.dataType, "PageQuery1");
|
Assert.assertEquals(parameter.dataType, "PageQuery1");
|
||||||
Assert.assertEquals(imports.size(), 1);
|
Assert.assertEquals(imports.size(), 1);
|
||||||
Assert.assertEquals(imports.iterator().next(), "PageQuery1");
|
Assert.assertEquals(imports.iterator().next(), "PageQuery1");
|
||||||
|
|
||||||
|
Assert.assertNotNull(parameter.getSchema());
|
||||||
|
Assert.assertEquals(parameter.getSchema().baseType, "object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user