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

prevent error caused by trying to confrom value that has already been… #436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

prevent error caused by trying to confrom value that has already been… #436

wants to merge 1 commit into from

Conversation

antonmos
Copy link
Contributor

@antonmos antonmos commented Feb 11, 2020

… coerced

in my situation, i am using a spec like this to transform the parameter:

(def get-events-spec
  (st/spec
    {:spec (s/coll-of string?)
     :description "comma separated list of user-ids"
     :json-schema/type {:type "string"}
     :json-schema/example "1,2,3"
     :decode/string #(cs/split %2 #",")
     :encode/string #(cs/join %2 ",")}))

referenced like this

(GET "/events" []
      :coercion :spec
      :query-params [user-ids :- get-events-spec,
                                  max-age :- ::corespec/max-age ]
...
)

When invoked with GET /events?user-ids=1 (i.e. with missing max-age param), I get a class cast exception thrown from cs/split.
This happens because the old code was calling conform on result of st/coerce, which means that the string has already been coerced into a vector of strings.

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.

1 participant