-
Notifications
You must be signed in to change notification settings - Fork 436
Open
Description
Regex string is not escaped when a property refers to a schema
https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/util/OpenAPIUtil.java#L25-L27
public static void addPropertiesFromRef(OpenAPI openAPI, Schema refSchema, CodegenProperty codegenProperty) {
final Map<String, Schema> allSchemas = openAPI.getComponents().getSchemas();
if (allSchemas == null || allSchemas.isEmpty()) {
return;
}
final Schema schema = allSchemas.get(getSimpleRef(refSchema.get$ref()));
if (schema == null) {
return;
}
if (StringUtils.isBlank(codegenProperty.pattern)) {
// pattern here is not escaped
codegenProperty.pattern = schema.getPattern();
}
codegenProperty.minLength = schema.getMinLength();
codegenProperty.maxLength = schema.getMaxLength();
if (codegenProperty.pattern != null || codegenProperty.minLength != null || codegenProperty.maxLength != null) {
codegenProperty.getVendorExtensions().put(HAS_VALIDATION_EXT_NAME, Boolean.TRUE);
}
}
Potential fix
public static void addPropertiesFromRef(CodegenConfig codegenConfig, OpenAPI openAPI, Schema refSchema, CodegenProperty codegenProperty) {
final Map<String, Schema> allSchemas = openAPI.getComponents().getSchemas();
if (allSchemas == null || allSchemas.isEmpty()) {
return;
}
final Schema schema = allSchemas.get(getSimpleRef(refSchema.get$ref()));
if (schema == null) {
return;
}
if (StringUtils.isBlank(codegenProperty.pattern)) {
// use toRegularExpression method in CodegenConfig to escape
codegenProperty.pattern = codegenConfig.toRegularExpression(schema.getPattern());
}
codegenProperty.minLength = schema.getMinLength();
codegenProperty.maxLength = schema.getMaxLength();
if (codegenProperty.pattern != null || codegenProperty.minLength != null || codegenProperty.maxLength != null) {
codegenProperty.getVendorExtensions().put(HAS_VALIDATION_EXT_NAME, Boolean.TRUE);
}
}
Metadata
Metadata
Assignees
Labels
No labels