Repository navigation
Description
Bug Report Checklist
- Provided a minimal standalone spec.
- Validated the OpenAPI 3.0 and 3.1 regression fixtures with the CLI validator.
- Reproduced on the latest master.
- Searched related issues and PRs.
- Included actual and expected output.
Description
With typescript-axios, a primitive schema whose anyOf alternatives contain validation keywords but no type becomes an empty interface and is incorrectly made nullable.
A pattern-only branch is not a null-only schema. The enclosing type: string still restricts the value to a string. See the OpenAPI Schema Object and JSON Schema validation keywords.
Actual output:
export interface Hostname {}
export interface Address {
'hostname': Hostname | null;
}This accepts numbers and null as SDK method arguments, and a returned hostname cannot be assigned to a string.
Expected output:
export type Hostname = string;
export interface Address {
'hostname': Hostname;
}The original pattern constraints should remain in the normalized OpenAPI document. TypeScript does not express those predicates, but it can preserve the enclosing primitive type and its nullability.
openapi-generator version
Reproduced with 7.27.0 and master at df804ac9802fba0c51a64f8c3cb03191ed3dde2d (7.28.0-SNAPSHOT). The new ModelUtils, normalizer, and Axios regression tests fail against the unmodified master implementation.
OpenAPI declaration file content or url
openapi: 3.0.3
info: {title: Primitive anyOf validation, version: 1.0.0}
paths: {}
components:
schemas:
Hostname:
type: string
anyOf: [{pattern: '^[a-z]+[.]example$'}, {pattern: '^[*][.][a-z]+[.]example$'}]
Address: {type: object, required: [hostname], properties: {hostname: {$ref: '#/components/schemas/Hostname'}}}Generation Details
java -jar openapi-generator-cli.jar generate \
-g typescript-axios -i primitive-anyof.yaml -o generatedSteps to reproduce
- Save the spec above as
primitive-anyof.yaml. - Run the generation command.
- Inspect
HostnameandAddress.hostnameingenerated/api.ts.
Related issues/PRs
#19155 concerns an untyped union of explicit primitive alternatives. #22427 and #24356 concern nullable reference propagation. This report concerns validation-only alternatives under an explicitly typed parent.
Suggest a fix
- Do not classify validation-only schemas as null schemas or discard their predicates during OpenAPI 3.1 normalization.
- Preserve an enclosing type when simplifying a single validation-only alternative.
- Generate primitive aliases for the Axios models, including inline properties and nullable references, while retaining genuine nullability.
AI disclosure — Codex
Codex investigated the code, prepared standalone fixtures, ran the reproductions and validation, and drafted this report. I supplied the problem and requested an upstream fix.
Activity