JSON SCHEMA VALIDATE in built service throwing error

Hey Folks,

I am trying to validate Json schema using in built service

image

It’s not working, I have been at this for more than 12hrs staright trying to sort out the mapping but same error.
Here is the mappings

For conform field I am passing in the schema that will validate the Json request coming in:

{
“$schema”: “http://json-schema.org/draft-06/schema#”,
“$ref”: “#/definitions/Welcome”,
“definitions”: {
“Welcome”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“header”: {
“$ref”: “#/definitions/header”
},
“body”: {
“$ref”: “#/definitions/body”
}
},
“required”: [
“body”,
“header”
],
“title”: “Welcome”
},
“body”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“phonenumber”: {
“type”: “string”,
“pattern”: “[1]{9}$”
}
},
“required”: [
“phonenumber”
]
},
“header”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“Id”: {
“type”: “string”,
“pattern”: “^\d{10}$”
}
},
“required”: [
“Id”
]

    }
}

}

Here is the Json request that will be passed into inbound field:

{

"header":{
    "Id":"1234567890"

},
"body":{
    "phonenumber":"123456789"
}

}

Here is the constant error:

com.wm.app.b2b.server.ServiceException: JSON schema validation failed: {
“$schema”: “http://json-schema.org/draft-06/schema#”,
“$ref”: “#/definitions/Welcome”,
“definitions”: {
“Welcome”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“header”: {
“$ref”: “#/definitions/header”
},
“body”: {
“$ref”: “#/definitions/body”
}
},
“required”: [
“body”,
“header”
],
“title”: “Welcome”
},
“body”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“phonenumber”: {
“type”: “string”,
“pattern”: “[2]{9}$”
}
},
“required”: [
“phonenumber”
]
},
“header”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“Id”: {
“type”: “string”,
“pattern”: “^\d{10}$”
}
},
“required”: [
“Id”
]

    }
}

}
is not a valid JSON document type.

com.wm.app.b2b.server.ServiceException: JSON schema validation failed: {
“$schema”: “http://json-schema.org/draft-06/schema#”,
“$ref”: “#/definitions/Welcome”,
“definitions”: {
“Welcome”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“header”: {
“$ref”: “#/definitions/header”
},
“body”: {
“$ref”: “#/definitions/body”
}
},
“required”: [
“body”,
“header”
],
“title”: “Welcome”
},
“body”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“phonenumber”: {
“type”: “string”,
“pattern”: “[3]{9}$”
}
},
“required”: [
“phonenumber”
]
},
“header”: {
“type”: “object”,
“additionalProperties”: false,
“properties”: {
“Id”: {
“type”: “string”,
“pattern”: “^\d{10}$”
}
},
“required”: [
“Id”
]

    }
}

}
is not a valid JSON document type.
at pub.jsonschema.getSchemaPathFromNode(jsonschema.java:120)
at pub.jsonschema.validate(jsonschema.java:97)
at sun.reflect.GeneratedMethodAccessor105.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:411)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:739)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:46)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:61)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:250)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:56)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:178)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:334)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:41)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:401)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:611)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:423)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:381)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:253)
at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:236)
at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:267)
at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:668)
at com.wm.lang.flow.FlowState.step(FlowState.java:534)
at com.wm.lang.flow.FlowState.invoke(FlowState.java:501)
at com.wm.app.b2b.server.FlowSvcImpl.baseInvoke(FlowSvcImpl.java:1150)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:739)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:46)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:61)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:250)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:56)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:178)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:334)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:41)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:401)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:611)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:423)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:381)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:253)
at com.wm.app.b2b.server.comm.DefaultServerRequestHandler.handleMessage(DefaultServerRequestHandler.java:127)
at com.wm.app.b2b.server.HTTPMessageHandler.process(HTTPMessageHandler.java:163)
at com.wm.app.b2b.server.HTTPDispatch.handleRequest(HTTPDispatch.java:223)
at com.wm.app.b2b.server.Dispatch.run(Dispatch.java:430)
at com.wm.util.pool.PooledThread.run(PooledThread.java:134)
at java.lang.Thread.run(Thread.java:748)

Please help folks. It is becoming tiresome.
I am not sure where to pass the schema and where to pass the request that I need to validate against schema.

Thanks


  1. \d ↩︎

  2. \d ↩︎

  3. \d ↩︎

Hello Sufran,

Are you passing JSON document type name in conformsTo field?

From the error message, it looks like you are passing string value in confirmsTo field. Please refer to the in-built service reference guide for more details.

Thanks,
Yogesh

Here is the fix:

Everywhere I read it is being mentioned with either Doc type or IS Doc type.
That actually diverted me and made my work more tedious.

It is actually JSON DOC Type
I was getting this error because passing the entire schema is not allowed, You have to pass in the name of JSON DOC TYPE you create.

Right click package → new → Json doc type
image

I was actually creating
image

that was throwing the error.
The way you pass in the name into conformto field is by right clicking json doc type in whichever package you created the json doc type and copy and then paste in the name into corfomto field and map it.

1 Like

It’s unfortunate that SAG called these “JSON Document Type” because they are not fully conceptually the same as document types. In the documentation:

JSON document type can be created only from a JSON schema…

These are a hybrid object, with characteristics of a document type and a schema. Many limitations associated with them. My take is to use them for validation only (if/when that is needed) and define a peer doc type that is used in the usual way that doc types are used.

As I’ve done elsewhere, I once again advocate for not performing payload validation “in the middle”. That aspect should be the domain of the end-points whenever possible.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.