-
Notifications
You must be signed in to change notification settings - Fork 215
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
Support Var-refs #985
Support Var-refs #985
Conversation
My 2c:
The part I'm most interested in wrt this MR is how var references interact with JSON schema and its derivatives:
|
What would this this mean in terms of code? If it means running |
yes, now with tests. moved all references to strings to ensure they get encoded correctly. (def UserId :string)
(def User
[:map {:registry {::location [:tuple :double :double]
`description :string}}
[:id #'UserId]
::location
`description
[:friends {:optional true} [:set [:ref #'User]]]])
(json-schema/transform User)
;{:type "object",
; :properties {:id {:$ref "#/definitions/malli.json-schema-test~1UserId"},
; :malli.json-schema-test/location {:$ref "#/definitions/malli.json-schema-test~1location"},
; malli.json-schema-test/description {:$ref "#/definitions/malli.json-schema-test~1description"},
; :friends {:type "array", :items {:$ref "#/definitions/malli.json-schema-test~1User"}, :uniqueItems true}},
; :required [:id :malli.json-schema-test/location malli.json-schema-test/description],
; :definitions {"malli.json-schema-test/UserId" {:type "string"},
; "malli.json-schema-test/location" {:type "array",
; :items [{:type "number"} {:type "number"}],
; :additionalItems false},
; "malli.json-schema-test/description" {:type "string"},
; "malli.json-schema-test/User" {:type "object",
; :properties {:id {:$ref "#/definitions/malli.json-schema-test~1UserId"},
; :malli.json-schema-test/location {:$ref "#/definitions/malli.json-schema-test~1location"},
; malli.json-schema-test/description {:$ref "#/definitions/malli.json-schema-test~1description"},
; :friends {:type "array",
; :items {:$ref "#/definitions/malli.json-schema-test~1User"},
; :uniqueItems true}},
; :required [:id
; :malli.json-schema-test/location
; malli.json-schema-test/description]}}}
yes.
yes. qualified keywords, symbols and Vars are all global in Clojure, so they can and should be global in JSON Schema too. |
In that case, I think we'll need properties support to override the namespace qualification, and some "global" property to add a mapping of qualifying namespace to other names when transforming the schema, with some means of conveying it to reitit |
@bsless so, you would not like to expose the namespaces? just for Vars or also for qualified keywords and symbols? |
Exactly. It's an implementation detail and can just add noise and confusion. Why would the consumer care that my schema is a
With qualified idents you can already give them whatever namespace prefix you like (and some argue you shouldn't use a |
@bsless extracted the requirement to mask Var namespaces in JSON Schema / Swagger into separate ns - #988 @ilmoraunio - didn't push the VarRegistry into defaults. Will sleep over this. |
Open Questions
m/-reference?
) and document them in pretty printing ✅ it's ok to removeSample
Invalid ref error