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

Limit the number of characters with string datatype #545

Open
jdacoello opened this issue Feb 21, 2023 Discussed in #533 · 3 comments
Open

Limit the number of characters with string datatype #545

jdacoello opened this issue Feb 21, 2023 Discussed in #533 · 3 comments

Comments

@jdacoello
Copy link
Contributor

Discussed in #533

Originally posted by jdacoello February 10, 2023
Is it possible to define the number of valid characters when using string datatype? One example would be to set light colours using hexadecimal color code, where 7 characters are expected.

  • #ABCDEF

If not, I can create an issue to work on that.

Another example where this function can help is the VIN number:

VehicleIdentification.VIN:
  datatype: string
  type: attribute
  description: 17-character Vehicle Identification Number (VIN) as defined by ISO 3779.

In practice, how do you enforce the use of 17 characters? If this characteristic is only mentioned in the description, one must have a custom function that does the job. In contrast, if a field in VSS explains the constraints, the user can refer to the described constraints.

@erikbosch
Copy link
Collaborator

There is no mechanism for that today. We have a similar topic for strings where the description says it shall be time formatted according to ISO 8601. One thought I had at a time was to "invent" special units, like unit: VIN , unit: color and describe the expected formatting as a comment in the unit file. Then one could even possibly add a regexp to the unit definition file which tooling/servers/client possibly could use for validation.

@jdacoello
Copy link
Contributor Author

There is no mechanism for that today. We have a similar topic for strings where the description says it shall be time formatted according to ISO 8601. One thought I had at a time was to "invent" special units, like unit: VIN , unit: color and describe the expected formatting as a comment in the unit file. Then one could even possibly add a regexp to the unit definition file which tooling/servers/client possibly could use for validation.

I would not use the unit for something that is not a unit. However, the approach taken for handling units could be reused with a new field. So, instead of defining that as a unit, we can do it as format (or some similar keyword).

@erikbosch
Copy link
Collaborator

I came up with a possible but maybe somewhat ugly idea for the string datatype. We have already min and max attributes, we typically use them today just for int/float values. We could possibly give them a different semantic meaning for signals of type string and string[] and let them indicate min/max length for the string (excluding trailing null).

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