{"record":{"id":"809825cae52e4e49","repo":"OpenAPITools/openapi-generator","slug":"pattern-must-follow-the-perl-pattern-modifiers-co-809825","errorCode":null,"errorMessage":"Pattern must follow the Perl /pattern/modifiers convention. %s is not valid.","messagePattern":"Pattern must follow the Perl /pattern/modifiers convention\\. (.+?) is not valid\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonConnexionServerCodegen.java","lineNumber":740,"sourceCode":"                }\n            }\n        }\n        return objs;\n    }\n\n    /*\n     * 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    @Override\n    public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {\n        if (pattern != null) {\n            int i = pattern.lastIndexOf('/');\n\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);\n            vendorExtensions.put(X_MODIFIERS, modifiers);\n        }\n    }\n}","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonConnexionServerCodegen.java#L722-L758","documentation":"AbstractPythonConnexionServerCodegen.postProcessPattern is the connexion-server copy of the Python pattern converter, called unconditionally for property.pattern and parameter.pattern (lines 627 and 657). It demands Perl /pattern/modifiers form: the first char must be '/' and the last '/' must sit at index >= 2, otherwise IllegalArgumentException. Because DefaultCodegen's addRegularExpressionDelimiter pass-through already leaves '/'-prefixed patterns untouched, the throw means a spec pattern started with '/' but has no non-empty delimited body.","triggerScenarios":"Generating -g python-connexion (or python-flask connexion line) when a schema pattern starts with '/' without a closing delimiter: \"/\", \"//\", or \"/api/v[0-9]+\". Bare ECMAScript patterns are auto-wrapped and do not hit this.","commonSituations":"URL-validating regexes beginning with a literal slash; half-converted Perl-style patterns from other toolchains; specs shared between generators where one expected delimiters.","solutions":["Rewrite the pattern as a plain ECMAScript regex without delimiters, e.g. \"^/api/v[0-9]+$\"","Or supply a complete Perl form with body and flags, e.g. \"/^\\d{4}$/i\"","Remove slash-only placeholder patterns"],"exampleFix":"# before\npattern: /api/v[0-9]+\n\n# after\npattern: ^/api/v[0-9]+","handlingStrategy":"validation","validationCode":"// JS: reject patterns starting with '/' that have no closing delimiter\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\")) { /* fix the embedded offending pattern in the spec */ } throw e; }","preventionTips":["Write OpenAPI patterns as bare ECMAScript regex without '/' delimiters","Pay special attention to regexes meant to match URL paths","Add a spec-lint step before python-connexion generation in CI"],"tags":["regex","connexion","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"}