MCPcopy
hub / github.com/ajv-validator/ajv / parseSchemaProperties

Function parseSchemaProperties

lib/compile/jtd/parse.ts:211–241  ·  view source on GitHub ↗
(cxt: ParseCxt, discriminator?: string)

Source from the content-addressed store, hash-verified

209}
210
211function 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
243function parseDefinedProperty(cxt: ParseCxt, key: Name, schemas: SchemaObjectMap = {}): void {
244 const {gen} = cxt

Callers 2

parseDiscriminatorFunction · 0.85
parsePropertiesFunction · 0.85

Calls 15

_Function · 0.90
strFunction · 0.90
hasPropFuncFunction · 0.90
andFunction · 0.90
notFunction · 0.90
parseItemsFunction · 0.85
parseStringFunction · 0.85
parseTokenFunction · 0.85
parseDefinedPropertyFunction · 0.85
parseEmptyFunction · 0.85
parsingErrorFunction · 0.85
letMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…