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

Support format property for object type of schemas #2290

Closed
muratgozel opened this issue Jun 8, 2023 · 1 comment
Closed

Support format property for object type of schemas #2290

muratgozel opened this issue Jun 8, 2023 · 1 comment

Comments

@muratgozel
Copy link

What version of Ajv you are you using?
8.12.0

What problem do you want to solve?
Unable validate object type of schemas which properties are dependent to each other.

Consider the following phone number schema:

const schema = {
    type: 'object',
    required: ['email', 'phone'],
    properties: {
        email: { type: 'string', format: 'email' }, // I have the email format and it works well
        phone: {
            type: 'object',
            required: ['num', 'country'],
            /* format: 'phone_num' // This is what I wish for. */
            properties: {
                num: { type: 'string' },
                country: { type: 'string', format: 'country_code' } // I have the country_code format and it works well
            }
        }
    }
}

Phone number schema needs one validator function that has num and country, as you guess. But I didn't see any way to validate this object as a whole in docs. Is there a recommended way to achieve this? Or is it something ajv doesn't support?

What do you think is the correct solution to problem?
Support format property for object type of schemas.

Will you be able to implement it?
I don't know yet.

@jasoniangreen
Copy link
Collaborator

After reviewing the docs it looks like format keyword only applies to type string and I don't think this is something we would be open to changing. You could, however, try adding a custom keyword. I believe keywords get access to more of the context and can be used on any data type.

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

No branches or pull requests

2 participants