Closed ikitommi closed 5 months ago
My 2c:
The part I'm most interested in wrt this MR is how var references interact with JSON schema and its derivatives:
should var-registry be enabled by default?
What would this this mean in terms of code?
If it means running mr/set-default-registry!
implicitly using a composite-var-registry, then there also needs to be a way to disable it easily. Also, this would likely constitute a bigger jump in terms of versioning semantics. But I'm carefully for it.
@bsless
The part I'm most interested in wrt this MR is how var references interact with JSON schema and its derivatives:
Do they get lifted to definitions?
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]}}}
Do they get qualified?
yes.
Should they?
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?
so, you would not like to expose the namespaces?
Exactly. It's an implementation detail and can just add noise and confusion. Why would the consumer care that my schema is a com.foo.my-service.blash.schema/User
? The benefit is it maps directly to the place where the schema is defined. Since it has pros and cons for each option, it makes sense to make it configurable and leave it up to users.
just for Vars or also for qualified keywords and symbols?
With qualified idents you can already give them whatever namespace prefix you like (and some argue you shouldn't use a ::foo
anyway), so it's less of an issue.
also, added report for the invalid function reg:
@bsless extracted the requirement to mask Var namespaces in JSON Schema / Swagger into separate ns - https://github.com/metosin/malli/issues/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