Comments (3)
Hi,
I think the problem comes from here:
:interceptors (concat martian/default-interceptors ...
The default interceptors in martian.core
do not include the "implementation" interceptors that actually make the http request. These you will find in martian.clj-http/default-interceptors
, or any of the other implementation namespaces (not sure which you are using).
Note that your interceptors will run after the martian interceptors, which include setting and validating the headers schema, so if you set the header schema but only populate the extra data after that interceptor as run then you will get the error above.
Hope this helps
from martian.
Thanks, that's a huge help!
I'm using martian.clj-http
now and I reordered the interceptors. I thought that you were suggesting that I needed to reorder them so that it it will assoc the api key before the martian default interceptors run but it's still failing schema validation.
(defn my-service
[{:keys [base-url api-key http-timeout]
:or {http-timeout 30000}}]
(martian-http/bootstrap
base-url
[{:route-name :get-item
:produces ["application/json"]
:consumes ["application/json"]
:headers-schema {:x-api-key sch/Str}
:path-parts ["/api/" :id]
:path-schema {:id sch/Str}
:method :get}]
{:interceptors (concat [{:name ::add-api-key
:enter (fn [ctx]
(update-in ctx [:request :headers]
assoc :x-api-key api-key))}]
martian-http/default-interceptors)}))
(let [base-url "https://www.my-service.com"
api-key "mochi"]
(fake/with-fake-routes-in-isolation
{"https://www.my-service.com/api/123"
{:get (fn [req]
{:status 200
:body (cheshire.core/generate-string {:a "b"})})}}
(martian/response-for (my-service {:base-url base-url
:api-key api-key})
:get-item
{:id "123"})))
;; Could not coerce value to schema: {:x-api-key missing-required-key}
;; {:type :schema-tools.coerce/error,
;; :schema {:x-api-key java.lang.String},
;; :value {:id "123"},
;; :error {:x-api-key missing-required-key}}
I only added :headers-schema
because I thought that's why it wasn't working. I could just remove it but I'm interested to learn what I'm doing wrong.
Thanks so much for the help!
from martian.
Hi,
Yes I was suggesting you reorder them as you have done, I expected that to work. It's possible Martian's headers interceptor is not merging properly. It's interesting that the value it sees is the map with your id. This means of course that you could pass the API key in the arguments map to martian, but you probably don't want to arrange your prod code that way.
I'll try to find time to look into this.
from martian.
Related Issues (20)
- Bootstrapping relative url for a swagger api from cljs doesn't work
- Unable to use martian over spotinst API HOT 4
- Use clj-commons/clj-http-lite? HOT 5
- Unclear how to use query-params when bootstrapping without openapi/swagger HOT 6
- Is it possible to use a file:// url for the openapi deifinition? HOT 2
- Can't find a way to use $ref parameters HOT 3
- Throw an exception on status code >= 400 or :error HOT 2
- VCR playback should terminate if it has a response
- Invalid cookie header HOT 3
- Exception when generating no content response HOT 1
- No matching content-type available for `application-json` HOT 6
- Endpoint with content type of application/yaml does not seem to be supported HOT 1
- Adding custom encoder does not get chosen if there is a mix of reply contents that include at least one of the default encodings.
- Misled by using martian-test with martian-http/bootstrap HOT 2
- json/decode is called twice with clj-http if api operation.response.content is "*/*" HOT 2
- Ability to be used as a general parser HOT 3
- Patching schema after bootstrap HOT 4
- $ref is not working properly for swagger parameters HOT 1
- `wrap-default` in CLJS causes compiler warning HOT 1
- Applying interceptors to `bootstrap-openapi` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from martian.