You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
We use regex patterns in our API specification. These include usage of character classes like \d and escaping special characters like \.. For example to create a pattern that accepts a string consisting of one or more digits we used pattern: "^\\d+$" (or pattern: '^\d+$').
The generated code would construct a regex like this regex::Regex::new(r"^\\d+$"), which would be different from our intended pattern, as it would correspond to strings starting with a \ followed by at least one d.
We expected either regex::Regex::new(r"^\d+$") or regex::Regex::new("^\\d+$").
We used: docker run --rm -v ${PWD}:/local --user $(id -u):$(id -g) openapitools/openapi-generator-cli:v7.11.0 generate -i /local/api/openapi.yaml --additional-properties=packageName=redacted,generateAliasAsModel=true,packageVersion=2.0.0 -g rust-axum -o /local/redacted
Steps to reproduce
Use the above command to generate the code from a given openapi.yaml
The file redacted/src/models.rs contains the mentioned regex patterns
Related issues/PRs
None found.
Suggest a fix
As a workaround we used a custom template to use default literals instead of raw literals to construct regex::Regex (i.e. replace all occurences of regex::Regex::new(r"{{ pattern }}") with regex::Regex::new("{{ pattern }}")). This works for us, but we do not know if this would be a general solution.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
We use regex patterns in our API specification. These include usage of character classes like
\d
and escaping special characters like\.
. For example to create a pattern that accepts a string consisting of one or more digits we usedpattern: "^\\d+$"
(orpattern: '^\d+$'
).The generated code would construct a regex like this
regex::Regex::new(r"^\\d+$")
, which would be different from our intended pattern, as it would correspond to strings starting with a\
followed by at least oned
.We expected either
regex::Regex::new(r"^\d+$")
orregex::Regex::new("^\\d+$")
.example on Rust Playground
openapi-generator version
We tried 7.8.0, 7.11 and the master as of this date. The problem is present in all of them.
OpenAPI declaration file content or url
Generation Details
We used:
docker run --rm -v ${PWD}:/local --user $(id -u):$(id -g) openapitools/openapi-generator-cli:v7.11.0 generate -i /local/api/openapi.yaml --additional-properties=packageName=redacted,generateAliasAsModel=true,packageVersion=2.0.0 -g rust-axum -o /local/redacted
Steps to reproduce
openapi.yaml
redacted/src/models.rs
contains the mentioned regex patternsRelated issues/PRs
None found.
Suggest a fix
As a workaround we used a custom template to use default literals instead of raw literals to construct
regex::Regex
(i.e. replace all occurences ofregex::Regex::new(r"{{ pattern }}")
withregex::Regex::new("{{ pattern }}")
). This works for us, but we do not know if this would be a general solution.The text was updated successfully, but these errors were encountered: