ajv icon indicating copy to clipboard operation
ajv copied to clipboard

Incomplete documentation for validateSchema method in _KeywordDef?

Open manuganji opened this issue 3 years ago • 4 comments

I want to implement a keyword called order for object schema type. However, I can't access the object schema in validateSchema function.

What version of Ajv are you using? Does the issue happen if you use the latest version? 8.1

Ajv options object


JSON Schema

{
  type: 'object',
  properties: {
    name: {
      type: 'string'
    },
    age: {
      type: 'integer'
    }
  },
  order: ['name', 'age'],
  required: ['name', 'age']
}

Sample data

{ name: 'test', age: 10 }

Your code

ajv.addKeyword({
  keyword: 'order',
  type: 'object',
  schemaType: 'array',
});

Validation result, data AFTER validation, error messages


What results did you expect? I wanted to be able to use validateSchema to look at my object's properties to validate my keyword schema. Specifically to verify that the strings inside order keyword to be the properties in the object.

Are you going to resolve the issue? No, I can't

manuganji avatar Feb 22 '22 14:02 manuganji

By the way, I think you should enable discussions on this project or some way to asking a questions. Or there can be an Issue category where I can raise a problem with documentation. Because this is not strictly a bug but at the same time I don't know if it's a bug in the docs.

manuganji avatar Feb 22 '22 14:02 manuganji

I will create an issue template for docs questions

epoberezkin avatar Feb 24 '22 07:02 epoberezkin

I don’t hunk I understand the question, sorry. Please look at the implementations of keywords in ajv-keywords package - there may be some helpful examples

epoberezkin avatar Feb 24 '22 07:02 epoberezkin

validateSchema method you can see in the type is the result of metaSchema compilation - normally you won’t use it, so it’s not documented.

epoberezkin avatar Feb 24 '22 07:02 epoberezkin