简体   繁体   English

我无法使用 jsonSchema 验证 postman 中任何对象的响应

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

I want to validate coming response with schema in Postman.我想用 Postman 中的模式验证即将到来的响应。 I'm using jsonSchema.我正在使用 jsonSchema。 But I can't use anyOf parameters in schema.但我不能在模式中使用 anyOf 参数。 For example I have an object in schema例如,我在架构中有一个 object

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

I expect that rmState can only have this enum parameters.我希望 rmState 只能有这个枚举参数。 But when I validate response with pm.response.to.have.jsonSchema(schema);但是当我用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.验证通过,甚至 rmState 从枚举中获取了任何其他字符串。只有当我将 rmState 更改为 int 时,验证才会失败。 What am I missing for this validation?这个验证我缺少什么? Thanks for helps.感谢您的帮助。

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我不明白你为什么需要 anyOf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM