You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to make validation strict and not allow any extra attributes on the object I'm validating allowUnknownAttributes set to false works as expected until you are having a ref to an additional schema and accessed in the definitions object on the Schema object.
Example interface Nested { fullName: string; isValid: boolean; nested: PostNewUser[]; }
translating this typescript into a schema results in looking like this:
Here is a test example of the JSON object I'm validating that should return true: { "fullName": "Jed Clampet", "isValid": true, "nested": [ { "firstName": "Jed", "lastName": "Clampet", "address": ["123 Fake Street"], "phone": 82155482 } ] }
When I run a valid object to this with allowUnknownAttributes being false I get an error like this:
SchemaError: Unsupported attribute: definitions\n at Validator.validateSchema
I think it makes sense for referenced schemas to be supported when allowUnknownAttributes is set to false. Is this possible to get fixed, or is there another way to get this to work?
The text was updated successfully, but these errors were encountered:
jonbaxt
changed the title
Nested Schema in the definitions object unsupported attribute when allowUnknownAttributes is set to true
Nested Schema in the definitions object unsupported attribute when allowUnknownAttributes is set to false
Oct 27, 2022
When attempting to make validation strict and not allow any extra attributes on the object I'm validating allowUnknownAttributes set to false works as expected until you are having a ref to an additional schema and accessed in the definitions object on the Schema object.
Example
interface Nested { fullName: string; isValid: boolean; nested: PostNewUser[]; }
translating this typescript into a schema results in looking like this:
{ "type": "object", "properties": { "fullName": { "type": "string" }, "isValid": { "type": "boolean" }, "nested": { "type": "array", "items": { "$ref": "#/definitions/PostNewUser" } } }, "required": [ "fullName", "isValid", "nested" ], "definitions": { "PostNewUser": { "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "address": { "type": "array", "items": { "type": "string" } }, "phone": { "type": "number" } }, "required": [ "address", "firstName", "lastName", "phone" ] } }, "$schema": "http://json-schema.org/draft-07/schema#" }
Here is a test example of the JSON object I'm validating that should return true:
{ "fullName": "Jed Clampet", "isValid": true, "nested": [ { "firstName": "Jed", "lastName": "Clampet", "address": ["123 Fake Street"], "phone": 82155482 } ] }
When I run a valid object to this with allowUnknownAttributes being false I get an error like this:
SchemaError: Unsupported attribute: definitions\n at Validator.validateSchema
I think it makes sense for referenced schemas to be supported when allowUnknownAttributes is set to false. Is this possible to get fixed, or is there another way to get this to work?
The text was updated successfully, but these errors were encountered: