-
-
Notifications
You must be signed in to change notification settings - Fork 432
fix: nullable not respected for objects with nullable properties #533 #1550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bankyadam
wants to merge
10
commits into
acacode:main
Choose a base branch
from
bankyadam:issue-533
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d55a70e
fix: nullable is not respected if type: object #533
bankyadam-sx 6c08c87
fix: yarn immutable check issue
bankyadam-sx 4bddc9c
fix: lint issue
bankyadam-sx 6db9615
fix: adding changeset
bankyadam-sx 0fb029e
fix: Missing detection of null in middle of unions
bankyadam-sx 62b1ac8
fix: lint issue
bankyadam-sx 9f211a3
Merge branch 'main' into issue-533
bankyadam 93f68aa
Merge remote-tracking branch 'upstream/main' into issue-533
bankyadam 252b994
fix: handle parenthesized union types in null detection
bankyadam 97fb41c
test: regenerate snapshots after vitest key format change
bankyadam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "swagger-typescript-api": patch | ||
| --- | ||
|
|
||
| Fixed incorrect null handling for nullable objects with nullable properties (#533) |
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -151,24 +151,20 @@ export class SchemaUtils { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| isNullMissingInType = (schema, type) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const { nullable, type: schemaType } = schema || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| !( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| nullable || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| !!get(schema, "x-nullable") || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| schemaType === this.config.Ts.Keyword.Null | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof type !== "string" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const isSchemaMarkedNullable = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| nullable || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| !!get(schema, "x-nullable") || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| schemaType === this.config.Ts.Keyword.Null; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!isSchemaMarkedNullable) return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (typeof type !== "string") return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const nullKeyword = this.config.Ts.Keyword.Null; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const lastLine = type.trimEnd().split("\n").pop() ?? type; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasRootLevelNull = new RegExp( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| `(^|\\||\\()\\s*${nullKeyword}\\s*(\\||\\)|$)`, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ).test(type); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+163
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The regex check treats nested Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| !lastLine.includes(` ${nullKeyword}`) && | ||||||||||||||||||||||||||||||||||||||||||||||||||
| !lastLine.includes(`${nullKeyword} `) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return !hasRootLevelNull; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| safeAddNullToType = (schema, type) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Regex incorrectly matches null inside parenthesized sub-expressions, causing nullable arrays of nullable elements to lose their root-level
| null. For a nullable array with nullable items, the type(string | null)[]would not get| nullappended because the regex matches| null)inside the group.Consider anchoring the parenthesis check so it only matches when the parenthesized group constitutes the entire type (e.g.,
^\(.*\)$), or using a more targeted approach that doesn't match nested groups followed by array/generic suffixes.Prompt for AI agents