空数组失败,尽管在模式验证中设置为可选##(变量)

问题描述 投票:0回答:1

我们设置了测试和模式验证,但是当数组为空时,尽管该字段被标记为可选并且我们设置了

configure matchEachEmptyAllowed = true
,但它还是失败了。

这是否是由于响应返回时在数组中带有回车而不是 []?

针对架构进行评估的请求/响应

  Scenario: Scenario for endpoint
    * configure matchEachEmptyAllowed = true

    Given path 'v1/mduManagementProperties'
    When method GET
    Then status 200
    * match $ == schemaList.QueryOrgPropertiesResponse

Response
{
  "staffContacts": [
  ]
}


Resulting error:

* match $ == schemaList.QueryOrgPropertiesResponse
match failed: EQUALS
  $ | not equal | actual does not contain key - 'businessHours' (MAP:MAP)
  {"staffContacts":[]}
  {"staffContacts":"##[] schemaList.ContactItem","businessHours":{"Monday":"##[] schemaList.Time","Tuesday":"##[] schemaList.Time","Wednesday":"##[] schemaList.Time","Thursday":"##[] schemaList.Time","Friday":"##[] schemaList.Time","Saturday":"##[] schemaList.Time","Sunday":"##[] schemaList.Time"},"errorMessage":"##string","lastBusinessHoursModificationDate":"##string","lastContactConfirmationDate":"##string","result":"##string","txnId":"#regex[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}","timestamp":"#regex^[0-9]{4}-[0-1][0-9]-[0-3][0-9]{1}T[0-2][0-9]{1}:[0-5][0-9]{1}:[0-5][0-9]{1}(\\.[0-9]{1,9})?(Z)?(-[0-2][0-9]{1}:[0-5][0-9]{1})?$","message":"##string","systemErrorCode":"##string","code":"##string","clientIp":"##string","sourcePort":"##string"}

架构部分

Feature: List of response schemas for validation
  Scenario: Set Schemas
    * def QueryOrgPropertiesResponse =
    """
        {
        businessHours: '##(schemaList.BusinessHours)',
        errorMessage: '##string',
        lastBusinessHoursModificationDate: '##string',
        lastContactConfirmationDate: '##string',
        result: '##string',
        staffContacts: '##[] schemaList.ContactItem',
        txnId: '#(txnIdCheck)',
        timestamp: '#(timestampCheck)',
        message: '##string',
        systemErrorCode: '##string',
        code: '##string',
        clientIp: '##string',
        sourcePort: '##string'
        }
    """

    * def BusinessHours =
    """
        {
        Monday: '##[] schemaList.Time',
        Tuesday: '##[] schemaList.Time',
        Wednesday: '##[] schemaList.Time',
        Thursday: '##[] schemaList.Time',
        Friday: '##[] schemaList.Time',
        Saturday: '##[] schemaList.Time',
        Sunday: '##[] schemaList.Time'
        }
    """

    * def Time =
    """
        {
        start: '##string',
        end: '##string'
        }
    """

    * def ContactItem =
    """
        {
        staffContactId: '##string',
        firstName: '##string',
        lastName: '##string',
        phoneNumber: '##string',
        phoneType: '##string',
        email: '##string',
        extension: '##string',
        businessHoursPrimary: '##boolean',
        businessHoursAlternate: '##boolean',
        afterHoursPrimary: '##boolean',
        afterHoursAlternate: '##boolean'
        }
    """
karate
1个回答
0
投票

仔细查看您要匹配的内容。一个大物体与只有一把钥匙的物体。也许你需要做的就是这样:

 * match response contains schemaList.QueryOrgPropertiesResponse
© www.soinside.com 2019 - 2024. All rights reserved.