Bug Report Checklist
Description
When an OpenAPI spec contains models with pattern validation (regex constraints on string properties), the generated models.rs emits lazy_static::lazy_static! blocks and regex::Regex usages unconditionally — they are not gated behind any feature flag.
However, in the generated Cargo.toml, the client feature does not include "lazy_static" or "regex" in its dependency list (unless hasCallbacks is true). The server feature correctly includes them.
This means a consumer that enables only features = ["client"] (without "server") gets compile errors when any model in the spec uses pattern:
error[E0433]: failed to resolve: use of undeclared crate or module lazy_static
error[E0433]: failed to resolve: use of undeclared crate or module regex
Root Cause
In Cargo.mustache (line ~47):
client = [
...
{{#hasCallbacks}}
"serde_ignored", "percent-encoding", {{^apiUsesByteArray}}"lazy_static", "regex",{{/apiUsesByteArray}}
{{/hasCallbacks}}
"hyper", "percent-encoding", "hyper-util/http1", "hyper-util/http2", "url"
]
The lazy_static and regex features are only added to client when hasCallbacks is true (for server-path routing in callback handling).
But in models.mustache (line ~471):
{{#vars}}
{{#hasValidation}}
{{#pattern}}
{{^isByteArray}}
lazy_static::lazy_static! {
static ref RE_...: regex::Regex = regex::Regex::new(r"{{ pattern }}").unwrap();
}
{{/isByteArray}}
{{/pattern}}
{{/hasValidation}}
{{/vars}}
These model-level regex statics are emitted for any feature combination — they're part of the shared models.rs that both client and server use
openapi-generator version
Present across all 7.x releases
OpenAPI declaration file content or url
openapi: "3.0.3"
info:
title: Test API
version: "1.0.0"
paths:
/phone:
get:
summary: Get phone
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/PhoneNumber"
components:
schemas:
PhoneNumber:
type: string
pattern: '^+[1-9]\d{1,14}$'
Generation Details
Generate with rust-server:
java -jar openapi-generator-cli.jar generate
-i test-spec.yaml
-g rust-server
-o output/
Then in the consuming crate, depend on the generated crate with client-only:
my-api = { path = "../output", default-features = false, features = ["client"] }
Build fails:
- run: cargo build
- output: error[E0433]: failed to resolve: use of undeclared crate or module
lazy_static
- output: error[E0433]: failed to resolve: use of undeclared crate or module
regex
No special additional properties or config needed — any spec with a pattern constraint on a model triggers it when using only the client feature (without server).
Steps to reproduce
- Create an OpenAPI spec with a model that has a pattern constraint:
components:
schemas:
PhoneNumber:
type: string
pattern: '^+[1-9]\d{1,14}$'
- Generate a Rust crate using rust-server generator
- In a consuming crate, depend on the generated crate with only features = ["client"]
- Build → compile errors on lazy_static and regex
Related issues/PRs
Suggest a fix
Either:
A) Add "lazy_static", "regex" to the client feature unconditionally (matching server):
client = [
...
"hyper", "percent-encoding", "hyper-util/http1", "hyper-util/http2", "url",
{{^apiUsesByteArray}}"lazy_static", "regex"{{/apiUsesByteArray}}
]
B) Gate the model lazy_static! blocks behind #[cfg(any(feature = "server", feature = "client", feature = "validate"))] — though this is more complex and may break validation.
Option A is simpler and matches the existing server feature pattern.
Bug Report Checklist
Description
When an OpenAPI spec contains models with pattern validation (regex constraints on string properties), the generated models.rs emits lazy_static::lazy_static! blocks and regex::Regex usages unconditionally — they are not gated behind any feature flag.
However, in the generated Cargo.toml, the client feature does not include "lazy_static" or "regex" in its dependency list (unless hasCallbacks is true). The server feature correctly includes them.
This means a consumer that enables only features = ["client"] (without "server") gets compile errors when any model in the spec uses pattern:
error[E0433]: failed to resolve: use of undeclared crate or module
lazy_staticerror[E0433]: failed to resolve: use of undeclared crate or module
regexRoot Cause
In Cargo.mustache (line ~47):
client = [
...
{{#hasCallbacks}}
"serde_ignored", "percent-encoding", {{^apiUsesByteArray}}"lazy_static", "regex",{{/apiUsesByteArray}}
{{/hasCallbacks}}
"hyper", "percent-encoding", "hyper-util/http1", "hyper-util/http2", "url"
]
The lazy_static and regex features are only added to client when hasCallbacks is true (for server-path routing in callback handling).
But in models.mustache (line ~471):
{{#vars}}
{{#hasValidation}}
{{#pattern}}
{{^isByteArray}}
lazy_static::lazy_static! {
static ref RE_...: regex::Regex = regex::Regex::new(r"{{ pattern }}").unwrap();
}
{{/isByteArray}}
{{/pattern}}
{{/hasValidation}}
{{/vars}}
These model-level regex statics are emitted for any feature combination — they're part of the shared models.rs that both client and server use
openapi-generator version
Present across all 7.x releases
OpenAPI declaration file content or url
openapi: "3.0.3"
info:
title: Test API
version: "1.0.0"
paths:
/phone:
get:
summary: Get phone
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/PhoneNumber"
components:
schemas:
PhoneNumber:
type: string
pattern: '^+[1-9]\d{1,14}$'
Generation Details
Generate with rust-server:
java -jar openapi-generator-cli.jar generate
-i test-spec.yaml
-g rust-server
-o output/
Then in the consuming crate, depend on the generated crate with client-only:
my-api = { path = "../output", default-features = false, features = ["client"] }
Build fails:
lazy_staticregexNo special additional properties or config needed — any spec with a pattern constraint on a model triggers it when using only the client feature (without server).
Steps to reproduce
components:
schemas:
PhoneNumber:
type: string
pattern: '^+[1-9]\d{1,14}$'
Related issues/PRs
Suggest a fix
Either:
A) Add "lazy_static", "regex" to the client feature unconditionally (matching server):
client = [
...
"hyper", "percent-encoding", "hyper-util/http1", "hyper-util/http2", "url",
{{^apiUsesByteArray}}"lazy_static", "regex"{{/apiUsesByteArray}}
]
B) Gate the model lazy_static! blocks behind #[cfg(any(feature = "server", feature = "client", feature = "validate"))] — though this is more complex and may break validation.
Option A is simpler and matches the existing server feature pattern.