This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # bangalore-clj (2)
- # beginners (37)
- # boot (16)
- # cider (17)
- # clara (4)
- # cljs-dev (351)
- # cljsrn (16)
- # clojure (219)
- # clojure-belgium (4)
- # clojure-dev (3)
- # clojure-france (2)
- # clojure-italy (24)
- # clojure-russia (23)
- # clojure-spec (55)
- # clojure-switzerland (3)
- # clojure-uk (89)
- # clojurescript (121)
- # cursive (2)
- # datomic (29)
- # devops (2)
- # graphql (8)
- # hoplon (15)
- # immutant (5)
- # lein-figwheel (4)
- # liberator (3)
- # luminus (18)
- # off-topic (9)
- # om (6)
- # onyx (31)
- # pedestal (48)
- # precept (9)
- # re-frame (19)
- # reagent (63)
- # ring-swagger (69)
- # robots (1)
- # slack-help (14)
- # spacemacs (12)
- # sql (2)
- # test-check (4)
- # unrepl (28)
- # untangled (5)
- # yada (3)
@lambder hi, that should work. Just added a test with
string?, please check the test at https://github.com/metosin/compojure-api/blob/master/test19/compojure/api/coercion/spec_coercion_test.clj
Muuntaja does exact matches on the content-type, you can map
text/json to be JSON or you can do regex-matches for content-type. There is a configuration guide in https://github.com/metosin/muuntaja/wiki/Configuration
@ikitommi thanks your your answer. I was struggling with it for some time and finally got it.
@eoliphant Swagger routes are defined as map, so only one POST route can exist for an route - compojure-api only uses first match for the docs.
resource (and all other endpoint-types) are just ring-handlers, if they return
nil, the routing continues to search for next route match.
@eoliphant you can add manually swagger definitions to the first route to cover rest of the routes, with
:swagger. Not sure if that’s a good idea, but can be done.
Is there any way to document and return a different object (including schema definition) based on the resource URI and the Accept header value? I'd like to return a differently structured object depending on if it was application/json or application/vnd.api+json (JSON API) response. Based on the swagger 2.0 documentation this would appear to be impossible.
Also can someone provide an example where only json-kw and edn are allowed and show up in the swagger documentation for content type support? I tried to feed the 'api' call a list of just :formats [:json-kw :end] but that didn't work out. I am attempting to use compojure.api.sweet to do this. Hopefully someone here knows the answer or can help me figure it out.
@tmclane aside, do you have a library you’re using for JSON API serialization? I’ve been looking for something to use instead of rolling my own.
@barry Currently I am using compojure.api which includes mitosis/muuntaja which is automatically serializing the objects. I dislike that I can't tell it what the 'content-type' is however since it always says it is application/json which is true but it's also application/vnd.api+json which is more specific.
I am contemplating removing the extra code and just using Ring / http-kit directly and processing the headers myself. This can be done in a wrapper and have it do the same thing the compojure-api library does.
Does muuntaja support JSON API (vnd.api+json) serialization? It seems like it’s just ‘raw’ JSON out of the box.
@barry JSONAPI is merely JSON after all.. so yes it works although it will put the wrong content-type header on the response.
I'm working on figuring out how to override this and I am making a small bit of progress.
haha, yes, just JSON, but hand-crafting spec-compliant JSON-API isn’t trivial, e.g. for includes, relationships, etc.
correct — I may be hunting for something from fairy-tale land. JSON-API seems somewhat tied to relational database mindset, and many of the libraries tie themselves to an ORM
i’m trying to find a way to create some of the includes/relationship serialization bits automatically
ha. yes. Too bad I'm not getting paid for this. It's a hobby project I am working on that has me trying to figure out what and how to get this helper layer to help me. Instead it seems to be making it harder.
@barry Got it to return whichever 'Content-Type' was requested using that format. This is with 2.0.0-alpha4.