Fork me on GitHub
#reitit
<
2021-03-04
>
Cristian Saucedo01:03:42

Hello all does anyone have any idea where I should be passing the collection-format : "csv" option in order to parse query parameters values in a comma separated list? Looking through the source code, it looks like in schema-tools.swagger.core on line 51, the default option is multi, but I can't seem to find the right spot to overide that default. The default behavior on reitit swagger is to send multiple values of the same query parameters as duplicate query parameters, i.e ?id=1&id=2 . I'd like to support the structure ?id=1,2

juhoteperi10:03:29

Hmm, in Compojure-api/Ring-swagger this was using describe/field function, but it is a bit different here.

juhoteperi10:03:21

Aha yes. schema-tools.core/schema allows attaching additional data to a schema. (st/schema [s/Str] {:swagger/collection-format "csv"})

đź‘Ź 3
juhoteperi10:03:54

Doesn't seem to be documented. Impl is here: https://github.com/metosin/schema-tools/blob/master/src/schema_tools/swagger/core.cljc#L160-L164 Keys with :swagger ns from the additional data are merged to the properties swagger spec.

Matheus Moreira09:03:26

Hello! I am using muuntaja with reitit for response formatting (`format-response-middleware`) and I’d like to know if there is a way to configure the underlying object mapper to not write json properties with null value. Jackson’s object mapper supports it and I saw that jsonista uses Jackson’s OM, but I didn’t find a way to set this option (i.e. ObjectMapper.disable(SerializationFeature/WRITE_NULL_MAP_VALUES).

juhoteperi10:03:50

Jsonista doesn't support this option directly, but you can use :mapper (or :factory) options to provide custom base ObjectMapper. (json/object-mapper {:mapper (doto (ObjectMapper.) (.disable ...))})

dharrigan09:03:05

I do something a bit different (not saying it's better, just that I approached this from a different angle). I use specter to strip out any nil's from my maps before I send them out

dharrigan09:03:37

(:require
   [com.rpl.specter :refer [declarepath providepath if-path compact setval MAP-VALS NONE STAY]]))

(set! *warn-on-reflection* true)

(declare DEEP-MAP-VALS)
(declarepath DEEP-MAP-VALS)
(providepath DEEP-MAP-VALS (if-path map? [(compact MAP-VALS) DEEP-MAP-VALS] STAY))

(defn clean
  [data]
  (setval [DEEP-MAP-VALS nil?] NONE data))

dharrigan09:03:56

So I would call (clean my-data-structure) just before passing it back out

dharrigan10:03:39

@matheus.emm if you're interested, I've put together a working example here: https://github.com/dharrigan/strip-nils

dharrigan10:03:56

This provides serialisation features to Jackson, to strip out the nils, with examples