( schema: StandardJSONSchemaV1, io: "in" | "out" )
| 75 | : parse(schema).toJsonSchema(options) |
| 76 | |
| 77 | const readStandardSchema = ( |
| 78 | schema: StandardJSONSchemaV1, |
| 79 | io: "in" | "out" |
| 80 | ): BaseRoot => { |
| 81 | // only its key was checked, so it may be anything |
| 82 | const standard = schema["~standard"] as |
| 83 | | Partial<StandardJSONSchemaV1.Props> |
| 84 | | null |
| 85 | | undefined |
| 86 | if (!hasDomain(standard, "object")) |
| 87 | return throwParseError(writeUnparsableSchemaMessage(printable(schema))) |
| 88 | const vendor = String(standard.vendor) |
| 89 | if (!hasDomain(standard.jsonSchema, "object")) { |
| 90 | return throwParseError( |
| 91 | writeUnparsableSchemaMessage( |
| 92 | `a ${vendor} Standard Schema without ~standard.jsonSchema` |
| 93 | ) |
| 94 | ) |
| 95 | } |
| 96 | const method = io === "in" ? "input" : "output" |
| 97 | let jsonSchema: JsonSchema.Input |
| 98 | try { |
| 99 | jsonSchema = standard.jsonSchema[method]({ target: "draft-2020-12" }) |
| 100 | } catch (cause) { |
| 101 | throw Object.assign( |
| 102 | new ParseError( |
| 103 | writeUnreadableStandardSchemaMessage(vendor, method, cause) |
| 104 | ), |
| 105 | { cause } |
| 106 | ) |
| 107 | } |
| 108 | return readJsonSchema(jsonSchema) |
| 109 | } |
no test coverage detected