Validate no extra fields in document type

Hi,

Let’s say I have a document Reference with 4 fields

-firstName
-lastName
-dob
-postcode

when I use pub.schema:validate against the documentType, it doesn’t fail if I add an extra field in the document, how would you validate that the document only contains those 4 fields ?

Thanks
Alex

There is the document property “allow unspecified fields”. Set it to true. Then you can add arbitrary fields to the published doc (not to its definition but to the published instance) and it will validate and report no errors.

Hi,

this was the reversed answer to the question.

This property needs to be set to “false” to disallow unwanted fields.
It need to be set to the node which contains these 4 fields.

Please check if you are validating against the DocType or the schema used to create the DocType.
The behaviour of pub.schema:validate is slightly different then.

See IS Built-In-Services Reference for details.

Regards,
Holger

That’s correct, I misread the original post. Usually (when the publishable doc is created) this property is set to “false” so that no additional fields are allowed. People usually ask about how to change the default behaviour. My fault.

Hi, thanks for your answers, this works at the node level if a document contains a document node, what about restricting the document to have certain fields at the root level ?

Thanks
Alex

Try and see what happens :slight_smile:

then where is the “allow unspecified fields” options for the document itself ? :wink:

Hrm… I could not find it. I’ve always thought that documents are checked “strictly” when published,e.g. that no additional fields are allowed by default. Isn’t it a case for a support request?