Skip to content

Commit 1236cd2

Browse files
convert Null types in JSON schema to nullable attributes
1 parent 1ea87dc commit 1236cd2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

reverse_engineering/helpers/adaptJsonSchema/adaptJsonSchema.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,30 @@ const convertToString = (jsonSchema) => {
77
});
88
};
99

10+
const convertMultipleTypeToType = jsonSchema => {
11+
const type = jsonSchema.type.find(item => item !== 'null');
12+
13+
if (!type) {
14+
return convertToString(jsonSchema);
15+
} else if (!jsonSchema.type.includes('null')) {
16+
return {
17+
...jsonSchema,
18+
type
19+
}
20+
}
21+
22+
return {
23+
...jsonSchema,
24+
type,
25+
nullable: true
26+
}
27+
}
28+
1029
const adaptJsonSchema = (jsonSchema) => {
1130
return mapJsonSchema(jsonSchema, (jsonSchemaItem) => {
12-
if (jsonSchemaItem.type !== 'null') {
31+
if (Array.isArray(jsonSchemaItem.type)) {
32+
return convertMultipleTypeToType(jsonSchemaItem);
33+
} else if (jsonSchemaItem.type !== 'null') {
1334
return jsonSchemaItem;
1435
}
1536

0 commit comments

Comments
 (0)