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

Missing-key / disallowed key on path-params when setting defaults in query-schema #215

Open
licht1stein opened this issue Jan 5, 2025 · 2 comments

Comments

@licht1stein
Copy link

Here's my example:

 (def m (martian/bootstrap
          "http://example.com"
          [{:query-schema {:version (st/default s/Int 70)},
            :path-schema {:id s/Str}
            :route-name :test/route
            :method :get,
            :path-parts ["/part/" :id]}]
          {:use-defaults? true}))

  (martian/request-for m :test/route {:id "honestly-i-am-a-string"})
  ;; Value cannot be coerced to match schema: {:id disallowed-key}

  (martian/request-for m :test/route {})
  ;; Could not coerce value to schema: {:id missing-required-key}

I tried working from the readme test example, and figured out that adding a :query-schema map breaks it:

(let [m (martian/bootstrap "https://api.org"
                   [{:route-name :load-pet
                     :path-parts ["/pets/" :id]
                     :query-schema {:version (st/default s/Int 70)}
                     :method :get
                     :path-schema {:id s/Str}}]
                   {:use-defaults? true})]
    (martian/request-for m :load-pet {:id "1"}))
;; Value cannot be coerced to match schema: {:id disallowed-key}
@licht1stein
Copy link
Author

Moreover, when removing the defaults part everything works:

(let [ m (martian/bootstrap
         "http://example.com"
         [{:query-schema {:version s/Int},
           :path-schema {:id s/Any}
           :route-name :test/route
           :method :get,
           :path-parts ["/part/" :id]}]
         )]

    (martian/request-for m :test/route {:id "honestly-i-am-a-string" :version 1}))
;; => {:method :get, :url "http://example.com/part/honestly-i-am-a-string", :query-params {:version 1}}

@licht1stein licht1stein changed the title Missing-key / disallowed key on path-params when setting query params Missing-key / disallowed key on path-params when setting defaults in query-schema Jan 5, 2025
@oliyh
Copy link
Owner

oliyh commented Jan 5, 2025

Hi,

Thanks for the explanation and example. This is very odd, I can't explain this behaviour. I will have a look into this when I have a chance.

Cheers

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

No branches or pull requests

2 participants