diff --git a/dev_scripts/update_to_aas_core_meta_and_codegen.py b/dev_scripts/update_to_aas_core_meta_and_codegen.py index 164126b8f..d34282d14 100644 --- a/dev_scripts/update_to_aas_core_meta_and_codegen.py +++ b/dev_scripts/update_to_aas_core_meta_and_codegen.py @@ -25,6 +25,11 @@ # exactly that meta-model version. import aas_core_meta.v3 +import aas_core_codegen.jsonschema.main +import aas_core_codegen.run +import aas_core_codegen.specific_implementations +import aas_core_codegen.common + AAS_CORE_META_DEPENDENCY_RE = re.compile( r"aas-core-meta@git\+https://github.com/aas-core-works/aas-core-meta@([a-fA-F0-9]+)#egg=aas-core-meta" ) @@ -35,7 +40,7 @@ def _make_sure_no_changed_files( - repo_dir: pathlib.Path, expected_branch: str + repo_dir: pathlib.Path, expected_branch: str ) -> Optional[int]: """ Make sure that no files are modified in the given repository. @@ -63,8 +68,7 @@ def _make_sure_no_changed_files( def _update_setup_py( - our_repo: pathlib.Path, aas_core_meta_revision: str, - aas_core_codegen_revision: str + our_repo: pathlib.Path, aas_core_meta_revision: str, aas_core_codegen_revision: str ) -> None: """Update the aas-core-meta in setup.py.""" setup_py = our_repo / "setup.py" @@ -88,7 +92,7 @@ def _update_setup_py( def _uninstall_and_install_aas_core_meta( - our_repo: pathlib.Path, aas_core_meta_revision: str + our_repo: pathlib.Path, aas_core_meta_revision: str ) -> None: """Uninstall and install the latest aas-core-meta in the virtual environment.""" subprocess.check_call( @@ -108,7 +112,7 @@ def _uninstall_and_install_aas_core_meta( def _uninstall_and_install_aas_core_codegen( - our_repo: pathlib.Path, aas_core_codegen_revision: str + our_repo: pathlib.Path, aas_core_codegen_revision: str ) -> None: """Uninstall and install the latest aas-core-codegen in the virtual environment.""" subprocess.check_call( @@ -127,15 +131,15 @@ def _uninstall_and_install_aas_core_codegen( ) -def _copy_python_sdk_and_schemas_from_aas_core_codegen( - aas_core_codegen_repo: pathlib.Path, - our_repo: pathlib.Path, - aas_core_codegen_revision: str, +def _copy_python_sdk_and_xml_schema_from_aas_core_codegen( + aas_core_codegen_repo: pathlib.Path, + our_repo: pathlib.Path, + aas_core_codegen_revision: str, ) -> None: """Copy the generated Python SDK from aas-core-codegen's test data.""" source_dir = ( - aas_core_codegen_repo - / "test_data/python/test_main/aas_core_meta.v3/expected_output" + aas_core_codegen_repo + / "test_data/python/test_main/aas_core_meta.v3/expected_output" ) target_dir = our_repo / "aas_core3" @@ -157,12 +161,6 @@ def _copy_python_sdk_and_schemas_from_aas_core_codegen( ''' init_py.write_text(text, encoding="utf-8") - shutil.copy( - aas_core_codegen_repo - / "test_data/jsonschema/test_main/aas_core_meta.v3/expected_output/schema.json", - our_repo / "test_data/schema.json", - ) - shutil.copy( aas_core_codegen_repo / "test_data/xsd/test_main/aas_core_meta.v3/expected_output/schema.xsd", @@ -170,9 +168,56 @@ def _copy_python_sdk_and_schemas_from_aas_core_codegen( ) +def _generate_jsonschema_for_python( + our_repo: pathlib.Path, +) -> None: + model_path = pathlib.Path(aas_core_meta.v3.__file__) + symbol_table_atok, error = aas_core_codegen.run.load_model(model_path=model_path) + assert error is None, f"Unexpected error loading {model_path}: {error}" + assert symbol_table_atok is not None + + symbol_table, _ = symbol_table_atok + + text, errors = aas_core_codegen.jsonschema.main.generate( + symbol_table=symbol_table, + spec_impls={ + aas_core_codegen.specific_implementations.ImplementationKey( + "schema_base.json" + ): aas_core_codegen.common.Stripped( + """\ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "title": "AssetAdministrationShellEnvironment", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/Environment" + } + ] +}""" + ) + }, + # NOTE (mristin): + # We rely that the aas-core-meta uses Python-conform regular expressions, + # which jsonschema library can readily use as well. + fix_pattern=lambda pattern: pattern, + ) + + if errors is not None: + errors_joined = "\n\n".join(error.message for error in errors) + raise AssertionError( + f"Unexpected errors when generating the Python-conform JSON schema:\n" + f"{errors_joined}" + ) + + assert text is not None + + (our_repo / "test_data/schema.json").write_text(text, encoding="utf-8") + + def _run_in_parallel( - calls: Sequence[Callable[[], subprocess.Popen[AnyStr]]], - on_status_update: Callable[[int], None], + calls: Sequence[Callable[[], subprocess.Popen[AnyStr]]], + on_status_update: Callable[[int], None], ) -> Optional[int]: """ Run the given scripts in parallel. @@ -301,9 +346,9 @@ def _run_tests_in_parallel(our_repo: pathlib.Path) -> Optional[int]: f"tests.{pth.stem}" for pth in (our_repo / "tests").glob("test_*.py") if ( - pth.is_file() - and not pth.name.startswith("__") - and not pth.name.startswith(".") + pth.is_file() + and not pth.name.startswith("__") + and not pth.name.startswith(".") ) ] @@ -367,23 +412,18 @@ def _generate_test_data(our_repo: pathlib.Path) -> Optional[int]: for name in ("generate_json.py", "generate_rdf.py", "generate_xml.py") ] - # pylint: disable=consider-using-with - commands = [ - [ + start = time.perf_counter() + + for script in scripts: + command = [ sys.executable, str(script), "--model_path", aas_core_meta.v3.__file__, "--test_data_dir", - test_data_dir, + str(test_data_dir), ] - for script in scripts - ] - # pylint: enable=consider-using-with - start = time.perf_counter() - - for command in commands: command_escaped = " ".join(shlex.quote(part) for part in command) print(f"Running: {command_escaped}") subprocess.check_call(command, cwd=str(our_repo)) @@ -395,8 +435,7 @@ def _generate_test_data(our_repo: pathlib.Path) -> Optional[int]: def _create_branch_commit_and_push( - our_repo: pathlib.Path, aas_core_meta_revision: str, - aas_core_codegen_revision: str + our_repo: pathlib.Path, aas_core_meta_revision: str, aas_core_codegen_revision: str ) -> None: """Create a feature branch, commit the changes and push it.""" branch = ( @@ -593,7 +632,9 @@ def main() -> int: our_repo=our_repo, aas_core_codegen_revision=aas_core_codegen_revision ) - _copy_python_sdk_and_schemas_from_aas_core_codegen( + _generate_jsonschema_for_python(our_repo=our_repo) + + _copy_python_sdk_and_xml_schema_from_aas_core_codegen( aas_core_codegen_repo=aas_core_codegen_repo, our_repo=our_repo, aas_core_codegen_revision=aas_core_codegen_revision, diff --git a/setup.py b/setup.py index 70fa74277..41357cfd1 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ "icontract>=2.5.2,<3", "networkx==2.8", "typing-extensions==4.5.0", - "aas-core-codegen@git+https://github.com/aas-core-works/aas-core-codegen@4433d092#egg=aas-core-codegen", + "aas-core-codegen@git+https://github.com/aas-core-works/aas-core-codegen@c77b7dc6#egg=aas-core-codegen", ], # fmt: off extras_require={ diff --git a/test_data/schema.json b/test_data/schema.json index b66c9a8ed..b6c7d531b 100644 --- a/test_data/schema.json +++ b/test_data/schema.json @@ -36,12 +36,12 @@ "properties": { "language": { "type": "string", - "pattern": "^(([a-zA-Z]{2,3}(-[a-zA-Z]{3}(-[a-zA-Z]{3}){0,2})?|[a-zA-Z]{4}|[a-zA-Z]{5,8})(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-(([a-zA-Z0-9]){5,8}|[0-9]([a-zA-Z0-9]){3}))*(-[0-9A-WY-Za-wy-z](-([a-zA-Z0-9]){2,8})+)*(-[xX](-([a-zA-Z0-9]){1,8})+)?|[xX](-([a-zA-Z0-9]){1,8})+|((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)))$" + "pattern": "^(([a-zA-Z]{2,3}(-[a-zA-Z]{3}(-[a-zA-Z]{3}){,2})?|[a-zA-Z]{4}|[a-zA-Z]{5,8})(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-(([a-zA-Z0-9]){5,8}|[0-9]([a-zA-Z0-9]){3}))*(-[0-9A-WY-Za-wy-z](-([a-zA-Z0-9]){2,8})+)*(-[xX](-([a-zA-Z0-9]){1,8})+)?|[xX](-([a-zA-Z0-9]){1,8})+|((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)))$" }, "text": { "type": "string", "minLength": 1, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" } }, "required": [ @@ -64,7 +64,7 @@ "maxLength": 4 }, { - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, { "pattern": "^(0|[1-9][0-9]*)$" @@ -79,7 +79,7 @@ "maxLength": 4 }, { - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, { "pattern": "^(0|[1-9][0-9]*)$" @@ -93,7 +93,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" } } } @@ -163,7 +163,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "specificAssetIds": { "type": "array", @@ -176,7 +176,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "defaultThumbnail": { "$ref": "#/definitions/Resource" @@ -214,7 +214,7 @@ "type": "string", "minLength": 1, "maxLength": 255, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "messageBroker": { "$ref": "#/definitions/Reference" @@ -262,10 +262,10 @@ "maxLength": 100 }, { - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, { - "pattern": "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\\t !-~]|[\\x80-\\xff]))*\"))*$" + "pattern": "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \t]*;[ \t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\t !-~]|[\\x80-\\xff]))*\"))*$" } ] }, @@ -384,7 +384,7 @@ "unit": { "type": "string", "minLength": 1, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "unitId": { "$ref": "#/definitions/Reference" @@ -392,12 +392,12 @@ "sourceOfDefinition": { "type": "string", "minLength": 1, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "symbol": { "type": "string", "minLength": 1, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "dataType": { "$ref": "#/definitions/DataTypeIec61360" @@ -412,7 +412,7 @@ "valueFormat": { "type": "string", "minLength": 1, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "valueList": { "$ref": "#/definitions/ValueList" @@ -421,7 +421,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "levelType": { "$ref": "#/definitions/LevelType" @@ -538,7 +538,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "specificAssetIds": { "type": "array", @@ -612,7 +612,7 @@ "type": "string", "minLength": 1, "maxLength": 255, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "subjectId": { "$ref": "#/definitions/Reference" @@ -643,7 +643,7 @@ "type": "string", "minLength": 1, "maxLength": 128, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "valueType": { "$ref": "#/definitions/DataTypeDefXsd" @@ -676,7 +676,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "contentType": { "type": "string", @@ -686,10 +686,10 @@ "maxLength": 100 }, { - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, { - "pattern": "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\\t !-~]|[\\x80-\\xff]))*\"))*$" + "pattern": "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \t]*;[ \t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\t !-~]|[\\x80-\\xff]))*\"))*$" } ] }, @@ -764,7 +764,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" } }, "required": [ @@ -783,7 +783,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" } }, "required": [ @@ -1071,7 +1071,7 @@ "type": "string", "minLength": 1, "maxLength": 128, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "valueType": { "$ref": "#/definitions/DataTypeDefXsd" @@ -1135,7 +1135,7 @@ "type": "string", "minLength": 1, "maxLength": 128, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "idShort": { "type": "string", @@ -1145,7 +1145,7 @@ "maxLength": 128 }, { - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, { "pattern": "^[a-zA-Z][a-zA-Z0-9_]*$" @@ -1274,7 +1274,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "contentType": { "type": "string", @@ -1284,10 +1284,10 @@ "maxLength": 100 }, { - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, { - "pattern": "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\\t !-~]|[\\x80-\\xff]))*\"))*$" + "pattern": "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \t]*;[ \t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\t !-~]|[\\x80-\\xff]))*\"))*$" } ] } @@ -1307,13 +1307,13 @@ "type": "string", "minLength": 1, "maxLength": 64, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "value": { "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "externalSubjectId": { "$ref": "#/definitions/Reference" @@ -1507,7 +1507,7 @@ "type": "string", "minLength": 1, "maxLength": 2000, - "pattern": "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" + "pattern": "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" }, "valueId": { "$ref": "#/definitions/Reference" diff --git a/tests/test_jsonschema_library.py b/tests/test_jsonschema_library.py new file mode 100644 index 000000000..7c8ed88d0 --- /dev/null +++ b/tests/test_jsonschema_library.py @@ -0,0 +1,28 @@ +"""Test the intricacies of the JSON schema library we use for the tests.""" + +# pylint: disable=missing-docstring + +import re +import unittest + +import jsonschema + + +class TestUnicode(unittest.TestCase): + def test_for_above_bmp(self) -> None: + schema = { + "type": "string", + "pattern": ( + "^[\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\U00010000-\\U0010FFFF]*$" + ), + } + assert re.match( + schema["pattern"], + "\U000fe800" + ) + + jsonschema.validate(instance='"\U000fe800"', schema=schema) + + +if __name__ == "__main__": + unittest.main()