fix(typescript-fetch): filter Null type from oneOf to prevent missing model references#23179
Draft
guizmaii wants to merge 4 commits intoOpenAPITools:masterfrom
Draft
fix(typescript-fetch): filter Null type from oneOf to prevent missing model references#23179guizmaii wants to merge 4 commits intoOpenAPITools:masterfrom
guizmaii wants to merge 4 commits intoOpenAPITools:masterfrom
Conversation
… model references In OpenAPI 3.1, oneOf can include type: 'null' to represent nullable unions. The codegen maps this to a "Null" model name and adds it to the oneOf variants list and imports. However, no Null.ts model file is generated, causing TypeScript import errors like: Module '"../models/index"' has no exported member 'Null' Fix: remove "Null" from cm.oneOf and filter it from oneOfModels during model post-processing, following the same pattern used by the C#, Java, and PowerShell generators. The model is marked as nullable instead.
When a oneOf includes type: 'null', the Null model reference is removed to prevent broken imports. The union type should include | null to preserve the nullable semantics from the original spec.
When an API endpoint returns type: 'null' (OpenAPI 3.1), the codegen maps it to a Null model that doesn't exist as a generated file. Convert these operations to void return type and remove the Null import from both operation-level and operations-level imports.
Contributor
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java:721">
P2: Unconditional `"Null"` return-type rewrite can erase legitimate user-defined `Null` response models and remove needed imports.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java
Show resolved
Hide resolved
Verify that OpenAPI 3.1 responses with `type: 'null'` are converted to void return types instead of generating a broken Null model import.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In OpenAPI 3.1,
oneOfcan includetype: 'null'to represent nullable unions:The codegen maps
type: 'null'to a model named"Null"and adds it to the oneOf variants list. However, noNull.tsmodel file is ever generated, causing TypeScript import errors:Solution
Filter
"Null"fromcm.oneOfandcm.oneOfModelsduring model post-processing inTypeScriptFetchClientCodegen.processCodeGenModel(), and setcm.isNullable = trueinstead.This follows the same pattern already used by the C#, Java, and PowerShell generators:
CSharpClientCodegen.java:1670JavaClientCodegen.java:1207-1210PowerShellClientCodegen.java:1098-1101Test plan
testNullableOneOfDoesNotImportNullModeltest with a new spec (nullable-oneOf.yaml) that usestype: 'null'in aoneOfNullimports/references in the generated model fileNull.tsmodel file is generatedSummary by cubic
Fixes
typescript-fetchcodegen to handle OpenAPI 3.1type: 'null'correctly.oneOfunions now use| null, and operations that returnedNullare generated asvoid, removing broken imports.cm.oneOf/oneOfModels; setcm.isNullable = trueand updatemodelOneOfInterfaces.mustacheto append| null.returnType === 'Null'tovoidand removeNullfrom operation and file-level imports.nullable-oneOf.yamlto verify unions include only real models plus| nullwith noNull.ts, andnull-response.yamlto ensure null responses becomevoid.Written for commit cda4b15. Summary will update on new commits.