-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [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+$").
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: SuccessGeneration 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.rscontains 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.