forked from loafle/openapi-generator-original
* fix issue 6675 & add javadoc * fix formatting issue * update JUnit test for 6675 * build & update samples for PR * clean package and regenerating samples * add progress for fix to issue 10957 * Revert "add progress for fix to issue 10957" This reverts commit 8240c7ccb17141f7551ab34eda864ab4e068ebd8. * fix version issues * fix more versioning issues * fix discrepancies with backslashes * update samples Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
parent
0fc3f65ce3
commit
7f07fa5ba0
@ -311,6 +311,13 @@ public class PythonLegacyClientCodegen extends AbstractPythonCodegen implements
|
|||||||
* The OpenAPI pattern spec follows the Perl convention and style of modifiers. Python
|
* The OpenAPI pattern spec follows the Perl convention and style of modifiers. Python
|
||||||
* does not support this in as natural a way so it needs to convert it. See
|
* does not support this in as natural a way so it needs to convert it. See
|
||||||
* https://docs.python.org/2/howto/regex.html#compilation-flags for details.
|
* https://docs.python.org/2/howto/regex.html#compilation-flags for details.
|
||||||
|
*
|
||||||
|
* @param pattern (the String pattern to convert from python to Perl convention)
|
||||||
|
* @param vendorExtensions (list of custom x-* properties for extra functionality-see https://swagger.io/docs/specification/openapi-extensions/)
|
||||||
|
* @return void
|
||||||
|
* @throws IllegalArgumentException if pattern does not follow the Perl /pattern/modifiers convention
|
||||||
|
*
|
||||||
|
* Includes fix for issue #6675
|
||||||
*/
|
*/
|
||||||
public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {
|
public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
@ -322,6 +329,13 @@ public class PythonLegacyClientCodegen extends AbstractPythonCodegen implements
|
|||||||
+ "/pattern/modifiers convention. " + pattern + " is not valid.");
|
+ "/pattern/modifiers convention. " + pattern + " is not valid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check for instances of extra backslash that could cause compile issues and remove
|
||||||
|
int firstBackslash = pattern.indexOf("\\");
|
||||||
|
int bracket = pattern.indexOf("[");
|
||||||
|
if (firstBackslash == 0 || firstBackslash == 1 || firstBackslash == bracket+1) {
|
||||||
|
pattern = pattern.substring(0,firstBackslash)+pattern.substring(firstBackslash+1);
|
||||||
|
}
|
||||||
|
|
||||||
String regex = pattern.substring(1, i).replace("'", "\\'");
|
String regex = pattern.substring(1, i).replace("'", "\\'");
|
||||||
List<String> modifiers = new ArrayList<String>();
|
List<String> modifiers = new ArrayList<String>();
|
||||||
|
|
||||||
|
@ -91,6 +91,9 @@ public class PythonLegacyClientCodegenTest {
|
|||||||
Assert.assertEquals(op.allParams.get(4).pattern, "/^pattern\\/\\d{3}$/");
|
Assert.assertEquals(op.allParams.get(4).pattern, "/^pattern\\/\\d{3}$/");
|
||||||
// pattern_with_modifiers '/^pattern\d{3}$/i
|
// pattern_with_modifiers '/^pattern\d{3}$/i
|
||||||
Assert.assertEquals(op.allParams.get(5).pattern, "/^pattern\\d{3}$/i");
|
Assert.assertEquals(op.allParams.get(5).pattern, "/^pattern\\d{3}$/i");
|
||||||
|
// pattern_with_backslash_after_bracket '/^[\pattern\d{3}$/i'
|
||||||
|
// added to test fix for issue #6675
|
||||||
|
Assert.assertEquals(op.allParams.get(6).pattern, "/^[\\pattern\\d{3}$/i");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +45,11 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
pattern: '/^pattern\d{3}$/i'
|
pattern: '/^pattern\d{3}$/i'
|
||||||
|
- name: pattern_with_backslash_after_bracket
|
||||||
|
in: header
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
pattern: '/^[\pattern\d{3}$/i'
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user