Skip to content

Commit c2f6432

Browse files
committed
Nest discriminators
1 parent 2854edd commit c2f6432

File tree

2 files changed

+137
-12
lines changed

2 files changed

+137
-12
lines changed

schema.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,16 @@ export interface CustomElementExport {
155155
deprecated?: boolean | string;
156156
}
157157

158+
/**
159+
* @discriminator kind
160+
*/
158161
export type Declaration =
159-
| ClassDeclaration
160162
| FunctionDeclaration
161-
| MixinDeclaration
162163
| VariableDeclaration
163-
| CustomElementDeclaration
164-
| CustomElementMixinDeclaration;
164+
| /** @discriminator customElement */(MixinDeclaration
165+
| CustomElementMixinDeclaration)
166+
| /** @discriminator customElement */(ClassDeclaration
167+
| CustomElementDeclaration)
165168

166169
/**
167170
* A reference to an export of a module.

schema.json

Lines changed: 130 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,26 +590,148 @@
590590
"type": "object"
591591
},
592592
"Declaration": {
593-
"anyOf": [
593+
"allOf": [
594594
{
595-
"$ref": "#/definitions/ClassDeclaration"
595+
"if": {
596+
"properties": {
597+
"kind": {
598+
"const": "function",
599+
"type": "string"
600+
}
601+
}
602+
},
603+
"then": {
604+
"$ref": "#/definitions/FunctionDeclaration"
605+
}
596606
},
597607
{
598-
"$ref": "#/definitions/FunctionDeclaration"
608+
"if": {
609+
"properties": {
610+
"kind": {
611+
"const": "variable",
612+
"type": "string"
613+
}
614+
}
615+
},
616+
"then": {
617+
"$ref": "#/definitions/VariableDeclaration"
618+
}
599619
},
600620
{
601-
"$ref": "#/definitions/MixinDeclaration"
621+
"if": {
622+
"allOf": [
623+
{
624+
"properties": {
625+
"kind": {
626+
"const": "mixin",
627+
"type": "string"
628+
}
629+
},
630+
"required": [
631+
"kind"
632+
]
633+
},
634+
{
635+
"not": {
636+
"properties": {
637+
"customElement": {}
638+
},
639+
"required": [
640+
"customElement"
641+
]
642+
}
643+
}
644+
]
645+
},
646+
"then": {
647+
"$ref": "#/definitions/MixinDeclaration"
648+
}
602649
},
603650
{
604-
"$ref": "#/definitions/VariableDeclaration"
651+
"if": {
652+
"properties": {
653+
"customElement": {
654+
"const": true
655+
},
656+
"kind": {
657+
"const": "mixin",
658+
"type": "string"
659+
}
660+
},
661+
"required": [
662+
"kind",
663+
"customElement"
664+
]
665+
},
666+
"then": {
667+
"$ref": "#/definitions/CustomElementMixinDeclaration"
668+
}
605669
},
606670
{
607-
"$ref": "#/definitions/CustomElementDeclaration"
671+
"if": {
672+
"allOf": [
673+
{
674+
"properties": {
675+
"kind": {
676+
"const": "class",
677+
"type": "string"
678+
}
679+
},
680+
"required": [
681+
"kind"
682+
]
683+
},
684+
{
685+
"not": {
686+
"properties": {
687+
"customElement": {}
688+
},
689+
"required": [
690+
"customElement"
691+
]
692+
}
693+
}
694+
]
695+
},
696+
"then": {
697+
"$ref": "#/definitions/ClassDeclaration"
698+
}
608699
},
609700
{
610-
"$ref": "#/definitions/CustomElementMixinDeclaration"
701+
"if": {
702+
"properties": {
703+
"customElement": {
704+
"const": true
705+
},
706+
"kind": {
707+
"const": "class",
708+
"type": "string"
709+
}
710+
},
711+
"required": [
712+
"kind",
713+
"customElement"
714+
]
715+
},
716+
"then": {
717+
"$ref": "#/definitions/CustomElementDeclaration"
718+
}
611719
}
612-
]
720+
],
721+
"properties": {
722+
"kind": {
723+
"enum": [
724+
"function",
725+
"variable",
726+
"mixin",
727+
"class"
728+
]
729+
}
730+
},
731+
"required": [
732+
"kind"
733+
],
734+
"type": "object"
613735
},
614736
"Demo": {
615737
"additionalProperties": false,

0 commit comments

Comments
 (0)