Fork me on GitHub
#ring-swagger
<
2017-02-07
>
ikitommi16:02:44

@mrchance don't know any easy way, but it is doable. Needs custom transformations for docs, in & out. In & Out can be done with schema coercions, middleware or custom Muuntaja formatter. Docs can be transformed in a custom middleware before the swagger-routes. I would use fooBar all the way down if that's the requirement for swagger

mrchance16:02:02

@ikitommi thanks! Yeah, that's how I solved it, not an issue, just a minor aesthetic itch 😉

ikitommi16:02:41

well, we have foo_bar in one project 😑

daveliepmann16:02:00

I'm getting started with swaggerifying my routes, and I seem not to be able to find a particular use case in the docs. I'd like to define a schema (e.g. (s/defschema PageRequest [{:attributes :- [s/Str] ["uuid"]}])) for query parameters and then plug that into my GET's :query-params, but query-params seems to want names instead of keys (e.g. [{attributes :- [s/Str] ["uuid"]}]). Is there a conversion between these two schema representations that I'm missing?

ikitommi18:02:32

@daveliepmann there is :query and :query-params. If you have a request-schema predefined, try the :query.

ikitommi18:02:04

and your example-schema should be something like (s/defschema PageRequest {:attributes [s/Str]})). Sadly, there is no default-handling in the Schema core itself.

ikitommi18:02:42

the plumbing fnk has the notation of default, someone should integrate that in schema itself.

ikitommi18:02:58

actually, there is integration, but not integrated to c-api

ikitommi19:02:09

(require '[schema.core :as s])
(require '[schema-tools.core :as st])
(require '[schema-tools.coerce :as stc])

(s/defschema PageRequest
  {:attributes (st/default [s/Str] ["enum"])})

;; enforce the defaults
(stc/coerce {:attributes nil} PageRequest stc/default-coercion-matcher)
; {:attributes ["enum"]}

daveliepmann19:02:16

@ikitommi Many thanks, I'm implementing now. Note for future folks, the help namespace is new, so if you're on stable (1.1.10) it won't show up.