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

Function rewriteNullable

packages/tools/ai-codegen/src/Generator.ts:230–243  ·  view source on GitHub ↗
(
  js: JsonSchema.JsonSchema,
  acceptsNull: (schema: JsonSchema.JsonSchema) => boolean
)

Source from the content-addressed store, hash-verified

228
229/** Converts legacy `nullable: true` markers, including standalone `allOf` members, to null unions. */
230const rewriteNullable = (
231 js: JsonSchema.JsonSchema,
232 acceptsNull: (schema: JsonSchema.JsonSchema) => boolean
233): JsonSchema.JsonSchema => {
234 const allOf = Array.isArray(js.allOf) ? js.allOf : undefined
235 if (js.nullable !== true && !allOf?.some(isNullableMarker)) return js
236 const { nullable: _, ...rest } = js
237 const members = allOf?.filter((member) => !isNullableMarker(member))
238 const { allOf: _allOf, ...base } = rest
239 const schema = members === undefined ? rest : members.length === 0 ? base : { ...base, allOf: members }
240 if (acceptsNull(schema)) return schema
241 const annotations = pick(schema, isAnnotation)
242 return { ...annotations, anyOf: [pick(schema, (key) => !isAnnotation(key)), { type: "null" }] }
243}
244
245const objectKeys = new Set(["type", "properties", "required", "additionalProperties"])
246const annotationKeys = new Set([

Callers 1

prepareFunction · 0.85

Calls 6

isNullableMarkerFunction · 0.85
isAnnotationFunction · 0.85
someMethod · 0.80
acceptsNullFunction · 0.70
pickFunction · 0.70
filterMethod · 0.45

Tested by

no test coverage detected