Skip to content

Commit f1988f6

Browse files
committed
Support v3.1 typed arrays
In OpenAPI v3.1 the nullable property was replaced with a "typed array", that is an array that can either be of type T or null. To make the minimal amount of changes this commit converts a type array back into what a 3.0 parser would expect. Closes #991
1 parent c2ade36 commit f1988f6

File tree

1 file changed

+11
-0
lines changed
  • src/schema-parser/base-schema-parsers

1 file changed

+11
-0
lines changed

src/schema-parser/base-schema-parsers/object.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ export class ObjectSchemaParser extends MonoSchemaParser {
3636
"rawTypeData",
3737
{},
3838
);
39+
// In OpenAPI v3.1 the nullable property was replaced with a "typed
40+
// array", that is an array that can either be of type T or null.
41+
if (Array.isArray(property.type) && property.type.length == 2) {
42+
if (property.type[0] == "null") {
43+
property.type = property.type[1];
44+
property.nullable = true;
45+
} else if (property.type[1] == "null") {
46+
property.type = property.type[0];
47+
property.nullable = true;
48+
}
49+
}
3950
const nullable = !!(rawTypeData.nullable || property.nullable);
4051
const fieldName = this.typeNameFormatter.isValidName(name)
4152
? name

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy