ostrowr/ts-json-validator

Error when making validation schema with array item validation

funkel1989 opened this issue · 2 comments

  • Before submitting a bug report, double-check that your Typescript version is at least 3.7.

Describe the bug
I was under the impression that that json you build for the validator was based off of AJV but i can't seem to get arrays to work the way i expect them to.

To Reproduce

const parser = new TsjsonParser(
  S({
    type: 'object',
    properties: {
      Id: S({ type: 'string' }),
      Type: S({ type: 'string', enum: ['email'] as const }),
      Message: S({ type: 'string' }),
      links: S({ type: 'array', items: [{ type: 'string' }]}),
    }
  })
);

Expected behavior
Expect the above code to be correct (assuming i'm doing everything correctly)
Actual behavior
Type '{ type: string; }' is not assignable to type 'SchemaLike'.
Object literal may only specify known properties, and 'type' does not exist in type 'Schema
Additional context
Am i just doing something wrong here or is there a bug?

@funkel1989 I see you closed this; did you manage to get it working?

Yes, I had a syntax error that I missed due to all of the ( and { and [ and [S({ lol. Your package is great but brackets are everywhere.
I do have another problem and once I determine its not my fault this time I'll post it. Potentially just a how-to as I can't seem to get patternProperties to work for validation with dynamic keys.