I can't validate response with jsonSchema for anyOf objects in postman

Viewed 177

I want to validate coming response with schema in Postman. I'm using jsonSchema. But I can't use anyOf parameters in schema. For example I have an object in schema

"rmState":{
    "anyOf": [
        {
            "type": "string",
            "enum": [
                "REGISTERED",
                "DEREGISTERED"
            ]
        },
        {
            "type": "string"
        }
    ]
}

I expect that rmState can only have this enum parameters. But when I validate response with pm.response.to.have.jsonSchema(schema); validation passes even rmState got any other string from enum.Validation fails only if I change rmState to int. What am I missing for this validation? Thanks for helps.

1 Answers

You are checking if it is a string with any of the enum values OR a string. So it matches for all strings. I do not see why you need the anyOf

Related