oliyh / martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more
MIT License
529 stars 44 forks source link

Keys not mentioned in body schema are "unaliased" #109

Closed chopptimus closed 3 years ago

chopptimus commented 3 years ago

If I have a body schema that looks like this

{:PetMetadata s/Any
 :Name s/Str
 :Age s/Int}

and the value of :PetMetadata happens to include the keys :age or :name, those keys will be "unaliased". For instance:

(def martian (m/bootstrap "https://thepetshopboys.co.uk"
                          [{:route-name :add-pet
                            :method :get
                            :path-parts ["/add-pet"]
                            :body-schema {:payload
                                          {:PetMetadata s/Any
                                           :Name s/Str
                                           :Age s/Int}}}]))

(m/request-for martian :add-pet {:PetMetadata {:age 3}
                                 :Age 3
                                 :Name "Roger Rabbit"})

=> {:method :get,
    :url "https://thepetshopboys.co.uk/add-pet",
    :body {:PetMetadata {:Age 3}, :Name "Roger Rabbit", :Age 3}}