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 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+$").
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
openapi: 3.1.0
info:
title: Regex
description: Regex example api spec
version: 1.0.0
paths:
/apps/{id}:
get:
parameters:
- name: id
in: path
schema:
type: string
pattern: "^\\d+$"
required: true
responses:
"200":
description: Success
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
- 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.
Bug Report Checklist
Description
We use regex patterns in our API specification. These include usage of character classes like
\dand 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/redactedSteps to reproduce
openapi.yamlredacted/src/models.rscontains 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.