metosin / compojure-api

Sweet web apis with Compojure & Swagger
http://metosin.github.io/compojure-api/doc/
Eclipse Public License 1.0
1.11k stars 149 forks source link

Inconsistency with allowed :responses route parameter values between Schema and spec coercion #413

Closed salokristian closed 4 years ago

salokristian commented 5 years ago

Library Version(s)

2.0.0-alpha28

Problem

When giving an invalid value for the :responses route parameter, the code compiles and runs without exceptions if default Schema coercion is used. However, when :coercion :spec is applied to an endpoint with an invalid :responsesparameter, a compilation error is thrown.

An example of an invalid :responses param with default coercion, working fine:

(api/GET "/" []
  :coercion :schema
  :responses {200 {}}
  (str "works fine"))

An example of an invalid :responses param with spec coercion, resulting in a compilation error.

(api/GET "/" []
   :coercion :spec
   :responses {200 {}}
   (str "doesn't compile"))

The error thrown is:

Syntax error (IllegalArgumentException) compiling at (core.clj:12:3).
No implementation of method: :specify of protocol: #'compojure.api.coercion.spec/Specify found for class: nil

I'm not sure if an error should be thrown anytime when a value like {200 {}} for :responses is given, or if this should be considered valid. In any case, it is inconsistent that changing the coercion setting causes an error which is unrelated to coercion to be thrown.