( js: JsonSchema.JsonSchema, acceptsNull: (schema: JsonSchema.JsonSchema) => boolean )
| 228 | |
| 229 | /** Converts legacy `nullable: true` markers, including standalone `allOf` members, to null unions. */ |
| 230 | const 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 | |
| 245 | const objectKeys = new Set(["type", "properties", "required", "additionalProperties"]) |
| 246 | const annotationKeys = new Set([ |
no test coverage detected