(cxt: ParseCxt, discriminator?: string)
| 209 | } |
| 210 | |
| 211 | function parseSchemaProperties(cxt: ParseCxt, discriminator?: string): void { |
| 212 | const {gen, schema, data} = cxt |
| 213 | const {properties, optionalProperties, additionalProperties} = schema |
| 214 | parseItems(cxt, "}", () => { |
| 215 | const key = gen.let("key") |
| 216 | parseString({...cxt, data: key}) |
| 217 | parseToken(cxt, ":") |
| 218 | gen.if(false) |
| 219 | parseDefinedProperty(cxt, key, properties) |
| 220 | parseDefinedProperty(cxt, key, optionalProperties) |
| 221 | if (discriminator) { |
| 222 | gen.elseIf(_`${key} === ${discriminator}`) |
| 223 | const tag = gen.let("tag") |
| 224 | parseString({...cxt, data: tag}) // can be discarded, it is already assigned |
| 225 | } |
| 226 | gen.else() |
| 227 | if (additionalProperties) { |
| 228 | parseEmpty({...cxt, data: _`${data}[${key}]`}) |
| 229 | } else { |
| 230 | parsingError(cxt, str`property ${key} not allowed`) |
| 231 | } |
| 232 | gen.endIf() |
| 233 | }) |
| 234 | if (properties) { |
| 235 | const hasProp = hasPropFunc(gen) |
| 236 | const allProps: Code = and( |
| 237 | ...Object.keys(properties).map((p): Code => _`${hasProp}.call(${data}, ${p})`) |
| 238 | ) |
| 239 | gen.if(not(allProps), () => parsingError(cxt, str`missing required properties`)) |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | function parseDefinedProperty(cxt: ParseCxt, key: Name, schemas: SchemaObjectMap = {}): void { |
| 244 | const {gen} = cxt |
no test coverage detected
searching dependent graphs…