swagger-api / swagger-api/swagger-codegen
python client produces invalid pattern regex with metacharacters - eg \d
Open
@HugoMario is already working on this.
Since May 8, 2020.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Building a swagger python client with a pattern, in this case P\d+' results in a raw string that's escaped: r'P\\d+' which matches something like P\3 but not valid input like P3.
Swagger-codegen version
2.4.6
This used to produce valid regex's.
Swagger declaration file content or url
Command line used for generation
docker run --rm \
-v $PWD/generated_$1:/swagger-api/out \
-v $PWD:/swagger-api/yamls \
-it swaggerapi/swagger-codegen-cli:2.4.6 generate \
-i /swagger-api/yamls/swagger.yaml \
-l python \
-o /swagger-api/out \
--config /swagger-api/yamls/config.json
Steps to reproduce
generate python client.
Then try to use the client the resulting regex will always fail with valid content
if 'fooid' in params and not re.search(r'FOO\\d+', params['fooid']): # noqa: E501
Related issues/PRs
Suggest a fix/enhancement
removing the r in the template fixes this issue which was the behavior of some earlier versions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.