metosin / metosin/compojure-api

spec coercion to int

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

Nobody has claimed this yet.

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

Description

## Library Version(s)
2.0.0-alpha31

## Problem

```clojure
(s/def ::version (s/and int? #{1 2}))

(GET "/test/:v" request
:path-params [v :- ::version]
(r/ok v))
```
when requesting `GET /test/1` results in
```clojure
{:problems
[{:message "Validation error",
:details
{:path ["v"],
:pred [1 2],
:val "1",
:via ["spec$60151/v"],
:in ["v"],
:phrase.alpha/mappings {:x0 1, :x1 2, :x2 ["x1" "x0"]},
:phrase.alpha/via []}}]}
```
However
```clojure
(s/def ::version #{1 2})

(GET "/test/:v" request
:path-params [v :- (s/and int? ::version)]
(r/ok v))
```
when requesting `GET /test/1` does give me the expected response body of `1`.

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

No repository file, test, or entry point is named. Reproduce the two GET /test/:v examples with the shown specs and compare their path-parameter handling; done means the int? combined with #{1 2} case handles the request consistently with the working example.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.