| 335 | * @experimental |
| 336 | */ |
| 337 | export const fromAST = (ast: AST.AST, options: { |
| 338 | readonly definitions: Record<string, JsonSchema7> |
| 339 | readonly definitionPath?: string | undefined |
| 340 | readonly target?: Target | undefined |
| 341 | readonly topLevelReferenceStrategy?: TopLevelReferenceStrategy | undefined |
| 342 | readonly additionalPropertiesStrategy?: AdditionalPropertiesStrategy | undefined |
| 343 | }): JsonSchema7 => { |
| 344 | const definitionPath = options.definitionPath ?? "#/$defs/" |
| 345 | const getRef = (id: string) => definitionPath + id |
| 346 | const target = options.target ?? "jsonSchema7" |
| 347 | const topLevelReferenceStrategy = options.topLevelReferenceStrategy ?? "keep" |
| 348 | const additionalPropertiesStrategy = options.additionalPropertiesStrategy ?? "strict" |
| 349 | return go( |
| 350 | ast, |
| 351 | options.definitions, |
| 352 | "handle-identifier", |
| 353 | [], |
| 354 | { |
| 355 | getRef, |
| 356 | target, |
| 357 | topLevelReferenceStrategy, |
| 358 | additionalPropertiesStrategy |
| 359 | }, |
| 360 | "handle-annotation", |
| 361 | "handle-errors" |
| 362 | ) |
| 363 | } |
| 364 | |
| 365 | const constNever: JsonSchema7Never = { |
| 366 | $id: "/schemas/never", |