schema-tools icon indicating copy to clipboard operation
schema-tools copied to clipboard

JsonSchema type should allow arrays and not only object

Open rickydidaravong opened this issue 5 years ago • 4 comments

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.

rickydidaravong avatar Jul 18 '19 23:07 rickydidaravong

@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?

dtranVAMP avatar Aug 12 '19 17:08 dtranVAMP

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.

nhc avatar Jan 28 '21 00:01 nhc

I would love it - I have multiple responses that are an array of objects

Nefariis avatar Feb 05 '21 19:02 Nefariis

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.

tstackhouse avatar Mar 23 '21 15:03 tstackhouse