Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

JsonSchema type should allow arrays and not only object #274

Open
rickydidaravong opened this issue Jul 18, 2019 · 4 comments
Open

JsonSchema type should allow arrays and not only object #274

rickydidaravong opened this issue Jul 18, 2019 · 4 comments

Comments

@rickydidaravong
Copy link

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.

@dtranVAMP
Copy link

dtranVAMP commented Aug 12, 2019

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

@nhc
Copy link

nhc commented Jan 28, 2021

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.

@Nefariis
Copy link

Nefariis commented Feb 5, 2021

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

@tstackhouse
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants