Bug Report Checklist
Description
The typescript-fetch generator does not enforce a string property's not: { enum: [...] } constraint in its generated type guard. The generated instanceOfOther guard accepts both the excluded value "known" and an allowed value such as "other". This makes the guards for the Known and Other variants overlap even though their schemas are intended to be mutually exclusive.
openapi-generator version
Reproduced with a local 7.26.0-SNAPSHOT build. The unmodified source baseline was upstream commit 271e4dd6e6d03ee456d8acef6542617371ef827c. The latest master has not been retested separately.
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: TypeScript not enum reproduction
version: 1.0.0
paths: {}
components:
schemas:
Known:
type: object
required: [kind]
properties:
kind:
type: string
enum: [known]
Other:
type: object
required: [kind]
properties:
kind:
type: string
not:
enum: [known]
TaggedUnion:
oneOf:
- $ref: '#/components/schemas/Known'
- $ref: '#/components/schemas/Other'
The spec passes openapi-generator-cli validate with no validation errors. The CLI reports only recommendations that the three models are unused because the spec has no paths. All three model files are generated with the default typescript-fetch options.
Generation Details
Generator: typescript-fetch, with default options.
openapi-generator-cli generate \
-i typescript-not-enum.yaml \
-g typescript-fetch \
-o /tmp/typescript-not-enum
Steps to reproduce
- Save the spec above as
typescript-not-enum.yaml and generate the client.
- Import
instanceOfOther from the generated models/Other.ts and evaluate it with { kind: "known" } and { kind: "other" }.
Actual behavior:
instanceOfOther({ kind: "known" }) -> true
instanceOfOther({ kind: "other" }) -> true
Expected behavior:
instanceOfOther({ kind: "known" }) -> false
instanceOfOther({ kind: "other" }) -> true
"known" is explicitly excluded by not: { enum: [known] }. With Known first in this reproduction, TaggedUnion resolution may choose Known before testing Other, so this example does not necessarily throw a multiple-match error. The incorrect Other guard is independently reproducible.
Related issues/PRs
Related Go report: #25090. Related Go fix: #25089. Related Java report: #25065. Related Python report: #25069.
Suggest a fix
Preserve and enforce the nested not.enum constraint when typescript-fetch generates type guards for object properties.
Bug Report Checklist
Description
The
typescript-fetchgenerator does not enforce a string property'snot: { enum: [...] }constraint in its generated type guard. The generatedinstanceOfOtherguard accepts both the excluded value"known"and an allowed value such as"other". This makes the guards for theKnownandOthervariants overlap even though their schemas are intended to be mutually exclusive.openapi-generator version
Reproduced with a local
7.26.0-SNAPSHOTbuild. The unmodified source baseline was upstream commit271e4dd6e6d03ee456d8acef6542617371ef827c. The latest master has not been retested separately.OpenAPI declaration file content or url
The spec passes
openapi-generator-cli validatewith no validation errors. The CLI reports only recommendations that the three models are unused because the spec has no paths. All three model files are generated with the defaulttypescript-fetchoptions.Generation Details
Generator:
typescript-fetch, with default options.Steps to reproduce
typescript-not-enum.yamland generate the client.instanceOfOtherfrom the generatedmodels/Other.tsand evaluate it with{ kind: "known" }and{ kind: "other" }.Actual behavior:
Expected behavior:
"known"is explicitly excluded bynot: { enum: [known] }. WithKnownfirst in this reproduction,TaggedUnionresolution may chooseKnownbefore testingOther, so this example does not necessarily throw a multiple-match error. The incorrectOtherguard is independently reproducible.Related issues/PRs
Related Go report: #25090. Related Go fix: #25089. Related Java report: #25065. Related Python report: #25069.
Suggest a fix
Preserve and enforce the nested
not.enumconstraint whentypescript-fetchgenerates type guards for object properties.