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

Removing tags pattern since we can't use this with check-jsonschema. #8

Closed
wants to merge 1 commit into from

Conversation

djgoku
Copy link

@djgoku djgoku commented Oct 27, 2023

I am wanting to add validating AWS ECS task definitions using the schema.json as part of check-jsonschema. Which then can checked via a pre-commit hook.

But the probably I am having is show below and it centers around tags pattern.

I have tested intellisense with VS Code and my schema.json which doesn't have tags pattern and it still works great.

For context here is the errors I see without and with tags pattern. Here is a valid AWS ECS task definition and here is the invalid AWS ECS task definition.

Without tags pattern happy path:

$ check-jsonschema --schemafile https://raw.githubusercontent.com/djgoku/amazon-ecs-intellisense-schema/chore/remove-tag-pattern/src/model/schema/schema.json tests/example-files/hooks/positive/aws-ecs-task-definition/ecs-anywhere-runtask-task-definition.json 
ok -- validation done

Without tags pattern fail path:

$ check-jsonschema --schemafile https://raw.githubusercontent.com/djgoku/amazon-ecs-intellisense-schema/chore/remove-tag-pattern/src/model/schema/schema.json tests/example-files/hooks/negative/aws-ecs-task-definition/aws-ecs-task-definition.json 
Schema validation errors were encountered.
  tests/example-files/hooks/negative/aws-ecs-task-definition/aws-ecs-task-definition.json::$: 'family' is a required property
  tests/example-files/hooks/negative/aws-ecs-task-definition/aws-ecs-task-definition.json::$: 'containerDefinitions' is a required property

With current tags pattern happy path:

$ check-jsonschema --schemafile https://raw.githubusercontent.com/awslabs/amazon-ecs-intellisense-schema/mainline/src/model/schema/schema.json tests/example-files/hooks/positive/aws-ecs-task-definition/ecs-anywhere-runtask-task-definition.json 
Error: schemafile was not valid: {'type': 'object', 'properties': {'key': {'description': 'One part of a key-value pair that make up a tag. A key is a general label that acts like a category for more specific tag values.', 'type': 'string', 'maxLength': 128, 'minLength': 1, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}, 'value': {'description': 'The optional part of a key-value pair that make up a tag. A value acts as a descriptor within a tag category (key).', 'type': 'string', 'maxLength': 256, 'minLength': 0, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}}, 'additionalProperties': False} is not valid under any of the given schemas

Failed validating 'anyOf' in metaschema['properties']['properties']['additionalProperties']['properties']['items']:
    {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}],
     'default': True}

