how to use the keyword 'items' in JSON Schema/AJV to refer to a response payload property with the same name 'items'

Viewed 215

I have a response payload that has a property named items. When I try creating a JSON Schema to validate the response payload with AJV I get the following warning strict mode: missing type "array" for keyword "items".

response-model.ts

const payloadItems = {
  type: 'array',
  items: {
    type: 'object',
    properties: {
      a: {
        type: 'string'
      },
      b: {
        type: 'integer',
      },
      c: {
        type: 'string'
      }
    }
  }
} as const;

const responseSchema = {
  allOf: [
    { ... },
    { items: payloadItems }
  ]
} as const;

I have also tried putting the payload items as a definition:

const responseSchema = {
  $defs: {
    payloadItems
  },
  allOf: [
    { ... },
    {
      items: {
        $ref: '#/$defs/payloadItems'
      }
    },
  ]
} as const;

Is there a way to use the name items as a property in the response payload AND as a keyword in the JSON Schema without the above message?

0 Answers
Related