Fix Golang pattern validation with regex fails on commas #20079#20369
Fix Golang pattern validation with regex fails on commas #20079#20369mlebihan wants to merge 3 commits into
Conversation
aa7aba8 to
2b7cc7f
Compare
|
thanks for the PR can you please rebase/merge the latest master, which should have the gradle tests fixed? |
|
It should be done, now. |
| @@ -0,0 +1,70 @@ | |||
| package openapi | |||
There was a problem hiding this comment.
thanks for the PR and adding the tests.
can you please PM me to discuss the integration tests when you've time?
Slack: https://join.slack.com/t/openapi-generator/shared_invite/zt-2wmkn4s8g-n19PJ99Y6Vei74WMUIehQA
|
Will this PR also fix #22101 ? |
|
@srgoni do you mind pulling this change locally to test with your use cases? |
1437026 to
ef56537
Compare
ef56537 to
3c1627d
Compare
3c1627d to
7e25bba
Compare
|
@wing328 I faced the same issue. |
|
@markshleifer-coralogix thanks for testing the fix. will try to get it merged in the upcoming stable release. |
|
@wing328 I've tested this PR against the tests that are here: With various matching cases: {
"code": "52,",
"creditCard": "3124 5675 4400 4567",
"date": "31/4/1999",
"windowsAbsolutePath": "\\\\directory\\\\directory2",
"email1": "abc@dummy",
"email2": "abc.123.*&ca",
"htmlHexadecimalColorCode1": "123G45",
"htmlHexadecimalColorCode2": "SS AB CD",
"ipAddress": "0.0.0",
"javaComments": "a=1",
"money": "$1",
"positiveNegativeDecimalValue": "++41",
"password1": "abc",
"password2": "*&^g",
"phoneNumber": "888 6898",
"sentence1": "i am fine",
"sentence2": "i am fine",
"socialSecurityNumber": "123 45 6789",
"url": "http://sample.com"
}and not matching ones: {
"code": "52,",
"creditCard": "4123-6453-2222-1746",
"date": "1999/04/19",
"windowsAbsolutePath": "/directory2",
"email1": "ab*cd@efg.hijkl",
"email2": "^%abcdefg123",
"htmlHexadecimalColorCode1": "12-44-CC",
"htmlHexadecimalColorCode2": "1223AB",
"ipAddress": "256.89.457.02",
"javaComments": "a=1",
"money": "$-75.17",
"positiveNegativeDecimalValue": "-+97.14",
"password1": "*abcdefghijkl",
"password2": "1bcd",
"phoneNumber": "519 883-6898",
"sentence1": "i am fine",
"sentence2": "i am fine",
"socialSecurityNumber": "1234-56-7891",
"url": "http://www.sample.comm"
}This PR improves the situation, but there's still two cases failing. I cannot succeed in correcting completely this issue, however, because there's a flaw in one of the underlying packages Go uses to validate or use regex. So, I'm happy and glad if this PR can solve many regex that causes troubles. But it won't fix them all. |
In a struct, for a
type: stringaccompanied by apattern, these generated Go directives are corrected:Test cases added
18 new regular expressions has been taken for test cases, from an SAP help page.
A go test has been run with various values, and it succeeds except for one test case:
windowsAbsolutePaththat might encounter ago validator.v2package internal trouble.Tests are in
modules/openapi-generator/src/test/resources/3_0:ls modules/openapi-generator/src/test/resources/3_0/issue_20079_*The following command should then show the success:
Remaining problem
This fix mostly fixes the handling of regular expressions with Go.
But there's still two problems remaining, that will require other issues to be handled 👍
For
javaCommentstest case, when it should use the^/\*.*\*/|//[^\\n]*$pattern, theorg.yaml.snakeyaml.scannerparser that scans the spec file, wrongly tells that\*is an invalid escape code.But attempting to enter
^/\\*.*\\*/|//[^\\n]*$keeps the\\*and generates^/\\*.*\\*/|//[^\n]*$instead of the wished^/\*.*\*/|//[^\n]*$For
windowsAbsolutePathtest case, Govalidator.package v2doesn't look handling this regexp well, and tell it having a bad parameter.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)