Skip to content

Property name restriction based on values of array #102

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

Closed
ASnow opened this issue Oct 18, 2016 · 7 comments
Closed

Property name restriction based on values of array #102

ASnow opened this issue Oct 18, 2016 · 7 comments

Comments

@ASnow
Copy link

ASnow commented Oct 18, 2016

I want get validation schema for something like this:

{
  "base_keys_collection": [
    {"name": "key1"}, // "keyN" is just for example it could be any string
    {"name": "key2"},
    {"name": "key3"}
  ],
  "base_values_collection": [
    {"name": "value1"}, // "valueN" is just for example it could be any string
    {"name": "value2"},
    {"name": "value3"}
  ],
  "target_validated_collection": {
    "key1": ["value1", "value2"],
    "key2": ["value1", "value3"]
  }
}

it should validate target_validated_collection properties by base_keys_collection/*/name and target_validated_collection property's values by base_values_collection/*/name

I think it could be done by definitions. We should define Keys and Values and use them as templates for object properties.

@Relequestual
Copy link
Member

I don't understand how what you are suggesting is beyond what definitions already provides. Could you elaborate?

@awwright
Copy link
Member

@ASnow Can you please provide an example of how the keyword might work?

@ASnow
Copy link
Author

ASnow commented Oct 19, 2016

{
  brands: [
   "Lada",
   "BMW",
   "Opel",
   "Audi"
  ],
  transport: [
   'car',
   'motorcycle'
  ],
  products: {
    "BMW": ['car', 'motorcycle'],
    "Lada": 'car'
  }
}

I need to verify products by brands and transport

@awwright
Copy link
Member

@ASnow An example of the schema keyword, used in a schema. How would it work?

@epoberezkin
Copy link
Member

@ASnow I think what you want would be covered by propertyNames #70 (which allows to validate keys against any schema, so you would be able to use enum).

@epoberezkin
Copy link
Member

epoberezkin commented Oct 20, 2016

And if you want to have dynamic value of enum it is covered by $data proposal: https://github.com/json-schema/json-schema/wiki/$data-(v5-proposal)

@ASnow
Copy link
Author

ASnow commented Oct 20, 2016

@epoberezkin, thanks. Those features will cover this problem.

@ASnow ASnow closed this as completed Oct 20, 2016
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

4 participants