Skip to content
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

Merged
merged 7 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/configs/typescript-consolidated-nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
generatorName: typescript
outputDir: samples/client/others/typescript/builds/null-types-simple
inputSpec: modules/openapi-generator/src/test/resources/3_1/null-types-simple.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Contributor Author

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:

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.

Copy link
Contributor Author

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.

as.setUniqueItems(schema.getUniqueItems());
if (schema.getItems() != null) {
// `items` is also a json schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class ModelUtils {

private static final String URI_FORMAT = "uri";

// These types are for 3.0.x only; 3.1 also has a `null` type as well
private static final Set<String> OPENAPI_TYPES = Set.of("array", "integer", "number", "boolean", "string", "object");

private static final String generateAliasAsModelKey = "generateAliasAsModel";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
openapi: 3.1.0
info:
title: ""
version: ""
components:
schemas:
WithNullableType:
type: object
required:
# This simplifies the output
- arrayDataOrNull
- stringDataOrNull
- oneofOrNull
properties:
arrayDataOrNull:
Copy link
Contributor Author

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

items:
$ref: "#/components/schemas/SomeObject"
type:
- array
- 'null'
# This was working when this fixture was introduced,
# but we need to make sure we don't regress
stringDataOrNull:
type:
- string
- 'null'
# This was working when this fixture was introduced,
# but we need to make sure we don't regress
oneofOrNull:
oneOf:
- $ref: "#/components/schemas/SomeObject"
- type: 'null'
SomeObject:
type: object
properties:
data:
type: string
1 change: 1 addition & 0 deletions samples/client/others/typescript/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
builds/**/* linguist-generated=true
Copy link
Contributor Author

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.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading