-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix(core): nullable array
types in 3.1.x
specs
#19687
fix(core): nullable array
types in 3.1.x
specs
#19687
Conversation
- stringDataOrNull | ||
- oneofOrNull | ||
properties: | ||
arrayDataOrNull: |
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.
This is the broken part
import { HttpFile } from '../http/http'; | ||
|
||
export class WithNullableType { | ||
'arrayDataOrNull': Array<SomeObject>; |
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.
Should be:
'arrayDataOrNull': Array<SomeObject>; | |
'arrayDataOrNull': Array<SomeObject> | null; |
import { HttpFile } from '../http/http'; | ||
|
||
export class WithNullableType { | ||
'arrayDataOrNull': Array<SomeObject> | null; |
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.
This line is the fix - it now has the | null
@@ -0,0 +1 @@ | |||
builds/**/* linguist-generated=true |
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.
This makes sure that all the generated code collapses in the github diff.
@@ -1268,6 +1268,7 @@ private Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchemas) | |||
as.setMaxItems(schema.getMaxItems()); | |||
as.setExtensions(schema.getExtensions()); | |||
as.setXml(schema.getXml()); | |||
as.setNullable(schema.getNullable()); |
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.
Further up, we fix up the nullable
flag when the types contain the new 3.1 null
type:
Lines 1249 to 1252 in 29c3b02
if (schema.getTypes().contains("null")) { | |
schema.setNullable(true); | |
schema.getTypes().remove("null"); | |
} |
but then, if there's a single type left AND it is an array schema, we forget to copy this property to the cloned ArraySchema
. This line makes sure that the nullable flag is transferred onto the schema clone.
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.
This issue is likely to happen again in the future when/if a new property is added that is in 3.1+ but not 3.0.x - we could possibly introduce a clone
or transfer
function somewhere which would make this a bit more obvious, but it's not a guarantee either.
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.
thanks!
array
types in 3.1.x
specs
array
types in 3.1.x
specsarray
types in 3.1.x
specs
…penapi-generator into joscha/nullable-array-types-3_1
lgtm. thanks for the fix. i will file another PR to add a unit test later this week |
Quickly added one: #19714; also fixes the botched up samples due to a cross-interaction with changes on |
Currently, in 3.1 specs, the follwing:
yields:
where it should yield:
It seems either nullability is not determined correctly in core and/or the
typescript
generator doesn't interpret it correctly.Real-life example: planet-a-ventures/affinity-node#49
Discussion: https://openapi-generator.slack.com/archives/CLSB0U0R5/p1727342905017529
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)If your PR is targeting a particular programming languageI think this is a core issue: @wing328 (2015/07) ❤️@jimschubert (2016/05) ❤️
@cbornet (2016/05)
@jmini (2018/04) ❤️
@etherealjoy (2019/06)