metosin / metosin/compojure-api

Issue with s/or coercion in body-params spec

Open
#424 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

upstream-problem
Dominant language
Clojure
Stars
1.1k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

## 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}}}))))
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the alternate body-params cases in the issue through `swagger-routes`, `context`, `resource`, and `:coercion :spec`. Trace how `s/or` is handled for the `::group` body parameter and identify the existing coercion tests or entry point covering spec alternatives. Done means both the Linux and Windows payloads are accepted while Swagger still exposes one alternative.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.