ostrowr / ts-json-validator

Let JSON play nicely with Typescript
MIT License
342 stars 7 forks source link

Error when making validation schema with array item validation #37

Closed funkel1989 closed 4 years ago

funkel1989 commented 4 years ago

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?

ostrowr commented 4 years ago

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

funkel1989 commented 4 years ago

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.