Skip to content

Types are always arrays, not compatible with some parsers #14

Open
@ngsilverman

Description

@ngsilverman

The README states that this:

(json-schema.infer/infer-strict
    {:title "ent-1"})
    {:things [{:quantity 1}]})

Will generate this:

{:$schema "http://json-schema.org/draft-07/schema#"
 :title "ent-1"
 :type :object
 :additionalProperties false
 :properties {"things" {:type :array
                        :items {:type :object
                                :additionalProperties false
                                :properties {"quantity" {:type :integer}}
                                :required ["quantity"]}}}
 :required ["things"]}

However, for me, using version 0.4.1, it generates this:

{:$schema "http://json-schema.org/draft-07/schema#",
 :title "ent-1",
 :type #{:object},
 :additionalProperties false,
 :properties {"things" {:type #{:array},
                        :items {:type #{:object},
                                :additionalProperties false,
                                :properties {"quantity" {:type #{:integer}}},
                                :required #{"quantity"}}}},
 :required #{"things"}}

Notably, the types are sets, which gets correctly converted to JSON lists, and which is technically a valid schema but can cause issues. For example the OpenAI API doesn't recognize that format, it expects a single type rather than an array of types.

If there is only one type I would suggest making it a single value rather than an array.

Thanks for this library! The infer function is awesome!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions