Skip to content

issue-9509 adding support to v3. Escaping for ref defined patterns #1346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

evgeniimv
Copy link

@evgeniimv evgeniimv commented May 28, 2025

as was already stated in swagger-api/swagger-codegen#9509

Regex pattern like this '^\d{1,13}.\d{1,5}$' are not escape property and the generated java code does not compile.

tho, it was fixed in v2 of swagger-codegen
#1100
swagger-api/swagger-codegen#12038

it remains broken for swagger v3,

any chance to get this work resumed and merged, specially into v3? Thanks.

This change is intended to fix it in v3 as well, since v3 swagger-codegen uses DefaultCodegenConfig defined in this library

@@ -3185,7 +3185,7 @@ private void addVars(CodegenModel codegenModel, List<CodegenProperty> vars, Map<
if (this.openAPI == null) {
LOGGER.warn("open api utility object was not properly set.");
} else {
OpenAPIUtil.addPropertiesFromRef(this.openAPI, propertySchema, codegenProperty);
OpenAPIUtil.addPropertiesFromRef(this.openAPI, propertySchema, codegenProperty, this::toRegularExpression);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want to use toRegularExpression defined in child classes like AbstractJavaCodegen or TypeScriptAxiosClientCodegen.
Thus, we pass it as a Function<T,T>(UnaryOperator<String>) instead of implementing it in OpenAPIUtil

CodegenProperty urlProperty = codegenModel.vars.get(0);
Assert.assertEquals(urlProperty.getName(), "url");
//verifying java pattern is properly escaped
Assert.assertEquals(urlProperty.getPattern(), SSN_ESCAPED_PATTERN);
Copy link
Author

@evgeniimv evgeniimv May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so basically we verify that ^\d{3}-\d{2}-\d{4}$ pattern is transformed to ^\\d{3}-\\d{2}-\\d{4}$ when AbstractJavaCodegen is used

@evgeniimv evgeniimv changed the title issue-9509 adding escaping support to patterns added with ref properties issue-9509 adding support for v3 May 28, 2025
@evgeniimv evgeniimv changed the title issue-9509 adding support for v3 issue-9509 adding support to v3. Escaping for ref defined patterns May 28, 2025
@evgeniimv
Copy link
Author

 @frantuma Hey Francesco, may I ask you to check this one, once you have time.
 Much appreciate it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants