Merge pull request #6030 from xmahle/handle-nullable-in-parser

Handle nullable in parser.parseType
This commit is contained in:
Richard Davey 2022-04-14 16:13:50 +01:00 committed by GitHub
commit a9793f3261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -490,7 +490,7 @@ export class Parser {
continue;
}
let param = dom.create.parameter(paramDoc.name, this.parseType(paramDoc));
let param = dom.create.parameter(paramDoc.name, this.parseType(paramDoc, dom.type.undefined));
parameters.push(param);
if (optional && paramDoc.optional != true) {
@ -514,7 +514,7 @@ export class Parser {
obj.parameters = parameters;
}
private parseType(typeDoc: any): dom.Type {
private parseType(typeDoc: any, nullableType = dom.type.null): dom.Type {
if (!typeDoc || !typeDoc.type) {
return dom.type.any;
} else {
@ -527,6 +527,9 @@ export class Parser {
types.push(type);
}
if (typeDoc.nullable) {
types.push(nullableType);
}
if (types.length == 1) return types[0];
else return dom.create.union(types);
}