This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-16
Channels
- # announcements (25)
- # babashka (15)
- # beginners (14)
- # calva (60)
- # circleci (1)
- # clerk (1)
- # clj-kondo (13)
- # cljdoc (7)
- # clojure (45)
- # clojure-austin (1)
- # clojure-bay-area (1)
- # clojure-brasil (4)
- # clojure-dev (9)
- # clojure-europe (24)
- # clojure-norway (105)
- # clojure-uk (2)
- # clojurescript (6)
- # conjure (1)
- # core-typed (4)
- # cursive (4)
- # datalevin (1)
- # datomic (25)
- # emacs (31)
- # fulcro (3)
- # humbleui (10)
- # hyperfiddle (19)
- # jobs (2)
- # luminus (3)
- # malli (13)
- # nbb (5)
- # off-topic (16)
- # polylith (2)
- # portal (7)
- # releases (2)
- # shadow-cljs (5)
- # sql (8)
I’m able to tell if the map uses keywords:
(mu/find-first [:map
[:item-a string?]
[:misc [:vector string?]]]
(fn [schema _ _]
(some keyword? (-> schema mu/keys))))
But how do i do this if the map is part of a registry?
(mu/find-first{:something :string
:request-m
[:map
[:item-a :something]
[:misc [:vector string?]]]}
(fn [schema _ _]
(some keyword? (-> schema mu/keys))))
looks like mu/find-first has an opts arg where you should provide the registry. try that?
(def my-registry {:something :string
:request-m
[:map
[:item-a :something]
[:misc [:vector string?]]]})
(defn map-keywords? [schema opts]
(mu/find-first schema
(fn [schema _ _]
(some keyword? (-> schema mu/keys)))
opts))
(map-keywords? [:schema {:registry my-registry} :request-m] {})
I found that this works, using the options didn’t seem to help (how would it know which kv
to use?
However, I’m puzzled, if :request-m
is :request/m
or a qualified keyword ::request
then this does not work
(map-keywords? [:schema {:registry {:something :string
::request
[:map
[:item-a :something]
[:misc [:vector string?]]]}} ::request] {})
hey, I have been generating singular constant values from schemas using :gen/elements [x]
, which works, but feels less idiomatic than perhaps a hypothetical :gen/return x
(corresponding to clojure.test.check.generators/return
that I looked for initially). any reason :gen/return
isn't already provided for by malli.generate
?
no reason, goal has been to use same names & features as test-check. If/as it has return
, :gen/return
sounds good. Would you like to do a PR of this?
heh, I'm having trouble extending this test data map because I don't know the language:
{:korppu "koira"
:piilomaan "pikku aasi"
:muuli "mukkelis"}
any suggestions for the next couple of themed entries that I can add to test gen/return
?
I think I need the same shape as the first two entries, like:
:key1 "word"
:key2 "word word"
:rolling_on_the_floor_laughing: here’s some extras:
:pikimusta "kissa"
:aasi "isaskari"
source: https://yle.fi/aihe/artikkeli/2012/09/18/elakoon-piilomaan-pikku-aasiwell, I raised an issue https://github.com/metosin/malli/pull/932 and took a pass at it with PR https://github.com/metosin/malli/pull/933 (and some variation of fictional character names 😅) feedback welcome, my first time venturing into changing malli sources 🙂
post-fixed the malli CHANGELOG for https://github.com/metosin/malli/blob/master/CHANGELOG.md#0103-2023-03-18. There was an unmarked BREAKING
change with mu/strip-extra-keys-transformer
stripping extra keys from :map
s.
I’m using malli to generate some swagger docs and have a field marked as optional (here’s the subset of the schema):
[:map
[:qp_column_name {:optional true} [:maybe :string]]]
This is in a map that is a key in the parent calling map (i.e. it isn’t a top level key). When I generate my swagger.json file, I get this fragment:
"description": {
"type": "string",
"x-nullable": true
},
It does not contain the "required": *true*
attribute. Is there a way to set this?Maybe I'm reading it wrong, but why would the key be marked as required if it's already marked as optional?
Ah, I mistyped. Should have said false. it seems that the “parameters” key has required true or false for all entries. My body param looks like this:
{
"in": "body",
"name": "body",
"description": "",
"required": true,
"schema": {
The schema key itself seems to not have any required keys at all. Is there a way to set required on those keys (either true or false)?