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

Body params should be taken from supplied values and should not be named #5

Closed
oliyh opened this issue Jun 14, 2016 · 5 comments
Closed

Comments

@oliyh
Copy link
Owner

oliyh commented Jun 14, 2016

Currently martian attempts to give the body params a name and expects values in a submap under that name, e.g. (request-for m {:pet {:name "charlie" :age 2}}) where :pet is derived from the schema.

It should not do this; it is not robust and does not fit with the aim of abstracting HTTP structure from the function call. Instead, it should allow this: (request-for m {:name "charlie" :age 2}).

@oliyh oliyh closed this as completed in 481a43d Jun 14, 2016
@markdingram
Copy link
Contributor

Hi @oliyh, either I'm missing something (which is entirely possible!), but wrapping the body params still seems to be required when loading from a http swagger JSON,

Referring back to:
https://juxt.pro/blog/posts/martian.html

(-> (martian-http/bootstrap-swagger "https://pedestal-api.herokuapp.com/swagger.json")
    (martian/request-for :create-pet {:name "Doggy McDogFace" :type "Dog" :age 3}))

Gives:

ExceptionInfo Value cannot be coerced to match schema: {:pet missing-required-key}  schema.coerce/eval7131/coercer!--7136/fn--7137/fn--7138 (coerce.clj:52)```

Wrapping with the schema pet works:

(martian/request-for :create-pet {:pet {:name "Doggy McDogFace" :type "Dog" :age 3}}))

(running in a REPL from current master a6c9cc7)

I can see the test case still passes, so is there a subtle difference between data driven & http derived martian?

Thanks!

@oliyh
Copy link
Owner Author

oliyh commented Dec 8, 2016 via email

@markdingram
Copy link
Contributor

Ahh thanks.

The underlying reason I was looking here was that in my compojure-api derived swagger there are some anonymous body schemas that end up being named some random variant of Body12345, Body45245 etc.

Like you mention it is no problem to pull out the name from Martian e.g.:

(-> (martian/explore m :create-pet) (:parameters) (first) (key))

...but feels a little clunky.

I wonder if a :martian.core/body key could be added that always resolves to the body schema? If you like the approach or suggest something better I can do the PR.

(martian/request-for :create-pet {::martian/body {:name "Doggy McDogFace" :type "Dog" :age 3}}))

@oliyh
Copy link
Owner Author

oliyh commented Dec 8, 2016 via email

@markdingram
Copy link
Contributor

I created a PR #30 with the option where the namespaced keyword takes precedence, falling back to the named schema otherwise. This seems to be a nice simple path forward?

I am using a pretty recent compojure-api 1.1.8, which pulls ring-swagger 0.22.10 - these include any changes made by the issue you mentioned above.

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