Skip to content

Commit 2d57255

Browse files
authored
fix(core): nullable array types in 3.1.x specs (#19687)
* fix: nullable array types in 3.1.x * fix: pass on on `getNullable` value * chore: add generated marker * chore: add generated marker * Delete out
1 parent ea6b1c6 commit 2d57255

File tree

31 files changed

+1377
-0
lines changed

31 files changed

+1377
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
generatorName: typescript
2+
outputDir: samples/client/others/typescript/builds/null-types-simple
3+
inputSpec: modules/openapi-generator/src/test/resources/3_1/null-types-simple.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ private Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchemas)
12681268
as.setMaxItems(schema.getMaxItems());
12691269
as.setExtensions(schema.getExtensions());
12701270
as.setXml(schema.getXml());
1271+
as.setNullable(schema.getNullable());
12711272
as.setUniqueItems(schema.getUniqueItems());
12721273
if (schema.getItems() != null) {
12731274
// `items` is also a json schema

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class ModelUtils {
6363

6464
private static final String URI_FORMAT = "uri";
6565

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

6869
private static final String generateAliasAsModelKey = "generateAliasAsModel";
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openapi: 3.1.0
2+
info:
3+
title: ""
4+
version: ""
5+
components:
6+
schemas:
7+
WithNullableType:
8+
type: object
9+
required:
10+
# This simplifies the output
11+
- arrayDataOrNull
12+
- stringDataOrNull
13+
- oneofOrNull
14+
properties:
15+
arrayDataOrNull:
16+
items:
17+
$ref: "#/components/schemas/SomeObject"
18+
type:
19+
- array
20+
- 'null'
21+
# This was working when this fixture was introduced,
22+
# but we need to make sure we don't regress
23+
stringDataOrNull:
24+
type:
25+
- string
26+
- 'null'
27+
# This was working when this fixture was introduced,
28+
# but we need to make sure we don't regress
29+
oneofOrNull:
30+
oneOf:
31+
- $ref: "#/components/schemas/SomeObject"
32+
- type: 'null'
33+
SomeObject:
34+
type: object
35+
properties:
36+
data:
37+
type: string
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
builds/**/* linguist-generated=true

samples/client/others/typescript/builds/null-types-simple/.gitignore

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/.openapi-generator-ignore

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/.openapi-generator/FILES

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/.openapi-generator/VERSION

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/README.md

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/apis/baseapi.ts

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/apis/exception.ts

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/auth/auth.ts

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/configuration.ts

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)