Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Schema in the definitions object unsupported attribute when allowUnknownAttributes is set to false #379

Open
jonbaxt opened this issue Oct 27, 2022 · 0 comments

Comments

@jonbaxt
Copy link

jonbaxt commented 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?

@jonbaxt 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant