If a pattern such as ^['"\-\w\s]+$ is specified, the generated python code for validation produces a syntax error:
ifself.api_client.client_side_validationand'search_string'inlocal_var_paramsandnotre.search(r'^[\'"\-\w\s]+$', local_var_params['search_string']): # noqa: E501raiseApiValueError("Invalid value for parameter `search_string` when calling `example`, must conform to the pattern `/^['"\-\w\s]+$/`") # noqa: E501# --^
However, if it is changed to ^[\'\"\-\w\s]+$, the error then becomes:
ifself.api_client.client_side_validationand'search_string'inlocal_var_paramsandnotre.search(r'^[\\'\"\-\w\s]+$', local_var_params['search_string']): # noqa: E501# ---^raiseApiValueError("Invalid value for parameter `search_string` when calling `example`, must conform to the pattern `/^[\'\"\-\w\s]+$/`") # noqa: E501
The pattern ^['\"\-\w\s]+$ works, since the generated code has the correct escape sequences, but as far as I can tell, it is equivalent to the others (despite the redundant escapes).
openapi-generator version
I'm using version v4.3.1.
OpenAPI declaration file content or url
swagger: '2.0'info:
version: 1.0.0title: Exampleconsumes:
- application/jsonproduces:
- application/jsonpaths:
/example:
get:
operationId: exampleparameters:
- name: search_stringin: queryrequired: truetype: stringminLength: 1maxLength: 256pattern: ^['"\-\w\s]+$responses:
'200':
description: OK##### Command line used for generation
@hbusul and @RedRoserade do either of you or does anyone else want to fix this?
One would probably need to edit the existing postProcessPattern method here
To build in the proper escaping when going from openapi regex to a python regex string with escaping.
And here is where our regex patterns are placed in the generated python code.
Bug Report Checklist
Description
If a pattern such as
^['"\-\w\s]+$is specified, the generated python code for validation produces a syntax error:However, if it is changed to
^[\'\"\-\w\s]+$, the error then becomes:The pattern
^['\"\-\w\s]+$works, since the generated code has the correct escape sequences, but as far as I can tell, it is equivalent to the others (despite the redundant escapes).openapi-generator version
I'm using version
v4.3.1.OpenAPI declaration file content or url
docker run --rm
-v "$(pwd):/local"
--user="$(id -u):$(id -g)"
-w /local
openapitools/openapi-generator-cli:v4.3.1 generate
-i "swagger.yaml"
-g python
-o .
-c example.json
Related issues/PRs
Suggest a fix
I would like to fix this, if possible.
The text was updated successfully, but these errors were encountered: