Topic
  • 7 replies
  • Latest Post - ‏2014-06-19T20:16:08Z by msmps
msmps
msmps
209 Posts

Pinned topic JSON schema error

‏2014-06-12T19:33:16Z |
I have two Requests will be either 
one with  Last Name or First Name Along with Gender and State
or thru Userid
 
So the request for NameSearch is either

 
  {
    "NameSearch":
    {"LastName": "Doe",
    "Gender":"Male",
    "State" : "FL"
    }
    }
    
    or 
    
    {
    "NameSearch":
    {
    "FirstName": "John",
    "Gender":"Male",
    "State" : "FL"
    }
    }

 

 
and for UseridSearch is as follows
 
 
   {
    "UIDSearch":
    {
    "UID": "12345"
    }
    }

I wrote a schema to validate this to accomadate all three type of requests 

   
 {
         "anyOf": [
    
      {
     "type":"object",
     "additionalProperties": false,
     "properties":{
     
     
     "NameSearch": {         
        "anyOf": 
     [
                {
                    "type":"object",
                    "additionalProperties": false,
                    "properties":
     {
     "FirstName": 
     {
                                                "type":"string",                                          
     "required":true
                                            },
    
     "Gender": 
     {
     "type":"string", 
     "required":true
     },
     "State": 
     {
     "type":"string",
     "required":true
     }
     }
                },
                {
                    "additionalProperties": false,
                    "properties":
     {
     "LastName": 
     {
                                                "type":"string",                                          
     "required":true
                                            },
    
     "Gender": 
     {
     "type":"string", 
     "required":true
     },
     "State": 
     {
     "type":"string",
     "required":true
     }
     }
                }
            ]
     }
     }
     },
    
       {
     "additionalProperties": false,
     "properties":{
     "UIDSearch": {
     "type":"object",
     "additionalProperties": false,
     "properties":{
     "UID": 
     {
                                                "type":"string",
     "required":true
                                            }
     }
     }
     }
     }
     
     ]
     }
but dp is not validating it
 
  • NILAY97
    NILAY97
    245 Posts

    Re: JSON schema error

    ‏2014-06-14T16:52:32Z  

    what do u mean by DataPower not validating it? 

    Can you mention the steps you did to validate this?

    Thanks,

    Nilay

  • HermannSW
    HermannSW
    5831 Posts

    Re: JSON schema error

    ‏2014-06-14T20:40:58Z  

    Hi Robert,

    your JSV file is accoding draft-04 of JSON Schema validation ("anyOf" is in draft-04, not draft-03):
    https://github.com/json-schema/json-schema/blob/master/draft-04/schema
    https://github.com/json-schema/json-schema/blob/master/draft-03/schema

    DataPower firmware 6.0.0.x and 6.0.1.y implement draft-03.
    Yesterday released 7.0.0.0 firmware implements draft-04.

    As you can see here your 3 sample requests validate fine against your JSV file:
     

    $ curl --data-binary @NameSearchFirst.json http://dp1-l3:7501 ; echo
    
    {
      "NameSearch":{
        "State":"FL",
        "Gender":"Male",
        "FirstName":"John"
      }
    }
    $ 
    $ curl --data-binary @NameSearchLast.json http://dp1-l3:7501 ; echo
    
    {
      "NameSearch":{
        "State":"FL",
        "Gender":"Male",
        "LastName":"Doe"
      }
    }
    $ 
    $ curl --data-binary @UseridSearch.json http://dp1-l3:7501 ; echo
    
    {
      "UIDSearch":{
        "UID":"12345"
      }
    }
    $
    

    Hermann.

    Updated on 2014-06-14T20:46:53Z at 2014-06-14T20:46:53Z by HermannSW
  • HermannSW
    HermannSW
    5831 Posts

    Re: JSON schema error

    ‏2014-06-14T20:50:08Z  
    • HermannSW
    • ‏2014-06-14T20:40:58Z

    Hi Robert,

    your JSV file is accoding draft-04 of JSON Schema validation ("anyOf" is in draft-04, not draft-03):
    https://github.com/json-schema/json-schema/blob/master/draft-04/schema
    https://github.com/json-schema/json-schema/blob/master/draft-03/schema

    DataPower firmware 6.0.0.x and 6.0.1.y implement draft-03.
    Yesterday released 7.0.0.0 firmware implements draft-04.

    As you can see here your 3 sample requests validate fine against your JSV file:
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">$ curl --data-binary @NameSearchFirst.json http://dp1-l3:7501 ; echo { "NameSearch":{ "State":"FL", "Gender":"Male", "FirstName":"John" } } $ $ curl --data-binary @NameSearchLast.json http://dp1-l3:7501 ; echo { "NameSearch":{ "State":"FL", "Gender":"Male", "LastName":"Doe" } } $ $ curl --data-binary @UseridSearch.json http://dp1-l3:7501 ; echo { "UIDSearch":{ "UID":"12345" } } $ </pre>

    Hermann.

    Find attached 7.0.0.0 service export with slight performance improvement.

    In order to be able to do json schema validation JSON input needs to be parsed.
    This can be easily done by JSON request type.

    Side-effect of request type JSON is creation of context __JSONASJSONX and conversion of input as JSONX.

    Service has request type Non-XML and JSON parsing is done by JSONiq xfrom action doing  store:///identity-json.xq.
    This avoids JSONx conversion and population of context __JSONASJSONX.


    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> | <xqib/> | <myCE/> <myFrameless/>

    Attachments

    Updated on 2014-06-14T20:55:50Z at 2014-06-14T20:55:50Z by HermannSW
  • HermannSW
    HermannSW
    5831 Posts

    Re: JSON schema error

    ‏2014-06-15T19:01:32Z  
    • HermannSW
    • ‏2014-06-14T20:50:08Z

    Find attached 7.0.0.0 service export with slight performance improvement.

    In order to be able to do json schema validation JSON input needs to be parsed.
    This can be easily done by JSON request type.

    Side-effect of request type JSON is creation of context __JSONASJSONX and conversion of input as JSONX.

    Service has request type Non-XML and JSON parsing is done by JSONiq xfrom action doing  store:///identity-json.xq.
    This avoids JSONx conversion and population of context __JSONASJSONX.


    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> | <xqib/> | <myCE/> <myFrameless/>

    7.0.0.0 XI knowledge center has been uploaded, this is the "official" statement wrt JSV support for 7.0.0.0 (draft version 04):
    http://www-01.ibm.com/support/knowledgecenter/api/content/SS9H2Y_7.0.0/com.ibm.dp.xi.doc/relnotesXI.html?locale=en&ro=kcUI#relnotesXI__d11e698

    Not sure on whether/how deep links work for 6.0.1 InfoCenter.
    Just search for "draft specification" here (draft version 03):
    http://pic.dhe.ibm.com/infocenter/wsdatap/v6r0m1/index.jsp?topic=%2Fcom.ibm.dp.xi.doc%2FrelnotesXI.html


    Hermann.

  • msmps
    msmps
    209 Posts

    Re: JSON schema error

    ‏2014-06-18T15:44:01Z  
    • HermannSW
    • ‏2014-06-15T19:01:32Z

    7.0.0.0 XI knowledge center has been uploaded, this is the "official" statement wrt JSV support for 7.0.0.0 (draft version 04):
    http://www-01.ibm.com/support/knowledgecenter/api/content/SS9H2Y_7.0.0/com.ibm.dp.xi.doc/relnotesXI.html?locale=en&ro=kcUI#relnotesXI__d11e698

    Not sure on whether/how deep links work for 6.0.1 InfoCenter.
    Just search for "draft specification" here (draft version 03):
    http://pic.dhe.ibm.com/infocenter/wsdatap/v6r0m1/index.jsp?topic=%2Fcom.ibm.dp.xi.doc%2FrelnotesXI.html


    Hermann.

    Hi Hermann,
    My admin team is not yet ready to go to V7 firmware
    IS there any way I can accommodate in draft3. Could you help me  with draft3 schema
  • HermannSW
    HermannSW
    5831 Posts

    Re: JSON schema error

    ‏2014-06-19T02:53:47Z  
    • msmps
    • ‏2014-06-18T15:44:01Z
    Hi Hermann,
    My admin team is not yet ready to go to V7 firmware
    IS there any way I can accommodate in draft3. Could you help me  with draft3 schema

    Hi,

    of course it will not be possible to do all what draft-04 is about in draft-03.

    But I learned this from a colleague, you may try:

    In draft-03, anyOf is available through the type keyword. For instance, this draft-03 schema:
         { "type": [ { Schema1 }, { Schema2} ] }
    is equivalent to this draft-04 schema:
        { "anyOf": [ {Schema1}, { Schema2} ] }

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> | <xqib/> | <myCE/> <myFrameless/>

  • msmps
    msmps
    209 Posts

    Re: JSON schema error

    ‏2014-06-19T20:16:08Z  
    • HermannSW
    • ‏2014-06-19T02:53:47Z

    Hi,

    of course it will not be possible to do all what draft-04 is about in draft-03.

    But I learned this from a colleague, you may try:

    In draft-03, anyOf is available through the type keyword. For instance, this draft-03 schema:
         { "type": [ { Schema1 }, { Schema2} ] }
    is equivalent to this draft-04 schema:
        { "anyOf": [ {Schema1}, { Schema2} ] }

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> | <xqib/> | <myCE/> <myFrameless/>

    I tried using type as follows:
     
        "type": "object", 
        "additionalProperties": false, 
        "properties": { 
            "NameSearch": { 
                "required": true, 
                "type": [ { "$ref": "#/firstName" }, { "$ref": "#/LastName" } ] 
            } 
        }, 
        "firstName": { 
            "id": "#/firstName",
            "type": "object", 
            "additionalProperties": false, 
            "properties": {
    "firstName":{
                       "type":"string",
                                               
    "required":true
                                            },
    "Gender": 
    {
    "type":"string",
     
    "required":true
    },
    "State": 
    {
    "type":"string",
     
    "required":true
    }}
        }, 
        "LastName": { 
            "id": "#/LastName",   
            "type": "object", 
            "additionalProperties": false, 
               "properties": {
    "LastName":{
                       "type":"string",
                                               
    "required":true
                                            },
    "Gender": 
    {
    "type":"string",
     
    "required":true
    },
    "State": 
    {
    "type":"string",
     
    "required":true
    }}
        } 
    }
     
     
    It is working in our  appliance with  Firmware:XI52.6.0.1.0 Build:237837
     
    but in  appliance with Firmware:XI52.6.0.0.0 Build:231528 got the following error
     
    3:56:52 PM mpgw error 3791521474 error    0x00c30010 mpgw (mpgw_ab): Internal Error
    3:56:52 PM schema error 3791521474      0x80a002a0 xmlmgr (default): xsd: Request failed to compile. Fatal Error at ?:0: Keyword not implemented. Referenced by local:///sample.jsv.
    3:56:52 PM schema debug 3791521474      0x80a002a3 xmlmgr (default): xsd Compilation Request: Beginning compilation of URL 'local:///sample.jsv'.
    3:56:52 PM multistep error 3791521474 request    0x80c00009 mpgw (mpgw_ab): request mpgw_ab_req_rule #1 validate: 'INPUT json-schema local:///sample.jsv' failed: Internal Error
    3:56:52 PM schema debug 3791521474      0x80a002af xmlmgr (default): xsd Compilation Request: Not in cache. Compiling 'local:///sample.jsv'.
    3:56:52 PM schema debug 3791521474      0x80a002aa xmlmgr (default): xsd Compilation Request: Checking cache for URL 'local:///sample.jsv'.