schema-tools
schema-tools copied to clipboard
JsonSchema type should allow arrays and not only object
File: objects.ts
Issue: JsonSchema currently only allows just 'object' as a type, but if a json response returns an array of objects. The only type that can be validated is just 'object' therefore the type would return an error for the wrong type.
@bahmutov please advise
We forked and made this change to the object.ts:
export type JsonSchema = { title: string type: JsonPropertyTypes description?: string properties?: JsonProperties items?: JsonProperty patternProperties?: object // which properties are MUST have required?: string[] | true // does the schema allow unknown properties? additionalProperties: boolean deprecated?: string }
Would this be a optimal approach in your opinion?
I know this is stale, but I'm having exactly the same issue.
The JsonSchema.type
should not be limited to object. I need the solution that @dtranVAMP is suggesting. I can issue a PR if that helps, but I don't want to waste my time if no one is looking at this.
I would love it - I have multiple responses that are an array of objects
We've worked around this on my team by asserting that the response is an array and then using the schema in a loop to check the contents of the array.