(required: boolean, schema: JSONSchema)
| 171 | } |
| 172 | |
| 173 | export function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema { |
| 174 | if (required) { |
| 175 | return schema |
| 176 | } |
| 177 | |
| 178 | return { |
| 179 | anyOf: [ |
| 180 | schema, |
| 181 | { not: {} }, |
| 182 | ], |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf), |
no outgoing calls
no test coverage detected