Iām probably being dense here, but please bear with me.
My question:
I have created an API, by importing the following Swagger/OpenAPI 2.0 file:
https://raw.githubusercontent.com/tmforum-apis/TMF641_ServiceOrder/master/TMF641-ServiceOrdering-v4.1.0.swagger.json
It imported just fine: I allowed it to import as both collection + API.
However, when I create a client request in the Collection, the request is not validated against the Swagger schema (e.g. I can add nonsense top-level fields, or wrong data types for fields, and they are happily sent out).
Equally, if I create a Mock endpoint, the received request is not validated either. It just tells me it canāt find any matching mock. Of course, I can create matching mocks for specific valid requests, but I would like requests which are not valid according to the schema to be rejected.
Am I missing something obvious here? It seems to be a simple enough requirement, that if Iāve loaded an OpenAPI schema, that Postman can tell me whether the request Iāve prepared in the client collection is valid or not.
Iāve already tried:
I did find a blog post about validating responses, using the āTestsā feature. It suggested I added the following under the API āTestsā tab:
pm.test("Validate schema", () => {
pm.response.to.have.jsonSchema(schema);
});
But as far as I can see from the manual, tests are only run after the response has been received.
So instead, I tried creating a pre-request script:
pm.request.to.have.jsonSchema(schema);
This tells me that āschemaā is not defined. So I added above this:
var schema={
"swagger": "2.0",
"info": {
"title": "API ServiceOrdering",
...snip entire large swagger doc...
};
This runs, but the (invalid) request is still happily sent out. I changed it to:
console.log("XXX:" + pm.request.to.have.jsonSchema(schema));
and I get XXX:[object Object]
in the console.
If I change it to
console.log("XXX:" + pm.request.to.have.jsonSchema(schema).keys().join());
then I get āAssertionError: keys requiredā. As this point, I suspect I donāt know enough about the syntax of this āfluentā testing API.
Itās also quite likely that Iām misunderstanding the difference between JSON schema and Swagger/OpenAPI.
If this is a FAQ, or in the documentation please do point me at it - but Iāve done quite a lot of searching already and couldnāt find anything. Thereās plenty of documentation about how to validate the Swagger API document itself, as opposed to validating requests and responses against the Swagger API doc. But I donāt need to validate the Swagger API doc: this is already provided to me in its final state and I wonāt be changing it.
Many thanks for taking the time to read this!