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

Issue with s/or coercion in body-params spec #424

Open kjothen opened 5 years ago

kjothen commented 5 years ago

Library Version(s)

2.0.0-alpha30

Problem

Specs containing or fail on alternate cases - this was working in 2.0.0-alpha28. Of course, the swagger definition can only show one of the or alternatives only, but any request payload that conforms to the spec should (and did) work - could this behaviour be reverted back please?

eg. in the below, the definition of the linux-group would display in the swagger page, but body params containing the windows group would fail, eg {:group {:linux-id 1}} - succeeds, {:group {:windows-id "1"}} - fails.

(s/def ::linux-id int?)
(s/def ::linux-group (s/keys :req-un [::linux-id]))

(s/def ::windows-id string?)
(s/def ::windows-group (s/keys :req-un [::windows-id]))

(s/def ::group (s/or :group ::linux-group 
                               :group ::windows-group))

(api (swagger-routes (context "/group" [] :coercion :spec (resource {:post {:parameters {:body-params ::group}}}))))
miikka commented 4 years ago

This is caused by a bug in spec-tools: https://github.com/metosin/spec-tools/issues/178