Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malli generates circular json-schema #868

Closed
opqdonut opened this issue Mar 13, 2023 · 4 comments
Closed

Malli generates circular json-schema #868

opqdonut opened this issue Mar 13, 2023 · 4 comments

Comments

@opqdonut
Copy link
Member

... at least for mu/closed schemas

(require '[malli.util :as mu])
(require 'malli.json-schema)
(malli.json-schema/transform (mu/closed-schema [:schema {:registry {"Foo" :int}} "Foo"]))
 ==> {:$ref "#/definitions/Foo", :definitions {"Foo" {:$ref "#/definitions/Foo"}}}  ;; wrong, circular schema
(malli.json-schema/transform [:schema {:registry {"Foo" :int}} "Foo"])
 ==> {:$ref "#/definitions/Foo", :definitions {"Foo" {:type "integer"}}} ;; right

#863 seems to fix this.

@cap10morgan
Copy link
Contributor

@opqdonut Should this be closed now too since #863 was merged?

@opqdonut
Copy link
Member Author

I'll do some more testing and see if I can find any other corner cases.

@opqdonut
Copy link
Member Author

Mutual recursion still doesn't work:

user=> (malli.json-schema/transform [:schema {:registry {"Foo" [:vector [:ref "Bar"]] "Bar" [:ref "Foo"]}} "Foo"])
{:$ref "#/definitions/Foo", :definitions {"Foo" {:type "array", :items {:$ref "#/definitions/Bar"}}}}

@ikitommi
Copy link
Member

Fixed in master:

(malli.json-schema/transform [:schema {:registry {"Foo" [:vector [:ref "Bar"]] "Bar" [:ref "Foo"]}} "Foo"])
;{:$ref "#/definitions/Foo",
; :definitions {"Foo" {:type "array", :items {:$ref "#/definitions/Bar"}}
;               "Bar" {:$ref "#/definitions/Foo"}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants