hyperjump-io / json-schema

JSON Schema Validation, Annotation, and Bundling. Supports Draft 04, 06, 07, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1
https://json-schema.hyperjump.io/
MIT License
216 stars 22 forks source link

`JsonSchema` `boolean` type #62

Closed silverwind closed 3 months ago

silverwind commented 3 months ago

Is there a reason why theJsonSchema type has a boolean in its union type? As far as I'm aware, booleans are not valid JSON schemas.

https://github.com/hyperjump-io/json-schema/blob/724e2434459ecedb089cd9e8e2b309802cc6b5fe/stable/index.d.ts#L5

jdesrosiers commented 3 months ago

A boolean is a valid JSON Schema since draft-06. You can use a boolean anywhere a schema is expected.

silverwind commented 3 months ago

Hmm, this union is presenting a few typescript related issues to me with "type boolean is not assignable to object" and I'm sure my schemas will never be booleans. Would you be willing to accept a PR that exports a subtype for the object? E.g.

export type JsonSchemaObject = {}
export type JsonSchema = boolean | JsonSchemaObject
silverwind commented 3 months ago

Found a way:


type JsonSchemaObject = Exclude<JsonSchema, boolean>;
jdesrosiers commented 3 months ago

That's a great solution.

silverwind commented 3 months ago

Yeah, but it's only a temporary solution of course. I will make my code work with boolean schemas.