Reputation: 834
I want to validate the JSON schema against the response. For that, I set it as a global variable in Postman through UI. And it works perfectly fine.
Is there a way it could be set using pre-request script?
I tried defining the schema with quotes(string) and without quotes(object), but doesn't seem to work:
const schema =
"{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Core schema meta-schema",
"definitions": {},
"type": [
"object"
],
"title": "The Root Schema",
so on...
}"
pm.globals.set("globalSchema", schema);
Any help would be appreciated!
Upvotes: 1
Views: 1844
Reputation: 25901
This should be what you need to capture the schema
object:
pm.globals.set("globalSchema", JSON.stringify(schema))
You could then use this to reference that value elsewhere:
JSON.parse(pm.globals.get('globalSchema'))
Upvotes: 4