Fork me on GitHub
#ring-swagger
<
2016-02-12
>
jstokes20:02:01

can anyone give advice on how i might use pjson over cheshire for json parsing in a compojure-api app?

jstokes20:02:09

noticing our app is spending a lot of time in json parsing

juhoteperi20:02:48

@jstokes: Might be possible by disabling built-in json support (`[:format :formats]`) and adding your own middleware

juhoteperi20:02:09

But setting :formats option will also affect swagger docs

juhoteperi20:02:34

Maybe you can just use your own middleware without any settings, ring-middleware-format is probably no-op if the request body has already been parsed

jstokes20:02:02

and custom middleware is applied before ring-middleware-format?

juhoteperi20:02:03

Compojure-api just embeds ring-middleware-format with some specific options

juhoteperi20:02:49

@jstokes: Yes. If you do something like (pre 1.0 example): (defapi app' ...) (def app (-> app' wrap-own-mw))

juhoteperi20:02:17

own-mw will be applied before calling api handler

jstokes20:02:37

ill give it a shot, thanks @juhoteperi

piotrek20:02:20

I have a question around ring-middleware-format

piotrek20:02:03

I need to have json rq/rs with properties names in camelCaseFormat but would like to work in my system with maps with :kebab-style-keys

juhoteperi20:02:54

Hmm, I think r-m-f should allow options to cheshire

piotrek20:02:17

I tried to use {:format {:params-opts {:json {:key-fn ->kebab-case-keyword}}}

piotrek20:02:17

but then the problem is that my schema says for example user-id (this is actually my internal format) while the json format should be userId

juhoteperi20:02:25

Hmm the default json format might be :json-kw instead of :json

piotrek20:02:21

let me check :json-kw

juhoteperi20:02:59

I don't think there is a solution for having correct docs in this case currently

piotrek20:02:55

@juhoteperi: :json-kw worked - thanks

piotrek20:02:24

but discrepancy between schema and actual json format is still there

piotrek20:02:35

any ideas if it can be fixed easily?

juhoteperi20:02:43

Not sure how it could be fixed as different formats could have different names. It would require support from JSON Schema/Swagger

juhoteperi20:02:13

One possibility would be to force same key format for all formats

piotrek20:02:50

I see, I guess I have to stick to camelCase keys in my code for now 😕