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

Reconsider 'range' for string parameters #23

Closed
awoods opened this issue Aug 18, 2020 · 4 comments
Closed

Reconsider 'range' for string parameters #23

awoods opened this issue Aug 18, 2020 · 4 comments

Comments

@awoods
Copy link
Member

awoods commented Aug 18, 2020

Related to comments: #13 (comment)

The range currently defined for string parameters can be somewhat unintuitive:

the range specifies the maximum length of the string as an integer number of characters, not bytes

This issue is to discuss potentially more suitable definitions for a string's range.

@awoods
Copy link
Member Author

awoods commented Sep 10, 2020

As one datapoint, JSON allows for "ranges" to include:

  • maxLength and minLength
  • regex pattern
  • predefined formats

https://json-schema.org/understanding-json-schema/reference/string.html

@sprater
Copy link

sprater commented Sep 10, 2020

Regex might be a good catch-all range, as both length and format can be defined as regex patterns.

@botimer
Copy link

botimer commented Sep 10, 2020

It seems to me that flattening the schema and using string-encoded data here is medicine worse than the disease. I think the more intuitive approach is to expand the schema for parameter definitions to cover "constraints" as an optional, composite value with a set of valid properties dependent on the type. In such case, such definitions would be more obvious to humans and the handling/validation code will likely be less error prone than a bunch of conditional string parsing on the same overloaded field.

  • When type is integer, minValue and maxValue are integers (+ fuller details, inclusive/exclusive, etc.)
  • When type is string, minLength and maxLength are integers ... format is an ES6-compatible regular expression that must be matched by any value ...
  • When type is enum, allowedValues is an array of acceptable strings ...
  • When type is boolean, no constraints are applicable and must not be included

I think there is minimal value in requiring JSON-compatible identifiers and quoting but stopping short of accepting that some elements here really are structured or typed differently. A couple of key-value properties and an array property don't offend me, but string smashing does.

@awoods
Copy link
Member Author

awoods commented Nov 17, 2020

@awoods awoods closed this as completed Nov 17, 2020
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

3 participants