OpenAPITools/openapi-generator · error · IllegalArgumentException

Pattern must follow the Perl /pattern/modifiers convention.

Error message

Pattern must follow the Perl /pattern/modifiers convention. %s is not valid.

What it means

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.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonConnexionServerCodegen.java:740

                }
            }
        }
        return objs;
    }

    /*
     * 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
     * https://docs.python.org/2/howto/regex.html#compilation-flags for details.
     */
    @Override
    public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {
        if (pattern != null) {
            int i = pattern.lastIndexOf('/');

            //Must follow Perl /pattern/modifiers convention
            if (pattern.charAt(0) != '/' || i < 2) {
                throw new IllegalArgumentException("Pattern must follow the Perl "
                        + "/pattern/modifiers convention. " + pattern + " is not valid.");
            }

            String regex = pattern.substring(1, i).replace("'", "\\'");
            List<String> modifiers = new ArrayList<String>();

            for (char c : pattern.substring(i).toCharArray()) {
                if (regexModifiers.containsKey(c)) {
                    String modifier = regexModifiers.get(c);
                    modifiers.add(modifier);
                }
            }

            vendorExtensions.put(X_REGEX, regex);
            vendorExtensions.put(X_MODIFIERS, modifiers);
        }
    }
}

View on GitHub (pinned to fcec517be3)

Solutions

  1. Rewrite the pattern as a plain ECMAScript regex without delimiters, e.g. "^/api/v[0-9]+$"
  2. Or supply a complete Perl form with body and flags, e.g. "/^\d{4}$/i"
  3. Remove slash-only placeholder patterns

Example fix

# before
pattern: /api/v[0-9]+

# after
pattern: ^/api/v[0-9]+
Defensive patterns

Strategy: validation

Validate before calling

// JS: reject patterns starting with '/' that have no closing delimiter
function badPattern(p) {
  if (!p || !p.startsWith('/')) return false;
  return p.lastIndexOf('/') < 2;
}

Try / catch

try { generator.generate(); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Perl")) { /* fix the embedded offending pattern in the spec */ } throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: URL-validating regexes beginning with a literal slash; half-converted Perl-style patterns from other toolchains; specs shared between generators where one expected delimiters.

Related errors


AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22). Data as JSON: /api/errors/809825cae52e4e49. Report an issue: GitHub.