MCPcopy Create free account
hub / github.com/Effect-TS/effect / extractUnionTypes

Function extractUnionTypes

packages/platform/src/HttpApiSchema.ts:220–241  ·  view source on GitHub ↗
(ast: AST.AST)

Source from the content-addressed store, hash-verified

218 * @internal
219 */
220export const extractUnionTypes = (ast: AST.AST): ReadonlyArray<AST.AST> => {
221 if (!AST.isUnion(ast)) {
222 return [ast]
223 }
224 const types = ast.types.flatMap(extractUnionTypes)
225 if (!types.some(needsOwnResponse)) {
226 return Reflect.ownKeys(ast.annotations).length > 0 ? [ast] : types
227 }
228 const annotations = extractAnnotations(ast.annotations)
229 const keys = Reflect.ownKeys(annotations)
230 if (keys.length === 0) {
231 return types
232 }
233 return types.map((type) => {
234 const merged = mergedAnnotations(type)
235 return keys.every((key) => key in merged) ? type : AST.annotations(type, {
236 ...annotations,
237 ...extractAnnotations(merged),
238 ...type.annotations
239 })
240 })
241}
242
243const needsOwnResponse = (ast: AST.AST): boolean =>
244 isVoid(ast) || Reflect.ownKeys(extractAnnotations(mergedAnnotations(ast))).length > 0

Callers 2

UnionUnifyASTFunction · 0.85
HttpApiSchema.tsFile · 0.85

Calls 4

mergedAnnotationsFunction · 0.85
extractAnnotationsFunction · 0.70
mapMethod · 0.65
annotationsMethod · 0.65

Tested by

no test coverage detected