I’m trying to validate a document using pub.schema:validate. Here is a representative doc type definition (named ABC):
ID (string - required, no null)
Name (string - optional)
Summary (document list - required, no null)
…Product (string - required, no null)
…Type (string - required, no null)
Stage (string - required, no null)
Document var xyz has these fields present:
ID - 123
Name - foo
Stage - bar
Calling pub.schema:validate with these inputs:
object - xyz
conformsTo - ABC (IS doc type, not a schema)
maxErrors - -1
failIfInvalid - true
I expect the call to fail since xyz does not have the required doc list “Summary” present, but it does not. It fails as expected if “Stage” is omitted.
I’m missing something simple, I’m sure. Does anyone have an idea of what I’m overlooking?
when I pass in the schema directly into conformTo field, it throws this error
com.wm.app.b2b.server.ServiceException: JSON schema validation failed:{} is not a valid JSON document type.
Please let me know.
Pass in the name of the IS document type, not the JSON schema string. In Designer, create a “JSON Document Type”. You may need to adjust your JSON schema. When I tried to do this using the JSON above, it fails due to multiple issues.
Once the doc type is created, call pub.json.schema:validate to validate JSON content (string, bytes, stream, IS document) against the JSON document type. Pass the document type name that you created, not the JSON schema string.
Side note: I would encourage that you NOT perform document validation “in the middle.” Typically it is preferable to have the end points do that, if needed, because they know what they really need/care about which can change over time. What usually happens is middleware flags a document as invalid, then the end point application team says “oh, ignore that.”