ring-swagger

Tuomas-Matti Soikkeli 2024-12-02T12:22:06.448839Z

How can I configure swagger to send multiple enum string values in vector? Swagger is sending those as comma separated values. Curling with multiple params like ?fields=properties&fields=location ends up into array and works fine. See thread for code.

Tuomas-Matti Soikkeli 2024-12-02T12:22:33.013539Z

error from s/explain

Tuomas-Matti Soikkeli 2024-12-02T12:22:59.428549Z

schema

;; TODO: doesn't work from swagger, sending as comma separated values
(def legacy-fields #{"properties"
                     "schoolUse"
                     "email"
                     "type.name"
                     "reservationsLink"
                     "location.sportsPlaces"
                     "renovationYears"
                     "admin"
                     "location.coordinates.tm35fin"
                     "www"
                     "location.geometries"
                     "name"
                     "type.typeCode"
                     "location.locationId"
                     "constructionYear"
                     "freeUse"
                     "location.city.name"
                     "lastModified"
                     "marketingName"
                     "location.postalCode"
                     "location.postalOffice"
                     "location.city.cityCode"
                     "phoneNumber"
                     "location.neighborhood"
                     "owner"
                     "location.coordinates.wgs84"
                     "location.address"})

(s/def :lipas.legacy.api/field
  (st/spec {:spec legacy-fields
            :swagger/type "enum"
            :swagger/enum legacy-fields}))

  (s/def :lipas.legacy.api/fields
    (s/coll-of :lipas.legacy.api/field
               :distinct true
               :min-count 1
               :max-count (count legacy-fields)
               :into []))

(s/explain :lipas.legacy.api/fields "properties,name")
; "properties,name" - failed: coll? spec: :lipas.legacy.api/fields

Tuomas-Matti Soikkeli 2024-12-02T12:23:49.741829Z

From swagger ui the fields looks perfect.

Tuomas-Matti Soikkeli 2024-12-02T18:45:57.029859Z

Looks like I need to configure collectionFormat, where it should be declared? source: https://swagger.io/docs/specification/v2_0/describing-parameters/#array-and-multi-value-parameters

valtteri 2024-12-02T19:12:18.846299Z

There seems to be :collection-format option here https://github.com/metosin/ring-swagger?tab=readme-ov-file#customizing-swagger-spec-output

Tuomas-Matti Soikkeli 2024-12-02T19:20:49.786729Z

Thanks!

Tuomas-Matti Soikkeli 2024-12-03T11:04:11.308469Z

Found the root cause: https://github.com/metosin/reitit/issues/298

ikitommi 2024-12-02T14:44:15.536709Z

should there be malli-coercion for compojure-api?