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

Not available to validate specific values per field #60

Open
IlyaUmanets opened this issue Aug 25, 2022 · 3 comments
Open

Not available to validate specific values per field #60

IlyaUmanets opened this issue Aug 25, 2022 · 3 comments

Comments

@IlyaUmanets
Copy link

In schema, I don't see a way to define allowed values per field. Here is an example with allowed_values attribute

{
  "type": "object",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "city": { "type": "string", allowed_values: ["Paris", "London"] },
    "country": { "type": "string" }
  },
  "required": ["country"]
}

It means it returns an error if I pass a different city.

Is there any workaround to do this?

@remi
Copy link
Member

remi commented Aug 25, 2022

Hi @IlyaUmanets,

I’m not sure, are you asking if it’s possible to do that using a schema? Or you are reporting a bug with ActiveRecord::JSONValidator?

@IlyaUmanets
Copy link
Author

@remi, No, I do not report a bug. It's more like a question or suggestion rather than a bug.

@remi
Copy link
Member

remi commented Sep 14, 2022

@IlyaUmanets You could do string validation using the pattern field: https://json-schema.org/draft/2020-12/json-schema-validation.html#name-pattern

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

2 participants