Fork me on GitHub
#malli
<
2023-08-16
>
Joel03:08:50

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))))

steveb8n04:08:09

looks like mu/find-first has an opts arg where you should provide the registry. try that?

☝️ 2
Joel15:08:30

(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 kvto 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] {})

radhika07:08:33

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?

ikitommi08:08:03

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?

radhika08:08:27

sure, will do

radhika12:08:23

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"

ikitommi12:08:01

: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-aasi

🙌 2
radhika14:08:21

well, 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 🙂

ikitommi08:08:45

post-fixed the malli CHANGELOG for https://github.com/metosin/malli/blob/master/CHANGELOG.md#0103-2023-03-18. There was an unmarked BREAKINGchange with mu/strip-extra-keys-transformer stripping extra keys from :maps.

👍 4
🎉 4
🙏 2
markbastian22:08:30

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?

p-himik22:08:00

Maybe I'm reading it wrong, but why would the key be marked as required if it's already marked as optional?

markbastian22:08:51

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)?