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

Function normalizeOpenEnum

packages/tools/ai-codegen/src/Generator.ts:115–130  ·  view source on GitHub ↗
(js: JsonSchema.JsonSchema)

Source from the content-addressed store, hash-verified

113 * still exposing the known values as `members[1]` for autocomplete.
114 */
115const normalizeOpenEnum = (js: JsonSchema.JsonSchema): JsonSchema.JsonSchema => {
116 const anyOf = js.anyOf
117 if (!Array.isArray(anyOf) || anyOf.length < 2) return js
118
119 const [head, ...tail] = anyOf
120 if (!isOpenStringBranch(head)) return js
121
122 const literals: Array<string> = []
123 for (const branch of tail) {
124 const value = constBranchValue(branch)
125 if (value === undefined) return js
126 literals.push(value)
127 }
128
129 return { ...js, anyOf: [head, { enum: literals }] }
130}
131
132/**
133 * Layer providing the CodeGenerator service.

Callers 1

onEnterFunction · 0.85

Calls 3

isOpenStringBranchFunction · 0.85
constBranchValueFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected