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

JSON schema: problems with pattern values #567

Open
lsloan opened this issue Sep 26, 2023 · 0 comments
Open

JSON schema: problems with pattern values #567

lsloan opened this issue Sep 26, 2023 · 0 comments

Comments

@lsloan
Copy link
Member

lsloan commented Sep 26, 2023

I'm very happy to see the work @bracken put into the JSON schema. They are awesome! (I'm referring to the ones currently in json_schema/schema_1_1 on the json_schema branch.)

https://github.com/1EdTech/caliper-spec/tree/json_schema/json_schema/schema_1_1

However, the regular expression values used for pattern properties cause problems with validation of JSON. For example, consider two instances of pattern in json_schema/schema_1_1/Agent.json

  1. On line 115, for @context

              "pattern": "^http://purl.imsglobal.org/ctx/caliper/v1p1$"

    That regex is invalid. (See: https://regex101.com/r/ZeE6Gk/1) The "/" and "." characters need to be escaped because they have special meaning in a regex. Depending on which regex engine is used during the validation, the JSON input may always be marked as invalid, even when the value of its @context property is http://purl.imsglobal.org/ctx/caliper/v1p1.

  2. On line 109, for type

          "pattern": "^Agent$"

    The regex is valid, but this is an inefficient use of regex. Additionally, I found that using some JSON schema tools to generate JSON based on the schema would set the value of type to the literal string, "^Agent$". (True, that's mostly a problem with the tool I used, but the use of regex here is unnecessary.)

In each of those cases, the problems could be avoided by using const instead of pattern properties in the JSON schema. That applies to almost all the uses of pattern in the all of the JSON schema files. The only places you may need to use regexes are…

  • UUID value of id in CaliperData.json. (Although there may now be a uuid JSON schema type available.)
  • URL value of @context in AggregateMeasure.json, AggregateMeasureCollection.json, Collection.json, Link.json, LtiLink.json, and ToolLaunchEvent.json. In those cases, it looks like the intention is to allow the optional -extension at the end of the URL. However, the "/" and "." characters in the first part of the regexes make them invalid.
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

1 participant