(js: JsonSchema.JsonSchema)
| 113 | * still exposing the known values as `members[1]` for autocomplete. |
| 114 | */ |
| 115 | const 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. |
no test coverage detected