On schema['properties']['tags']['items']:
    {'additionalProperties': False,
     'properties': {'key': {'description': 'One part of a key-value pair '
                                           'that make up a tag. A key is a '
                                           'general label that acts like a '
                                           'category for more specific tag '
                                           'values.',
                            'maxLength': 128,
                            'minLength': 1,
                            'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                            'type': 'string'},
                    'value': {'description': 'The optional part of a '
                                             'key-value pair that make up '
                                             'a tag. A value acts as a '
                                             'descriptor within a tag '
                                             'category (key).',
                              'maxLength': 256,
                              'minLength': 0,
                              'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                              'type': 'string'}},
     'type': 'object'}

SchemaError: {'type': 'object', 'properties': {'key': {'description': 'One part of a key-value pair that make up a tag. A key is a general label that acts like a category for more specific tag values.', 'type': 'string', 'maxLength': 128, 'minLength': 1, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}, 'value': {'description': 'The optional part of a key-value pair that make up a tag. A value acts as a descriptor within a tag category (key).', 'type': 'string', 'maxLength': 256, 'minLength': 0, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}}, 'additionalProperties': False} is not valid under any of the given schemas

Failed validating 'anyOf' in metaschema['properties']['properties']['additionalProperties']['properties']['items']:
    {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}],
     'default': True}

On schema['properties']['tags']['items']:
    {'additionalProperties': False,
     'properties': {'key': {'description': 'One part of a key-value pair '
                                           'that make up a tag. A key is a '
                                           'general label that acts like a '
                                           'category for more specific tag '
                                           'values.',
                            'maxLength': 128,
                            'minLength': 1,
                            'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                            'type': 'string'},
                    'value': {'description': 'The optional part of a '
                                             'key-value pair that make up '
                                             'a tag. A value acts as a '
                                             'descriptor within a tag '
                                             'category (key).',
                              'maxLength': 256,
                              'minLength': 0,
                              'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                              'type': 'string'}},
     'type': 'object'}
  in "/Users/dj_goku/dev/github/djgoku/check-jsonschema/.venv/lib/python3.10/site-packages/check_jsonschema/checker.py", line 53
  >>> return self._schema_loader.get_validator(

With current tags pattern fail path:

$ check-jsonschema --schemafile https://raw.githubusercontent.com/awslabs/amazon-ecs-intellisense-schema/mainline/src/model/schema/schema.json tests/example-files/hooks/negative/aws-ecs-task-definition/aws-ecs-task-definition.json 
Error: schemafile was not valid: {'type': 'object', 'properties': {'key': {'description': 'One part of a key-value pair that make up a tag. A key is a general label that acts like a category for more specific tag values.', 'type': 'string', 'maxLength': 128, 'minLength': 1, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}, 'value': {'description': 'The optional part of a key-value pair that make up a tag. A value acts as a descriptor within a tag category (key).', 'type': 'string', 'maxLength': 256, 'minLength': 0, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}}, 'additionalProperties': False} is not valid under any of the given schemas

Failed validating 'anyOf' in metaschema['properties']['properties']['additionalProperties']['properties']['items']:
    {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}],
     'default': True}

On schema['properties']['tags']['items']:
    {'additionalProperties': False,
     'properties': {'key': {'description': 'One part of a key-value pair '
                                           'that make up a tag. A key is a '
                                           'general label that acts like a '
                                           'category for more specific tag '
                                           'values.',
                            'maxLength': 128,
                            'minLength': 1,
                            'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                            'type': 'string'},
                    'value': {'description': 'The optional part of a '
                                             'key-value pair that make up '
                                             'a tag. A value acts as a '
                                             'descriptor within a tag '
                                             'category (key).',
                              'maxLength': 256,
                              'minLength': 0,
                              'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                              'type': 'string'}},
     'type': 'object'}

SchemaError: {'type': 'object', 'properties': {'key': {'description': 'One part of a key-value pair that make up a tag. A key is a general label that acts like a category for more specific tag values.', 'type': 'string', 'maxLength': 128, 'minLength': 1, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}, 'value': {'description': 'The optional part of a key-value pair that make up a tag. A value acts as a descriptor within a tag category (key).', 'type': 'string', 'maxLength': 256, 'minLength': 0, 'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$'}}, 'additionalProperties': False} is not valid under any of the given schemas

Failed validating 'anyOf' in metaschema['properties']['properties']['additionalProperties']['properties']['items']:
    {'anyOf': [{'$ref': '#'}, {'$ref': '#/definitions/schemaArray'}],
     'default': True}

On schema['properties']['tags']['items']:
    {'additionalProperties': False,
     'properties': {'key': {'description': 'One part of a key-value pair '
                                           'that make up a tag. A key is a '
                                           'general label that acts like a '
                                           'category for more specific tag '
                                           'values.',
                            'maxLength': 128,
                            'minLength': 1,
                            'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                            'type': 'string'},
                    'value': {'description': 'The optional part of a '
                                             'key-value pair that make up '
                                             'a tag. A value acts as a '
                                             'descriptor within a tag '
                                             'category (key).',
                              'maxLength': 256,
                              'minLength': 0,
                              'pattern': '^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]*)$',
                              'type': 'string'}},
     'type': 'object'}
  in "/Users/dj_goku/dev/github/djgoku/check-jsonschema/.venv/lib/python3.10/site-packages/check_jsonschema/checker.py", line 53
  >>> return self._schema_loader.get_validator(

@djgoku
Copy link
Author

djgoku commented Nov 14, 2023

@pallymore are you able to do a review?

@pallymore
Copy link
Contributor

Hi - thanks for your contribution!

I think the root cause of the problem is that Python does not support unicode characters/properties Regex (e.g. \p{L} \p{Z} \p{N} ) - it's not really an issue with the schema itself. The schema provided in this repo is automatically generated from aws-sdk, and it's meant to be used with Intellisense (JSON LSPs, various editors) - unfortunately we are not able to support your use case at the moment. Also since the file is automatically generated, manual changes here will be overwritten by the next release 😅

For now, I'd recommend maybe looking into a different CLI tool for the schema validation. Thanks again

@djgoku
Copy link
Author

djgoku commented Nov 14, 2023

@pallymore I really appreciate you replying so quickly!

You have really helped me in understanding the problem.

@sirosen
Copy link

sirosen commented Nov 14, 2023

Hi there! check-jsonschema maintainer here. I'm just seeing this and wanted to check/ask a quick question:

Are the patterns used JavaScript/ECMA regexes?
I'm using a Rust backend for JS regex syntax, so I'm going to want to hunt through the info here when I have more time to see exactly what fails.

Any time you can spare to help point me in the right direction for this user is much appreciated!

@pallymore
Copy link
Contributor

pallymore commented Nov 14, 2023

The pattern is only supported when the u flag is used. See:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode#description

The JSON language server adds the u flag by default - which is why it works there 😅 https://github.com/microsoft/vscode-json-languageservice/blob/main/src/utils/strings.ts#L57

More info about these unicode patterns: https://www.regular-expressions.info/unicode.html

@sirosen
Copy link

sirosen commented Nov 14, 2023

Thanks much! It's going to take me some time to figure out what my options are, but at least now I have some solid starting points.

@djgoku djgoku deleted the chore/remove-tag-pattern branch December 30, 2023 01:04
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

Successfully merging this pull request may close these issues.

3 participants