OpenAPITools/openapi-generator · error · IllegalArgumentException
Pattern must follow the Perl /pattern/modifiers convention.
Error message
Pattern must follow the Perl /pattern/modifiers convention. {pattern} is not valid. What it means
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.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java:1922
* 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.
*
* @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) {
if (pattern != null) {
int i = pattern.lastIndexOf('/');
// TODO update the check below follow python convention
//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.replace("\"", "\\\""));
vendorExtensions.put(X_PATTERN, pattern.replace("\"", "\\\""));
vendorExtensions.put(X_MODIFIERS, modifiers);
}
}View on GitHub (pinned to fcec517be3)
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
Example fix
# before pattern: /api/v[0-9]+ # after pattern: ^/api/v[0-9]+
Defensive patterns
Strategy: validation
Validate before calling
// JS: same pre-scan as other Python generators
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")) { /* rewrite the offending pattern without delimiters */ } throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Path-matching regexes starting with a literal slash; partially converted Perl-notation patterns; placeholder slash-only patterns left in specs.
Related errors
- Pattern must follow the Perl /pattern/modifiers convention.
- Pattern must follow the Perl /pattern/modifiers convention.
- Error! Codegen Property not yet supported in getPydanticType
- Error! Failed to process getPydanticType when getting the co
- Error! Codegen Parameter not yet supported in getPydanticTyp
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/49d6a80d310d1cd4.
Report an issue: GitHub.