AJV Schema Validation

Apparently the properties property is required and is expected to be on the outmost section of the schema body.

If you want to validate the query string of a request, it does not work do to:

export const mySchema = {
  $id: 'path/to/schema/file/mySchema.json',
  query: {
	properties: {
		url: {
          type: 'string',
          pattern: 'https?://.*',
	    },
	},
  },
  required: ['url'],
};
mySchema.ts

Instead, it has to be:

export const mySchema = {
  $id: 'path/to/schema/file/mySchema.json',
  properties: {
    url: {
      type: 'string',
      pattern: 'https?://.*',
    },
  },
  required: ['url'],
};
mySchema.ts

I don't think this was clear in the documents, but seems like an important detail to keep in mind.

Also, the pattern, which is a regex, must be surrounded by quotes 🤷‍♀️

Show Comments