1
SchemaValidationTrial.Json = 
 {
  "accessedByMember": false,
  "account": {
    "displayName": "4ed395e7-97a7-42fc-a909-d15804136c5e"
  },
  "line": {
    "PIM": {
      "bicycleExists": true,
      "totalDiscount": {
        "amount": "1.42"
      },
      "bicycles": [
        {
          "status_Ext": "Added"
        },
        {
          "status_Ext": "Updated"
        }
      ]
    }
  }
}


@id=ValidateMainSchema
  Scenario: Validate the Main Schema
    * def reqPayloadFile = sharedPath + 'SchemaValidationTrial.json'
    * def reqPayload = read(reqPayloadFile)
    * def commonSchemaRef=karate.call(sharedPath+'PPPPartnerEventsActions.feature'+'@validateCommonSchema')
    * def accountMainSchema = commonSchemaRef.accountSchema
    * def PIMMainSchema = commonSchemaRef.PIMSchema
    * def MainSchema =
    """
    {
    "accessedByMember": '#boolean',
    "account": '##(accountMainSchema)',
    "line": '##(PIMMainSchema)'
    }
    """
    * match reqPayload == '##(MainSchema)'

@validateCommonSchema
  Scenario: validate the Common Schema
    * def accountSchema =
    """
    {
    "displayName":'#string'
    }
    """
    * def bicyclesSchema =
    """
    {
    "status_Ext": '#string'
    }
    """
    * def PIMSchema =
    """
    {
    "PIM": {
    "bicycleExists": '#boolean',
    "totalDiscount":{
     "amount": '#string'
     },
    "bicycles": '#[] ##(bicyclesSchema)'
    }
    }
    """

Requirement:

  1. The Sub schema should be reusable. Example: PIM{} should be reusable in multiple Scenario.

When I run first scenario, this called second scenario. I am getting an error "bicyclesSchema is not define", but it is defined in second scenario .please check the Error logs screenshot.

enter image description here

Question: How to resolve this issue when the sub-schema defined variable called by another scenario?

SternK
  • 11,649
  • 22
  • 32
  • 46
  • expecting complex schema validation in "one step" is un-realistic. if the linked answer does not give you an answer, you can assume that karate can't do what you are expecting. next time, please create a simpler example instead of such a convoluted one: https://stackoverflow.com/help/how-to-ask – Peter Thomas Aug 19 '23 at 09:59

0 Answers0