Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More configurable coercion #267

Merged
merged 10 commits into from Jan 21, 2017
Merged

More configurable coercion #267

merged 10 commits into from Jan 21, 2017

Conversation

ikitommi
Copy link
Member

@ikitommi ikitommi commented Jan 8, 2017

replace implementation (not the contract) of default coercion. in compojure.api.middleware:

  • remove default-coercion-matchers
  • use create-coercion & default-coercion-options instead for more fine grained access, uses format information prodived by Muuntaja to get format-level coercion.
  • BREAKING new default coercion rules:
Format Request Response
application/json json-coercion-matcher validate
application/edn json-coercion-matcher validate
application/msgpack json-coercion-matcher validate
application/x-yaml json-coercion-matcher validate
application/transit+json validate validate
application/transit+msgpack validate validate

default options (updated):

(def default-coercion-options
  {:body {:default (constantly nil)
          :formats {"application/json" json-coercion-matcher
                    "application/msgpack" json-coercion-matcher
                    "application/x-yaml" json-coercion-matcher}}
   :string string-coercion-matcher
   :response {:default (constantly nil)
              :formats {}}})

to create a valid coercion (for api or to routes):

;; create (with defaults)
(mw/create-coercion)
(mw/create-coercion mw/default-coercion-options)

;; no response coercion
(mw/create-coercion (dissoc mw/default-coercion-options :response)

;; disable all coercion
nil
(mw/create-coercion nil)

Why? More correct behaviour for EDN & Transit, easy to add own custom rules based on formats.

See #266

@ikitommi
Copy link
Member Author

might be a reason to bump the version to 2.0 if this get's merged.

@ikitommi ikitommi merged commit c613028 into master Jan 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant