Skip to content

Support for min/maxLength on object property names #110

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
frontierpsycho opened this issue Oct 25, 2016 · 2 comments
Closed

Support for min/maxLength on object property names #110

frontierpsycho opened this issue Oct 25, 2016 · 2 comments

Comments

@frontierpsycho
Copy link

(resubmitting from here)

It might be useful to be able to set limits on property names when defining them with patternProperties.

For example, I have an object which should have arbitrary key-value pairs, and I want to constrain the keys to be at most 64 characters. For now, I've resorted to this:

"additionalProperties": false,
"patternProperties": {
   "^\\S{1,64}$" : { ... }
}

(resubmitting this, from [here|https://github.com/json-schema/json-schema/issues/193#issuecomment-255453173])

However, the error message generated is very confusing. For example, if I send this object:

{ "SIXTYFOURCHARACTERSYOUSAYWELLALRIGHTTHENLETSNOTEXCEEDTHATSHALLWEIMEANWHONEEDSMORETHANSIXTYFOURCHARACTERSANYWAY":"value"}

I get the following error, which is clear to someone familiar with JSON-schema and the additional properties keyword, but not to everyone else:

SIXTYFOURCHARACTERSYOUSAYWELLALRIGHTTHENLETSNOTEXCEEDTHATSHALLWEIMEANWHONEEDSMORETHANSIXTYFOURCHARACTERSANYWAY: Additional properties not allowed

I suggest support for something like:

"patternProperties": {
  "^\\S*$": {
    "maxLength": 64,
    ...
  }
}

With the corresponding error message:

SIXTYFOURCHARACTERSYOUSAYWELLALRIGHTTHENLETSNOTEXCEEDTHATSHALLWEIMEANWHONEEDSMORETHANSIXTYFOURCHARACTERSANYWAY: Property name is too long (110 chars), maximum 64
@epoberezkin
Copy link
Member

@frontierpsycho This is covered by propertyNames proposal that is more generic: #70

@frontierpsycho
Copy link
Author

Indeed it is.

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