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

Optional properties in an object are still validated #63

Closed
rfcheung opened this issue Dec 12, 2018 · 5 comments
Closed

Optional properties in an object are still validated #63

rfcheung opened this issue Dec 12, 2018 · 5 comments
Assignees
Labels

Comments

@rfcheung
Copy link

If I try to validate an object like the example in the documentation. I get a JSON invalid error.

interface User {
  firstName: string;
  lastName: string;
  age?: number;
}

const schema: JSONSchemaObject = {
  properties: {
    firstName: { type: 'string' } as JSONSchemaString,
    lastName: { type: 'string' } as JSONSchemaString,
    age: { type: 'number' } as JSONSchemaNumeric
  },
  required: ['firstName', 'lastName']
};

const user: User = { firstName: 'Foo', lastName: 'Bar };
this.localStorage.setItem('user', user).subscribe(() => {});

this.localStorage.getItem<User>('user', { schema }).subscribe(res => console.log(res));

image

Am I doing something wrong?

Tested with 7.2.0

@cyrilletuzi
Copy link
Owner

This scenario is tested, and the test is OK.

There is a missing ' after Bar in your code, is that normal?

const user: User = { firstName: 'Foo', lastName: 'Bar };

@rfcheung
Copy link
Author

Ah my bad, but even with the the ', it is still giving JSON invalid. Don't really understand

@cyrilletuzi cyrilletuzi self-assigned this Dec 12, 2018
@cyrilletuzi
Copy link
Owner

Fixed in v5.3.2, v6.2.1 and v7.2.1.

@rfcheung Thanks for reporting. 👍

@bogacg
Copy link

bogacg commented Sep 23, 2019

Is it possible this problem still continues ? (v9-beta1)

@cyrilletuzi
Copy link
Owner

No, it's supposed to be fixed. If you found a bug, please file a new issue with a reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants