(variant: JsonUnionVariant, variants: JsonUnionVariant[])
| 938 | } |
| 939 | |
| 940 | function getJsonUnionMatchExpression(variant: JsonUnionVariant, variants: JsonUnionVariant[]): string | undefined { |
| 941 | const required = new Set(variant.schema?.required ?? []); |
| 942 | if (required.size === 0) return undefined; |
| 943 | |
| 944 | const otherRequired = new Set<string>(); |
| 945 | for (const other of variants) { |
| 946 | if (other === variant) continue; |
| 947 | for (const property of other.schema?.required ?? []) { |
| 948 | otherRequired.add(property); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | const present = [...required].filter((property) => !otherRequired.has(property)); |
| 953 | if (present.length === 0) return undefined; |
| 954 | |
| 955 | const absent = new Set<string>(); |
| 956 | for (const other of variants) { |
| 957 | if (other === variant) continue; |
| 958 | for (const property of other.schema?.required ?? []) { |
| 959 | if (!required.has(property)) absent.add(property); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | return [ |
| 964 | "element.ValueKind == JsonValueKind.Object", |
| 965 | ...present.map((property) => `element.TryGetProperty("${escapeCSharpStringLiteral(property)}", out _)`), |
| 966 | ...[...absent].sort().map((property) => `!element.TryGetProperty("${escapeCSharpStringLiteral(property)}", out _)`), |
| 967 | ].join(" && "); |
| 968 | } |
| 969 | |
| 970 | function generateJsonUnionClass(className: string, variants: JsonUnionVariant[], description: string | undefined, jsonContextType: string, isInternal: boolean): string { |
| 971 | const lines: string[] = []; |
no test coverage detected
searching dependent graphs…