( schema: JsonSchema, defaultInput: unknown, ctx: JsonSchemaContext )
| 1177 | } |
| 1178 | |
| 1179 | const writeDefault = ( |
| 1180 | schema: JsonSchema, |
| 1181 | defaultInput: unknown, |
| 1182 | ctx: JsonSchemaContext |
| 1183 | ): JsonSchema => { |
| 1184 | const value = |
| 1185 | typeof defaultInput === "function" ? defaultInput() : defaultInput |
| 1186 | const jsonDefault = |
| 1187 | isJsonData(value) ? value : ( |
| 1188 | ctx.fallback.defaultValue({ code: "defaultValue", value: value as never }) |
| 1189 | ) |
| 1190 | if (jsonDefault === undefined) return schema |
| 1191 | // OpenAPI 3.0 Reference Objects forbid sibling keywords and draft-07 ignores |
| 1192 | // them, so a $ref is wrapped to hold its default. Whether a fallback's |
| 1193 | // result is one is only known as it's called, so a writer reads it, which a |
| 1194 | // build records and its replay runs again |
| 1195 | if (ctx.target === "draft-07" || ctx.target === "openapi-3.0") |
| 1196 | return ctx.writers.default(schema, jsonDefault) |
| 1197 | schema.default = jsonDefault |
| 1198 | return schema |
| 1199 | } |
| 1200 | |
| 1201 | const reduceSequenceJsonSchema = ( |
| 1202 | node: Sequence.Node, |
no test coverage detected