{"record":{"id":"49d6a80d310d1cd4","repo":"OpenAPITools/openapi-generator","slug":"pattern-must-follow-the-perl-pattern-modifiers-co-49d6a8","errorCode":null,"errorMessage":"Pattern must follow the Perl /pattern/modifiers convention. {pattern} is not valid.","messagePattern":"Pattern must follow the Perl /pattern/modifiers convention\\. (.+?) is not valid\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java","lineNumber":1922,"sourceCode":"     * The OpenAPI pattern spec follows the Perl convention and style of modifiers. Python\n     * does not support this in as natural a way so it needs to convert it. See\n     * https://docs.python.org/2/howto/regex.html#compilation-flags for details.\n     *\n     * @param pattern (the String pattern to convert from python to Perl convention)\n     * @param vendorExtensions (list of custom x-* properties for extra functionality-see https://swagger.io/docs/specification/openapi-extensions/)\n     * @return void\n     * @throws IllegalArgumentException if pattern does not follow the Perl /pattern/modifiers convention\n     *\n     * Includes fix for issue #6675\n     */\n    public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {\n        if (pattern != null) {\n            int i = pattern.lastIndexOf('/');\n\n            // TODO update the check below follow python convention\n            //Must follow Perl /pattern/modifiers convention\n            if (pattern.charAt(0) != '/' || i < 2) {\n                throw new IllegalArgumentException(\"Pattern must follow the Perl \"\n                        + \"/pattern/modifiers convention. \" + pattern + \" is not valid.\");\n            }\n\n            String regex = pattern.substring(1, i).replace(\"'\", \"\\\\'\");\n            List<String> modifiers = new ArrayList<String>();\n\n            for (char c : pattern.substring(i).toCharArray()) {\n                if (regexModifiers.containsKey(c)) {\n                    String modifier = regexModifiers.get(c);\n                    modifiers.add(modifier);\n                }\n            }\n\n            vendorExtensions.put(X_REGEX, regex.replace(\"\\\"\", \"\\\\\\\"\"));\n            vendorExtensions.put(X_PATTERN, pattern.replace(\"\\\"\", \"\\\\\\\"\"));\n            vendorExtensions.put(X_MODIFIERS, modifiers);\n        }\n    }","sourceCodeStart":1904,"sourceCodeEnd":1940,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java#L1904-L1940","documentation":"AbstractPythonPydanticV1Codegen.postProcessPattern converts each schema pattern into Python regex pieces and enforces Perl /pattern/modifiers form: first character '/' and last '/' at index >= 2, else IllegalArgumentException. Since the pipeline's addRegularExpressionDelimiter only auto-wraps patterns that do NOT already start with '/', the throw fires when a spec pattern begins with '/' but carries no non-empty delimited body.","triggerScenarios":"Generating -g python-pydantic-v1 with a schema pattern like \"/\", \"//\", or \"/api/v[0-9]+\" — a leading slash with no closing delimiter. Plain \"^\\d+$\" style patterns are wrapped automatically and pass.","commonSituations":"Path-matching regexes starting with a literal slash; partially converted Perl-notation patterns; placeholder slash-only patterns left in specs.","solutions":["Rewrite as a bare ECMAScript regex without delimiters, e.g. \"^/api/v[0-9]+$\"","Or use a complete Perl form with body and flags, e.g. \"/^\\d{4}$/i\"","Strip slash-only placeholder patterns from the spec"],"exampleFix":"# before\npattern: /api/v[0-9]+\n\n# after\npattern: ^/api/v[0-9]+","handlingStrategy":"validation","validationCode":"// JS: same pre-scan as other Python generators\nfunction badPattern(p) {\n  if (!p || !p.startsWith('/')) return false;\n  return p.lastIndexOf('/') < 2;\n}","typeGuard":null,"tryCatchPattern":"try { generator.generate(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Perl\")) { /* rewrite the offending pattern without delimiters */ } throw e; }","preventionTips":["Author patterns as bare ECMAScript regex","Lint for leading-slash patterns before python-pydantic-v1 runs","Keep one canonical spec linting step shared by all Python generators"],"tags":["regex","pydantic","python","pattern-validation"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}