forked from baidu/amis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntersectionNodeParser.ts
More file actions
38 lines (32 loc) · 1.19 KB
/
IntersectionNodeParser.ts
File metadata and controls
38 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
BaseType,
Context,
IntersectionNodeParser as BaseIntersectionNodeParser,
IntersectionType,
NodeParser,
ReferenceType
} from 'ts-json-schema-generator';
import ts from 'typescript';
export class IntersectionNodeParser extends BaseIntersectionNodeParser {
protected readonly childParser: NodeParser;
public constructor(typeChecker: ts.TypeChecker, childNodeParser: NodeParser) {
super(typeChecker as any, childNodeParser);
this.childParser = childNodeParser;
}
public createType(node: any, context: Context): BaseType | undefined {
// 这两个只能用 allOf 来了,提取不了。
const shouldBeReference = (type: any) =>
['SchemaObject', 'FormControlSchema'].includes(
type.typeName?.escapedText
);
const matched = node.types.some(shouldBeReference);
// 跟 SchemaObject and 一般都有问题,改成 allOf 不要支持 additional props false 了
if (matched) {
const types: BaseType[] = node.types
.map((type: any) => this.childParser.createType(type as any, context)!)
.filter((item: any) => item);
return new IntersectionType(types);
}
return super.createType(node as any, context);
}
}