Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

karate : Complex JSON Schema matching #346

Closed
avyasbms opened this issue Mar 13, 2018 · 11 comments
Closed

karate : Complex JSON Schema matching #346

avyasbms opened this issue Mar 13, 2018 · 11 comments
Assignees
Milestone

Comments

@avyasbms
Copy link

Feature: Complex Schema
  Background:
    * def JSONtobeValidiated =
    """

  {
  "MyArray": {
    "MYinternalDetails": [
      {
        "SomeField": "dc",
        "textfield": [],
        "OptionalArray1": [
          {
            "Users": "Y",
            "IsAllowed": "Y"
          },
          {
            "Users": "Y",
            "IsAllowed": "Y"
          }
        ]
      },
      {
        "SomeField": "cd",
        "textfield": [],
        "OptionalArray3": [
          {
            "Astring": "Lazy",
            "AnotherString": "N",
            "textfield": []
          },
          {
            "Astring": "FREE",
            "AnotherString": "N",
            "textfield": [
              {
                "title": "Name",
                "alertMessage": "Please enter valid name."
              },
              {
                "title": "Mobile No",
                "alertMessage": "Please enter mobile no."
              }
            ]
          }
        ]
      },
      {
        "SomeField": "gv",
        "textfield": [
          {
            "title": "First",
            "alertMessage": "SOme Alert"
          }
        ]
      },
      {
        "SomeField": "rp",
        "textfield": []
      }
    ]
  }
}"""

    * def textfield = { title: '#string', alertMessage: '#string' }
    * def OptionalArray1 = { Users: '#string',IsAllowed: '#string' }
    * def OptionalArray3 = { Astring: '#string' ,AnotherString: '#string', textfield: '##[]'  }

    * def MYinternalDetails =
    """
      {
        SomeField: '#string',
        textfield: '##[]',
        OptionalArray1: '##[] OptionalArray1'
        OptionalArray3: '##[] OptionalArray3'
      }

    """

    * def ValidJsonSchema = { MyArray: { MYinternalDetails: '#[] MYinternalDetails' } }

  Scenario: These matches works

    * match JSONtobeValidiated.MyArray.MYinternalDetails == '#[]'
    * match JSONtobeValidiated.MyArray.MYinternalDetails == '#[4]'
    * match JSONtobeValidiated contains  { MyArray: '#ignore' }
    * match JSONtobeValidiated contains { MyArray: { MYinternalDetails: '#ignore' } }



  Scenario: These match doesn't work
    * match JSONtobeValidiated contains { MyArray: { MYinternalDetails: '#[] MYinternalDetails' } }

  Scenario: These match doesn't work either

    * match JSONtobeValidiated.MyArray.MYinternalDetails == '#[] MYinternalDetails'

  Scenario: These match Also doesn't work

    * match JSONtobeValidiated == ValidJsonSchema



In Above Example , Schema matching doesn't seems to be working as expected. Need to match full JSON schema.

Reference: https://stackoverflow.com/questions/49231115/karate-complex-json-schema-matching

@ptrthomas ptrthomas self-assigned this Mar 13, 2018
@ptrthomas ptrthomas added the bug label Mar 13, 2018
@ptrthomas ptrthomas added this to the v0.7.1 milestone Mar 13, 2018
@ptrthomas
Copy link
Member

able to replicate with this example:

Background:
* def json =
"""
{
  "foo": {
    "bars": [
      { "barOne": "dc", "barTwos": [] },
      { "barOne": "dc", "barTwos": [{ title: 'blah' }] },
      { "barOne": "dc", "barTwos": [{ title: 'blah' }], barThrees: [] },
      { "barOne": "dc", "barTwos": [{ title: 'blah' }], barThrees: [{ num: 1 }] }
    ]
  }
}
"""

* def barTwo = { title: '#string' }
* def barThree = { num: '#number' }
* def bar = { barOne: '#string', barTwos: '#[] barTwo', barThrees: '##[] barThree' }

Scenario:
* match json.foo.bars == '#[] bar'

@ptrthomas
Copy link
Member

@avyasbms thanks a lot for finding this, it is fixed in dev. if you can build and run from source, do verify - else we can release a 0.7.0.2 shortly.

@avyasbms
Copy link
Author

Waiting for 0.7.0.2 to verify.

@avyasbms
Copy link
Author

@ptrthomas Can you let me know how to verify?
A lot of our APIs are pending on this one.

@ptrthomas
Copy link
Member

@avyasbms sorry, I should have done this earlier, but somehow thought you had a workaround.

I just released 0.7.0.2 - can you confirm that it works ?

@avyasbms
Copy link
Author

Hey @ptrthomas It seems to be working. I'll check more cases and will confirm. Thanks a lot.

@avyasbms
Copy link
Author

Confirming that it worked for many other cases as well. Thanks again!

@ptrthomas
Copy link
Member

thanks @avyasbms I'll just keep this open pending the official 0.8.0 release

@ptrthomas ptrthomas reopened this Apr 26, 2018
@ptrthomas
Copy link
Member

released 0.8.0

@roma-shukla-wcq
Copy link

roma-shukla-wcq commented Sep 20, 2023

Hi @ptrthomas, the bug is again reproducible in 1.4.1.RC3. Please see this stackoverflow question for details: https://stackoverflow.com/questions/77125005/karate-complex-json-schema-validation-does-not-work-as-expected

I'm unaware of the process around reopening issues, so please suggest.

@ptrthomas
Copy link
Member

@roma-shukla-wcq there is some discussion in #2364 which I think is related to your issue, this may need more changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants