aas-core-codegen 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aas_core_codegen/__init__.py +6 -0
- aas_core_codegen/__main__.py +8 -0
- aas_core_codegen/common.py +500 -0
- aas_core_codegen/cpp/__init__.py +1 -0
- aas_core_codegen/cpp/aas_common/__init__.py +6 -0
- aas_core_codegen/cpp/aas_common/_generate.py +713 -0
- aas_core_codegen/cpp/common.py +681 -0
- aas_core_codegen/cpp/constants/__init__.py +6 -0
- aas_core_codegen/cpp/constants/_generate.py +568 -0
- aas_core_codegen/cpp/description.py +654 -0
- aas_core_codegen/cpp/enhancing/__init__.py +4 -0
- aas_core_codegen/cpp/enhancing/_generate.py +993 -0
- aas_core_codegen/cpp/iteration/__init__.py +6 -0
- aas_core_codegen/cpp/iteration/_generate.py +2332 -0
- aas_core_codegen/cpp/jsonization/__init__.py +6 -0
- aas_core_codegen/cpp/jsonization/_generate.py +2619 -0
- aas_core_codegen/cpp/main.py +694 -0
- aas_core_codegen/cpp/naming.py +170 -0
- aas_core_codegen/cpp/optionaling.py +557 -0
- aas_core_codegen/cpp/pattern/__init__.py +6 -0
- aas_core_codegen/cpp/pattern/_generate.py +508 -0
- aas_core_codegen/cpp/revm/__init__.py +6 -0
- aas_core_codegen/cpp/revm/_generate.py +1149 -0
- aas_core_codegen/cpp/stringification/__init__.py +5 -0
- aas_core_codegen/cpp/stringification/_generate.py +955 -0
- aas_core_codegen/cpp/structure/__init__.py +7 -0
- aas_core_codegen/cpp/structure/_generate.py +1503 -0
- aas_core_codegen/cpp/transpilation.py +1383 -0
- aas_core_codegen/cpp/unrolling.py +159 -0
- aas_core_codegen/cpp/verification/__init__.py +6 -0
- aas_core_codegen/cpp/verification/_generate.py +3073 -0
- aas_core_codegen/cpp/visitation/__init__.py +6 -0
- aas_core_codegen/cpp/visitation/_generate.py +521 -0
- aas_core_codegen/cpp/wstringification/__init__.py +5 -0
- aas_core_codegen/cpp/wstringification/_generate.py +586 -0
- aas_core_codegen/cpp/xmlization/__init__.py +6 -0
- aas_core_codegen/cpp/xmlization/_generate.py +5373 -0
- aas_core_codegen/cpp/yielding.py +201 -0
- aas_core_codegen/csharp/__init__.py +1 -0
- aas_core_codegen/csharp/common.py +224 -0
- aas_core_codegen/csharp/constants/__init__.py +5 -0
- aas_core_codegen/csharp/constants/_generate.py +409 -0
- aas_core_codegen/csharp/copying/__init__.py +4 -0
- aas_core_codegen/csharp/copying/_generate.py +498 -0
- aas_core_codegen/csharp/description.py +1103 -0
- aas_core_codegen/csharp/enhancing/__init__.py +4 -0
- aas_core_codegen/csharp/enhancing/_generate.py +667 -0
- aas_core_codegen/csharp/jsonization/__init__.py +4 -0
- aas_core_codegen/csharp/jsonization/_generate.py +1630 -0
- aas_core_codegen/csharp/main.py +421 -0
- aas_core_codegen/csharp/naming.py +157 -0
- aas_core_codegen/csharp/reporting/__init__.py +4 -0
- aas_core_codegen/csharp/reporting/_generate.py +266 -0
- aas_core_codegen/csharp/stringification/__init__.py +4 -0
- aas_core_codegen/csharp/stringification/_generate.py +243 -0
- aas_core_codegen/csharp/structure/__init__.py +6 -0
- aas_core_codegen/csharp/structure/_generate.py +1341 -0
- aas_core_codegen/csharp/transpilation.py +990 -0
- aas_core_codegen/csharp/unrolling.py +211 -0
- aas_core_codegen/csharp/verification/__init__.py +6 -0
- aas_core_codegen/csharp/verification/_generate.py +1457 -0
- aas_core_codegen/csharp/visitation/__init__.py +5 -0
- aas_core_codegen/csharp/visitation/_generate.py +579 -0
- aas_core_codegen/csharp/xmlization/__init__.py +4 -0
- aas_core_codegen/csharp/xmlization/_generate.py +1980 -0
- aas_core_codegen/golang/__init__.py +1 -0
- aas_core_codegen/golang/aas_common/__init__.py +4 -0
- aas_core_codegen/golang/aas_common/_generate.py +152 -0
- aas_core_codegen/golang/common.py +303 -0
- aas_core_codegen/golang/constants/__init__.py +5 -0
- aas_core_codegen/golang/constants/_generate.py +339 -0
- aas_core_codegen/golang/description.py +501 -0
- aas_core_codegen/golang/enhancing/__init__.py +4 -0
- aas_core_codegen/golang/enhancing/_generate.py +527 -0
- aas_core_codegen/golang/jsonization/__init__.py +4 -0
- aas_core_codegen/golang/jsonization/_generate.py +1740 -0
- aas_core_codegen/golang/main.py +368 -0
- aas_core_codegen/golang/naming.py +412 -0
- aas_core_codegen/golang/pointering.py +631 -0
- aas_core_codegen/golang/reporting/__init__.py +4 -0
- aas_core_codegen/golang/reporting/_generate.py +218 -0
- aas_core_codegen/golang/stringification/__init__.py +4 -0
- aas_core_codegen/golang/stringification/_generate.py +394 -0
- aas_core_codegen/golang/structure/__init__.py +6 -0
- aas_core_codegen/golang/structure/_generate.py +1493 -0
- aas_core_codegen/golang/transpilation.py +1191 -0
- aas_core_codegen/golang/unrolling.py +159 -0
- aas_core_codegen/golang/verification/__init__.py +6 -0
- aas_core_codegen/golang/verification/_generate.py +1513 -0
- aas_core_codegen/golang/xmlization/__init__.py +4 -0
- aas_core_codegen/golang/xmlization/_generate.py +2507 -0
- aas_core_codegen/infer_for_schema/__init__.py +21 -0
- aas_core_codegen/infer_for_schema/_inline.py +693 -0
- aas_core_codegen/infer_for_schema/_len.py +527 -0
- aas_core_codegen/infer_for_schema/_pattern.py +311 -0
- aas_core_codegen/infer_for_schema/_set.py +394 -0
- aas_core_codegen/infer_for_schema/_stringify.py +201 -0
- aas_core_codegen/infer_for_schema/_types.py +135 -0
- aas_core_codegen/infer_for_schema/match.py +122 -0
- aas_core_codegen/intermediate/__init__.py +78 -0
- aas_core_codegen/intermediate/_hierarchy.py +397 -0
- aas_core_codegen/intermediate/_stringify.py +989 -0
- aas_core_codegen/intermediate/_translate.py +5128 -0
- aas_core_codegen/intermediate/_types.py +2901 -0
- aas_core_codegen/intermediate/construction.py +750 -0
- aas_core_codegen/intermediate/doc.py +344 -0
- aas_core_codegen/intermediate/pattern_verification.py +428 -0
- aas_core_codegen/intermediate/revm.py +985 -0
- aas_core_codegen/intermediate/type_inference.py +2266 -0
- aas_core_codegen/java/__init__.py +1 -0
- aas_core_codegen/java/common.py +197 -0
- aas_core_codegen/java/constants/__init__.py +5 -0
- aas_core_codegen/java/constants/_generate.py +334 -0
- aas_core_codegen/java/copying/__init__.py +4 -0
- aas_core_codegen/java/copying/_generate.py +502 -0
- aas_core_codegen/java/description.py +774 -0
- aas_core_codegen/java/enhancing/__init__.py +4 -0
- aas_core_codegen/java/enhancing/_generate.py +820 -0
- aas_core_codegen/java/generation/__init__.py +5 -0
- aas_core_codegen/java/generation/_generate.py +285 -0
- aas_core_codegen/java/jsonization/__init__.py +4 -0
- aas_core_codegen/java/jsonization/_generate.py +1472 -0
- aas_core_codegen/java/main.py +438 -0
- aas_core_codegen/java/naming.py +187 -0
- aas_core_codegen/java/optional.py +514 -0
- aas_core_codegen/java/reporting/__init__.py +4 -0
- aas_core_codegen/java/reporting/_generate.py +248 -0
- aas_core_codegen/java/stringification/__init__.py +4 -0
- aas_core_codegen/java/stringification/_generate.py +212 -0
- aas_core_codegen/java/structure/__init__.py +6 -0
- aas_core_codegen/java/structure/_generate.py +1767 -0
- aas_core_codegen/java/transpilation.py +1111 -0
- aas_core_codegen/java/verification/__init__.py +6 -0
- aas_core_codegen/java/verification/_generate.py +1536 -0
- aas_core_codegen/java/visitation/__init__.py +5 -0
- aas_core_codegen/java/visitation/_generate.py +689 -0
- aas_core_codegen/java/xmlization/__init__.py +4 -0
- aas_core_codegen/java/xmlization/_generate.py +2274 -0
- aas_core_codegen/jsonld/__init__.py +1 -0
- aas_core_codegen/jsonld/main.py +455 -0
- aas_core_codegen/jsonschema/__init__.py +1 -0
- aas_core_codegen/jsonschema/main.py +982 -0
- aas_core_codegen/main.py +245 -0
- aas_core_codegen/naming.py +133 -0
- aas_core_codegen/opcua/__init__.py +1 -0
- aas_core_codegen/opcua/main.py +1525 -0
- aas_core_codegen/opcua/naming.py +126 -0
- aas_core_codegen/parse/__init__.py +46 -0
- aas_core_codegen/parse/_rules.py +796 -0
- aas_core_codegen/parse/_stringify.py +532 -0
- aas_core_codegen/parse/_translate.py +3940 -0
- aas_core_codegen/parse/_types.py +973 -0
- aas_core_codegen/parse/retree/__init__.py +46 -0
- aas_core_codegen/parse/retree/_fix.py +434 -0
- aas_core_codegen/parse/retree/_parse.py +1143 -0
- aas_core_codegen/parse/retree/_render.py +298 -0
- aas_core_codegen/parse/retree/_stringify.py +199 -0
- aas_core_codegen/parse/retree/_types.py +362 -0
- aas_core_codegen/parse/retree/_visitor.py +70 -0
- aas_core_codegen/parse/tree.py +1303 -0
- aas_core_codegen/protobuf/__init__.py +1 -0
- aas_core_codegen/protobuf/common.py +225 -0
- aas_core_codegen/protobuf/description.py +1102 -0
- aas_core_codegen/protobuf/main.py +115 -0
- aas_core_codegen/protobuf/naming.py +143 -0
- aas_core_codegen/protobuf/structure/__init__.py +6 -0
- aas_core_codegen/protobuf/structure/_generate.py +502 -0
- aas_core_codegen/py.typed +1 -0
- aas_core_codegen/python/__init__.py +1 -0
- aas_core_codegen/python/aas_common/__init__.py +4 -0
- aas_core_codegen/python/aas_common/_generate.py +63 -0
- aas_core_codegen/python/common.py +406 -0
- aas_core_codegen/python/constants/__init__.py +5 -0
- aas_core_codegen/python/constants/_generate.py +377 -0
- aas_core_codegen/python/description.py +508 -0
- aas_core_codegen/python/jsonization/__init__.py +4 -0
- aas_core_codegen/python/jsonization/_generate.py +1391 -0
- aas_core_codegen/python/main.py +323 -0
- aas_core_codegen/python/naming.py +255 -0
- aas_core_codegen/python/stringification/__init__.py +4 -0
- aas_core_codegen/python/stringification/_generate.py +129 -0
- aas_core_codegen/python/structure/__init__.py +6 -0
- aas_core_codegen/python/structure/_generate.py +1801 -0
- aas_core_codegen/python/transpilation.py +958 -0
- aas_core_codegen/python/unrolling.py +156 -0
- aas_core_codegen/python/verification/__init__.py +6 -0
- aas_core_codegen/python/verification/_generate.py +1471 -0
- aas_core_codegen/python/xmlization/__init__.py +4 -0
- aas_core_codegen/python/xmlization/_generate.py +3003 -0
- aas_core_codegen/python_protobuf/__init__.py +1 -0
- aas_core_codegen/python_protobuf/main.py +1424 -0
- aas_core_codegen/python_protobuf/naming.py +85 -0
- aas_core_codegen/rdf_shacl/__init__.py +1 -0
- aas_core_codegen/rdf_shacl/_description.py +351 -0
- aas_core_codegen/rdf_shacl/common.py +206 -0
- aas_core_codegen/rdf_shacl/main.py +114 -0
- aas_core_codegen/rdf_shacl/naming.py +145 -0
- aas_core_codegen/rdf_shacl/rdf.py +435 -0
- aas_core_codegen/rdf_shacl/shacl.py +453 -0
- aas_core_codegen/run.py +124 -0
- aas_core_codegen/smoke/__init__.py +1 -0
- aas_core_codegen/smoke/main.py +219 -0
- aas_core_codegen/specific_implementations.py +72 -0
- aas_core_codegen/stringify.py +333 -0
- aas_core_codegen/typescript/__init__.py +1 -0
- aas_core_codegen/typescript/aas_common/__init__.py +4 -0
- aas_core_codegen/typescript/aas_common/_generate.py +472 -0
- aas_core_codegen/typescript/common.py +340 -0
- aas_core_codegen/typescript/constants/__init__.py +5 -0
- aas_core_codegen/typescript/constants/_generate.py +347 -0
- aas_core_codegen/typescript/description.py +530 -0
- aas_core_codegen/typescript/jsonization/__init__.py +4 -0
- aas_core_codegen/typescript/jsonization/_generate.py +1510 -0
- aas_core_codegen/typescript/main.py +258 -0
- aas_core_codegen/typescript/naming.py +189 -0
- aas_core_codegen/typescript/stringification/__init__.py +4 -0
- aas_core_codegen/typescript/stringification/_generate.py +367 -0
- aas_core_codegen/typescript/structure/__init__.py +6 -0
- aas_core_codegen/typescript/structure/_generate.py +2500 -0
- aas_core_codegen/typescript/transpilation.py +1051 -0
- aas_core_codegen/typescript/unrolling.py +159 -0
- aas_core_codegen/typescript/verification/__init__.py +6 -0
- aas_core_codegen/typescript/verification/_generate.py +1578 -0
- aas_core_codegen/xsd/__init__.py +1 -0
- aas_core_codegen/xsd/main.py +1187 -0
- aas_core_codegen/xsd/naming.py +83 -0
- aas_core_codegen/yielding/__init__.py +1 -0
- aas_core_codegen/yielding/flow.py +139 -0
- aas_core_codegen/yielding/linear.py +754 -0
- aas_core_codegen-0.0.16.dist-info/METADATA +211 -0
- aas_core_codegen-0.0.16.dist-info/RECORD +604 -0
- aas_core_codegen-0.0.16.dist-info/WHEEL +5 -0
- aas_core_codegen-0.0.16.dist-info/entry_points.txt +3 -0
- aas_core_codegen-0.0.16.dist-info/licenses/AUTHORS +9 -0
- aas_core_codegen-0.0.16.dist-info/licenses/LICENSE +23 -0
- aas_core_codegen-0.0.16.dist-info/top_level.txt +2 -0
- dev/continuous_integration/__init__.py +1 -0
- dev/continuous_integration/check_help_in_readme.py +208 -0
- dev/continuous_integration/check_init_and_pyproject_consistent.py +154 -0
- dev/continuous_integration/precommit.py +400 -0
- dev/dev_scripts/__init__.py +1 -0
- dev/dev_scripts/compare_rendered_regexes_against_source_py.py +42 -0
- dev/dev_scripts/copy_to_aas_core3_cpp.py +100 -0
- dev/dev_scripts/copy_to_aas_core3_java.py +90 -0
- dev/dev_scripts/download_latest_aas_core_meta_v3.py +114 -0
- dev/dev_scripts/draw_bipartite_graph_based_on_lines.py +37 -0
- dev/dev_scripts/run_tests_with_rerecord.py +69 -0
- dev/dev_scripts/update_to_aas_core_meta.py +174 -0
- dev/integration_tests/input/jsonschema/boilerplate/main.py +55 -0
- dev/integration_tests/input/meta_model.py +38 -0
- dev/integration_tests/input/python/boilerplate/main.py +153 -0
- dev/integration_tests/main.py +258 -0
- dev/test_data/csharp/test_structure/concrete_class_with_descendants/meta_model.py +15 -0
- dev/test_data/csharp/test_structure/constructor_without_arguments/all_properties_optional/meta_model.py +9 -0
- dev/test_data/csharp/test_structure/constructor_without_arguments/no_properties/meta_model.py +6 -0
- dev/test_data/csharp/test_verification/builtin_functions/len/on_list/meta_model.py +20 -0
- dev/test_data/csharp/test_verification/builtin_functions/len/on_str/meta_model.py +16 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_prefix/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_suffix/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_group_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_the_middle/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_union/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/single_utf32_literal/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_within_group/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_without_group/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_beginning/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_end/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/in_the_middle/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/multiple/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/mixed_with_non_utf32/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/more_than_two_high_surrogates/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/multiple_utf32_ranges/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/multiple_utf32_ranges_mixed_with_non_utf32/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/two_high_surrogates/meta_model.py +8 -0
- dev/test_data/intermediate/expected/class/empty/meta_model.py +6 -0
- dev/test_data/intermediate/expected/class/implementation_specific_method/meta_model.py +8 -0
- dev/test_data/intermediate/expected/class/inheritance/meta_model.py +41 -0
- dev/test_data/intermediate/expected/class/methods_with_contracts/meta_model.py +15 -0
- dev/test_data/intermediate/expected/class/only_method_no_property/meta_model.py +7 -0
- dev/test_data/intermediate/expected/class/only_property_no_method/meta_model.py +9 -0
- dev/test_data/intermediate/expected/constant/constant_set/of_enum/meta_model.py +12 -0
- dev/test_data/intermediate/expected/constant/constant_set/of_str/meta_model.py +4 -0
- dev/test_data/intermediate/expected/constant/constant_set/with_description/meta_model.py +6 -0
- dev/test_data/intermediate/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
- dev/test_data/intermediate/expected/constant/constant_str/only_value/meta_model.py +7 -0
- dev/test_data/intermediate/expected/constant/constant_str/with_description/meta_model.py +5 -0
- dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py +20 -0
- dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py +20 -0
- dev/test_data/intermediate/expected/empty/meta_model.py +2 -0
- dev/test_data/intermediate/expected/enumeration/meta_model.py +9 -0
- dev/test_data/intermediate/expected/interface/basic/meta_model.py +14 -0
- dev/test_data/intermediate/expected/interface/empty/meta_model.py +7 -0
- dev/test_data/intermediate/expected/interface/inheritance/meta_model.py +27 -0
- dev/test_data/intermediate/expected/interface/method_signature/meta_model.py +10 -0
- dev/test_data/intermediate/expected/interface/only_constructor/meta_model.py +11 -0
- dev/test_data/intermediate/expected/method/non_mutating/implementation_specific/meta_model.py +12 -0
- dev/test_data/intermediate/expected/method/non_mutating/understood/meta_model.py +11 -0
- dev/test_data/intermediate/expected/type_annotation/atomic/meta_model.py +9 -0
- dev/test_data/intermediate/expected/type_annotation/subscripted/class/meta_model.py +13 -0
- dev/test_data/intermediate/expected/type_annotation/subscripted/primitive/meta_model.py +9 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/enumeration_literals_in_subset_outside_of_superset/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/invalid_literal/meta_model.py +11 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_between_enumeration_and_literal/meta_model.py +30 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_in_enumerations_between_subset_and_superset/meta_model.py +21 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/literals_in_subset_outside_of_superset/meta_model.py +18 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/mismatch_between_type_annotation_and_literals/meta_model.py +10 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/superset_and_subset_mismatch_in_type/meta_model.py +12 -0
- dev/test_data/intermediate/unexpected/constraints/dangling_constraintref/meta_model.py +18 -0
- dev/test_data/intermediate/unexpected/constraints/duplicate_constraints/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/documentation/unexpected_documentation_elements/meta_model.py +34 -0
- dev/test_data/intermediate/unexpected/invariant/class_invariant_uses_re/meta_model.py +10 -0
- dev/test_data/intermediate/unexpected/invariant/invariant_of_constrained_primitive_uses_re/meta_model.py +7 -0
- dev/test_data/intermediate/unexpected/invariant/unexpected_argument_count_to_len/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/invariant/unhandled_built_in_function/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/method_definitions/non_constant_default/meta_model.py +7 -0
- dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/default_non_none/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/no_default/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/after_inheritance/meta_model.py +58 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/meta_model.py +9 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/within_class/meta_model.py +22 -0
- dev/test_data/jsonschema/test_main/regression_when_len_constraints_on_inherited_property/meta_model.py +28 -0
- dev/test_data/opcua/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/opcua/test_main/classes_with_invariants/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_descendant/meta_model.py +27 -0
- dev/test_data/opcua/test_main/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_list_of_instances/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/opcua/test_main/concrete_class_with_string/meta_model.py +13 -0
- dev/test_data/opcua/test_main/constrained_primitive/meta_model.py +20 -0
- dev/test_data/opcua/test_main/multiple_inheritance/meta_model.py +25 -0
- dev/test_data/parse/expected/constant/constant_set/of_enum/meta_model.py +12 -0
- dev/test_data/parse/expected/constant/constant_set/of_str/meta_model.py +4 -0
- dev/test_data/parse/expected/constant/constant_set/with_description/meta_model.py +6 -0
- dev/test_data/parse/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
- dev/test_data/parse/expected/constant/constant_str/only_value/meta_model.py +7 -0
- dev/test_data/parse/expected/constant/constant_str/with_description/meta_model.py +5 -0
- dev/test_data/parse/expected/enum/ok/meta_model.py +15 -0
- dev/test_data/parse/expected/implementation_specific_class/properties_and_methods_in_implementation_specific_class/meta_model.py +17 -0
- dev/test_data/parse/expected/inheritance/basic/meta_model.py +11 -0
- dev/test_data/parse/expected/inheritance/diamond/meta_model.py +26 -0
- dev/test_data/parse/expected/inheritance/inheritance_from_concrete_class/meta_model.py +10 -0
- dev/test_data/parse/expected/invariants/in_relation/meta_model.py +16 -0
- dev/test_data/parse/expected/method/arguments/meta_model.py +7 -0
- dev/test_data/parse/expected/method/basic/meta_model.py +7 -0
- dev/test_data/parse/expected/method/contracts/condition_as_keyword_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/condition_as_positional_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/description_as_keyword_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/description_as_positional_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/multiple_contracts_in_order/meta_model.py +17 -0
- dev/test_data/parse/expected/method/contracts/postcondition/basic/meta_model.py +10 -0
- dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_keyword_arguments/meta_model.py +9 -0
- dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_positional_arguments/meta_model.py +9 -0
- dev/test_data/parse/expected/method/default/meta_model.py +9 -0
- dev/test_data/parse/expected/method/description/meta_model.py +8 -0
- dev/test_data/parse/expected/method/is_implementation_specific/meta_model.py +8 -0
- dev/test_data/parse/expected/method/non_mutating/meta_model.py +11 -0
- dev/test_data/parse/expected/method/returns_none/meta_model.py +7 -0
- dev/test_data/parse/expected/method/returns_something/meta_model.py +7 -0
- dev/test_data/parse/expected/single_class/description/meta_model.py +12 -0
- dev/test_data/parse/expected/single_class/empty/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/description/meta_model.py +14 -0
- dev/test_data/parse/expected/single_class/property/mandatory/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/optional/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/recursion_to_entity/meta_model.py +6 -0
- dev/test_data/parse/unexpected/class_decorators/non_name_decorator/meta_model.py +7 -0
- dev/test_data/parse/unexpected/class_decorators/unknown_decorator/meta_model.py +7 -0
- dev/test_data/parse/unexpected/class_definitions/is_abstract_and_implementation_specific/meta_model.py +8 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_before_a_method/meta_model.py +11 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_for_a_pass/meta_model.py +9 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_double_description_for_a_property/meta_model.py +10 -0
- dev/test_data/parse/unexpected/class_inheritances/inheriting_from_implementation_specific_parent/meta_model.py +20 -0
- dev/test_data/parse/unexpected/class_inheritances/non_name_super_class/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/expression_as_assignment_value/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/non_assignment/meta_model.py +8 -0
- dev/test_data/parse/unexpected/enum/non_string_literal/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/unexpected_inheritance/meta_model.py +6 -0
- dev/test_data/parse/unexpected/method_contracts/contract/non_lambda_condition/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/non_string_literal_description/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/without_any_arguments/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/without_condition/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/postcondition/OLD_in_postcondition_without_snapshot/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/postcondition/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/precondition/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/capture_not_a_lambda/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/invalid_name/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/name_not_a_string_literal/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_capture/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_name/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_constructor/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_verification_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_name_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/unknown_call_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/unknown_name_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_definitions/argument_with_final/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/argument_without_a_type_annotation/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/default_for_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/dunder/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/init_with_return_type/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_keyword_only_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_positional_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_type_annotation_for_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_variable_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_variable_keyword_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_type_annotation_for_result/meta_model.py +7 -0
- dev/test_data/parse/unexpected/property_definitions/final_without_subscript/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/nested_final/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/non_simple/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/unexpected_assignment/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/unexpected_non_name_property/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/without_type_annotation/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/constant_set_with_a_non_set_subset/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_inheritance/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_a_property/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_an_argument/meta_model.py +7 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_constant_set/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_subset_in_constant_set/meta_model.py +4 -0
- dev/test_data/parse/unexpected/symbol_table/inheritance_from_non_class/meta_model.py +10 -0
- dev/test_data/parse_retree/expected/character_set/common_escaping/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/double_caret/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/multiple_ranges/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/suffix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/escape_first_caret/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/literals_which_need_no_escaping_in_characters_set_but_need_escaping_outside/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/multiple_ranges/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/single_literal/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/single_range/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/only_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/prefix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/suffix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/dot/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group_in_a_group/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group_of_union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/regex/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/expected/escaped_literals/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/at_the_beginning/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/at_the_end/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/single_formatted_value/source.py +1 -0
- dev/test_data/parse_retree/expected/literal/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_least_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_least_one/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_most_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/exactly_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/maybe/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/zero_or_more/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_one/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_most_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/exactly_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/maybe/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/zero_or_more/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_character_set/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_formatted_value/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_group/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_literal/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/double_end_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/double_start_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/end_symbol_in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/only_start_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/only_stop_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_at_the_beginning/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/stop_symbol_at_the_end/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_character_sets/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_groups/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_string_literals/source.py +1 -0
- dev/test_data/parse_retree/expected/union/within_group/source.py +1 -0
- dev/test_data/parse_retree/expected/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/Uxxxxxxxx_out_of_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/only_backslash/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_Uxxxxxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_uxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unexpected_escaping/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/Uxxxxxxxx_out_of_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/only_backslash/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_Uxxxxxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_uxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unexpected_escaping/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_character_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/at_least_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/between_3_and_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/exactly_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unhandled_group_directives/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/character_set/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/group/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/group_of_union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_comma/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_number_and_comma/source.py +1 -0
- dev/test_data/proto/test_main/expected/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_descendants/meta_model.py +30 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_list_of_instances/meta_model.py +21 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/expected_output/pbization.py +532 -0
- dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/expected_output/pbization.py +527 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/meta_model.py +27 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_enum/expected_output/pbization.py +290 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/expected_output/pbization.py +328 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/meta_model.py +23 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/expected_output/pbization.py +274 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/rdf_shacl/test_main/expected/regression_when_lang_string_class_is_missing/meta_model.py +29 -0
- dev/test_data/rdf_shacl/test_main/expected/regression_when_len_constraints_on_inherited_property/meta_model.py +27 -0
- dev/test_data/rdf_shacl/test_main/unexpected/regression_len_constraint_on_class_property/meta_model.py +61 -0
- dev/test_data/real_meta_models/aas_core_meta.v3.py +5721 -0
- dev/test_data/smoke/test_main/unexpected/infer_for_schema_error/meta_model.py +12 -0
- dev/test_data/smoke/test_main/unexpected/intermediate_error/meta_model.py +18 -0
- dev/test_data/smoke/test_main/unexpected/parse_error/meta_model.py +5 -0
- dev/test_data/smoke/test_main/unexpected/pattern_verification_unparsable_regex/direct_match/meta_model.py +8 -0
- dev/test_data/smoke/test_main/unexpected/type_error/meta_model.py +18 -0
- dev/tests/__init__.py +1 -0
- dev/tests/common.py +197 -0
- dev/tests/cpp/__init__.py +0 -0
- dev/tests/cpp/test_common.py +32 -0
- dev/tests/cpp/test_main.py +144 -0
- dev/tests/cpp/test_pattern.py +188 -0
- dev/tests/cpp/test_verification.py +189 -0
- dev/tests/cpp/test_yielding.py +225 -0
- dev/tests/csharp/__init__.py +0 -0
- dev/tests/csharp/live_test_main.py +109 -0
- dev/tests/csharp/test_common.py +28 -0
- dev/tests/csharp/test_description.py +684 -0
- dev/tests/csharp/test_main.py +129 -0
- dev/tests/csharp/test_structure.py +93 -0
- dev/tests/csharp/test_verification.py +82 -0
- dev/tests/description.py +29 -0
- dev/tests/golang/__init__.py +0 -0
- dev/tests/golang/test_common.py +78 -0
- dev/tests/golang/test_main.py +128 -0
- dev/tests/infer_for_schema/__init__.py +0 -0
- dev/tests/infer_for_schema/common.py +47 -0
- dev/tests/infer_for_schema/test_len_on_properties.py +955 -0
- dev/tests/infer_for_schema/test_len_on_self.py +580 -0
- dev/tests/infer_for_schema/test_patterns_on_properties.py +686 -0
- dev/tests/infer_for_schema/test_patterns_on_self.py +258 -0
- dev/tests/infer_for_schema/test_property_in_set_of_enumeration_literals.py +600 -0
- dev/tests/infer_for_schema/test_property_in_set_of_primitives.py +549 -0
- dev/tests/intermediate/__init__.py +0 -0
- dev/tests/intermediate/test_constructor.py +719 -0
- dev/tests/intermediate/test_hierarchy.py +221 -0
- dev/tests/intermediate/test_revm.py +134 -0
- dev/tests/intermediate/test_translate.py +337 -0
- dev/tests/intermediate/test_type_inference.py +333 -0
- dev/tests/intermediate/test_types.py +169 -0
- dev/tests/java/__init__.py +0 -0
- dev/tests/java/test_common.py +20 -0
- dev/tests/java/test_description.py +128 -0
- dev/tests/java/test_main.py +234 -0
- dev/tests/jsonld_context/test_main.py +79 -0
- dev/tests/opcua/__init__.py +3 -0
- dev/tests/opcua/test_main.py +110 -0
- dev/tests/our_jsonschema/__init__.py +3 -0
- dev/tests/our_jsonschema/test_main.py +232 -0
- dev/tests/parse/__init__.py +0 -0
- dev/tests/parse/test_parse.py +503 -0
- dev/tests/parse/test_retree.py +272 -0
- dev/tests/proto/__init__.py +0 -0
- dev/tests/proto/test_main.py +112 -0
- dev/tests/python/__init__.py +0 -0
- dev/tests/python/test_common.py +124 -0
- dev/tests/python/test_main.py +126 -0
- dev/tests/python/test_xml_playground.py +254 -0
- dev/tests/python_protobuf/__init__.py +0 -0
- dev/tests/python_protobuf/test_main.py +111 -0
- dev/tests/rdf_shacl/__init__.py +0 -0
- dev/tests/rdf_shacl/test_common.py +32 -0
- dev/tests/rdf_shacl/test_description.py +223 -0
- dev/tests/rdf_shacl/test_main.py +194 -0
- dev/tests/smoke/__init__.py +0 -0
- dev/tests/smoke/test_main.py +83 -0
- dev/tests/test_common.py +94 -0
- dev/tests/typescript/__init__.py +0 -0
- dev/tests/typescript/test_common.py +108 -0
- dev/tests/typescript/test_main.py +125 -0
- dev/tests/xsd/__init__.py +0 -0
- dev/tests/xsd/test_main.py +227 -0
- dev/tests/yielding/__init__.py +0 -0
- dev/tests/yielding/test_linear.py +558 -0
|
@@ -0,0 +1,982 @@
|
|
|
1
|
+
"""Generate JSON schema corresponding to the meta-model."""
|
|
2
|
+
import collections
|
|
3
|
+
import json
|
|
4
|
+
from typing import (
|
|
5
|
+
TextIO,
|
|
6
|
+
Any,
|
|
7
|
+
MutableMapping,
|
|
8
|
+
Optional,
|
|
9
|
+
Tuple,
|
|
10
|
+
List,
|
|
11
|
+
Sequence,
|
|
12
|
+
Mapping,
|
|
13
|
+
Callable,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
from icontract import ensure, require
|
|
17
|
+
|
|
18
|
+
import aas_core_codegen.jsonschema
|
|
19
|
+
from aas_core_codegen import (
|
|
20
|
+
naming,
|
|
21
|
+
specific_implementations,
|
|
22
|
+
intermediate,
|
|
23
|
+
run,
|
|
24
|
+
infer_for_schema,
|
|
25
|
+
)
|
|
26
|
+
from aas_core_codegen.parse import retree as parse_retree
|
|
27
|
+
from aas_core_codegen.common import Stripped, Error, assert_never, Identifier
|
|
28
|
+
|
|
29
|
+
assert aas_core_codegen.jsonschema.__doc__ == __doc__
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _define_for_enumeration(
|
|
33
|
+
enumeration: intermediate.Enumeration,
|
|
34
|
+
) -> MutableMapping[str, Any]:
|
|
35
|
+
"""
|
|
36
|
+
Generate the definition for an ``enumeration``.
|
|
37
|
+
|
|
38
|
+
The list of definitions is to be *extended* with the resulting mapping.
|
|
39
|
+
"""
|
|
40
|
+
definition = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
41
|
+
definition["type"] = "string"
|
|
42
|
+
definition["enum"] = sorted(literal.value for literal in enumeration.literals)
|
|
43
|
+
|
|
44
|
+
model_type = naming.json_model_type(enumeration.name)
|
|
45
|
+
|
|
46
|
+
return collections.OrderedDict([(model_type, definition)])
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
_PRIMITIVE_MAP = {
|
|
50
|
+
intermediate.PrimitiveType.BOOL: "boolean",
|
|
51
|
+
intermediate.PrimitiveType.INT: "integer",
|
|
52
|
+
intermediate.PrimitiveType.FLOAT: "number",
|
|
53
|
+
intermediate.PrimitiveType.STR: "string",
|
|
54
|
+
intermediate.PrimitiveType.BYTEARRAY: "string",
|
|
55
|
+
}
|
|
56
|
+
assert all(literal in _PRIMITIVE_MAP for literal in intermediate.PrimitiveType)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _define_primitive_type(
|
|
60
|
+
primitive_type: intermediate.PrimitiveType,
|
|
61
|
+
) -> MutableMapping[str, Any]:
|
|
62
|
+
"""Generate the definition for the given ``primitive_type``."""
|
|
63
|
+
definition = collections.OrderedDict([("type", _PRIMITIVE_MAP[primitive_type])])
|
|
64
|
+
|
|
65
|
+
if primitive_type is intermediate.PrimitiveType.BYTEARRAY:
|
|
66
|
+
definition["contentEncoding"] = "base64"
|
|
67
|
+
|
|
68
|
+
return definition
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
72
|
+
def _define_type(
|
|
73
|
+
type_annotation: intermediate.TypeAnnotationExceptOptional,
|
|
74
|
+
) -> Tuple[Optional[MutableMapping[str, Any]], Optional[Error]]:
|
|
75
|
+
"""Generate the type definition for ``type_annotation``."""
|
|
76
|
+
if isinstance(type_annotation, intermediate.PrimitiveTypeAnnotation):
|
|
77
|
+
return _define_primitive_type(type_annotation.a_type), None
|
|
78
|
+
|
|
79
|
+
elif isinstance(type_annotation, intermediate.OurTypeAnnotation):
|
|
80
|
+
model_type = naming.json_model_type(type_annotation.our_type.name)
|
|
81
|
+
|
|
82
|
+
if isinstance(type_annotation.our_type, intermediate.Enumeration):
|
|
83
|
+
return (
|
|
84
|
+
collections.OrderedDict([("$ref", f"#/definitions/{model_type}")]),
|
|
85
|
+
None,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
elif isinstance(type_annotation.our_type, intermediate.ConstrainedPrimitive):
|
|
89
|
+
return _define_primitive_type(type_annotation.our_type.constrainee), None
|
|
90
|
+
|
|
91
|
+
elif isinstance(type_annotation.our_type, intermediate.Class):
|
|
92
|
+
if len(type_annotation.our_type.concrete_descendants) > 0:
|
|
93
|
+
return (
|
|
94
|
+
collections.OrderedDict(
|
|
95
|
+
[("$ref", f"#/definitions/{model_type}_choice")]
|
|
96
|
+
),
|
|
97
|
+
None,
|
|
98
|
+
)
|
|
99
|
+
else:
|
|
100
|
+
return (
|
|
101
|
+
collections.OrderedDict([("$ref", f"#/definitions/{model_type}")]),
|
|
102
|
+
None,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
else:
|
|
106
|
+
assert_never(type_annotation.our_type)
|
|
107
|
+
|
|
108
|
+
elif isinstance(type_annotation, intermediate.ListTypeAnnotation):
|
|
109
|
+
assert not isinstance(
|
|
110
|
+
type_annotation.items, intermediate.OptionalTypeAnnotation
|
|
111
|
+
), (
|
|
112
|
+
"NOTE (mristin, 2023-02-06): Lists of optional values were not expected "
|
|
113
|
+
"at the time when we implemented this. Please contact the developers "
|
|
114
|
+
"if you need this functionality."
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
items_type_definition, items_error = _define_type(
|
|
118
|
+
type_annotation=type_annotation.items
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
if items_error is not None:
|
|
122
|
+
return None, items_error
|
|
123
|
+
|
|
124
|
+
assert items_type_definition is not None
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
collections.OrderedDict(
|
|
128
|
+
[("type", "array"), ("items", items_type_definition)]
|
|
129
|
+
),
|
|
130
|
+
None,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
else:
|
|
134
|
+
raise NotImplementedError(
|
|
135
|
+
f"(mristin, 2021-11-10):\n"
|
|
136
|
+
f"We implemented only a subset of possible type annotations "
|
|
137
|
+
f"to be represented in a JSON schema since we lacked more information "
|
|
138
|
+
f"about the context.\n\n"
|
|
139
|
+
f"This feature needs yet to be implemented.\n\n"
|
|
140
|
+
f"{type_annotation=}"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# NOTE (mristin):
|
|
145
|
+
# This function is made public so that we can use it in other schema generators such
|
|
146
|
+
# as the SHACL generator.
|
|
147
|
+
def fix_pattern_for_utf16(pattern: str) -> str:
|
|
148
|
+
"""Parse the pattern and re-render it for UTF-16-only regex engines."""
|
|
149
|
+
regex, error = parse_retree.parse([pattern])
|
|
150
|
+
if error is not None:
|
|
151
|
+
raise ValueError(
|
|
152
|
+
f"The pattern could not be parsed: {pattern!r}; error was: {error}"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
assert regex is not None
|
|
156
|
+
parse_retree.fix_for_utf16_regex_in_place(regex)
|
|
157
|
+
|
|
158
|
+
parts = parse_retree.render(regex=regex)
|
|
159
|
+
assert all(
|
|
160
|
+
isinstance(part, str) for part in parts
|
|
161
|
+
), "Only string parts expected, no formatted values"
|
|
162
|
+
|
|
163
|
+
# NOTE (mristin, 2023-03-15):
|
|
164
|
+
# We have to make this transformation for mypy.
|
|
165
|
+
parts_str = [] # type: List[str]
|
|
166
|
+
for part in parts:
|
|
167
|
+
assert isinstance(part, str), "Only string parts expected, no formatted values"
|
|
168
|
+
parts_str.append(part)
|
|
169
|
+
|
|
170
|
+
return "".join(parts_str)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _define_constraints_for_primitive_type(
|
|
174
|
+
primitive_type: intermediate.PrimitiveType,
|
|
175
|
+
len_constraint: Optional[infer_for_schema.LenConstraint],
|
|
176
|
+
pattern_constraints: Optional[Sequence[infer_for_schema.PatternConstraint]],
|
|
177
|
+
fix_pattern: Callable[[str], str],
|
|
178
|
+
) -> MutableMapping[str, Any]:
|
|
179
|
+
"""
|
|
180
|
+
Generate the constraints, if any, for the ``primitive_type``.
|
|
181
|
+
|
|
182
|
+
If there are no constraints, an empty mapping is returned.
|
|
183
|
+
|
|
184
|
+
The ``fix_pattern`` determines how the pattern should be translated for
|
|
185
|
+
the regex engine. For example, some JSON schema verification engines expect only
|
|
186
|
+
characters below Basic Multilingual Plane (BMP), and use surrogate pairs to
|
|
187
|
+
represent characters above BMP.
|
|
188
|
+
"""
|
|
189
|
+
definition = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
190
|
+
|
|
191
|
+
if (
|
|
192
|
+
primitive_type
|
|
193
|
+
in (intermediate.PrimitiveType.STR, intermediate.PrimitiveType.BYTEARRAY)
|
|
194
|
+
and len_constraint is not None
|
|
195
|
+
):
|
|
196
|
+
if len_constraint.min_value is not None:
|
|
197
|
+
definition["minLength"] = len_constraint.min_value
|
|
198
|
+
|
|
199
|
+
if len_constraint.max_value is not None:
|
|
200
|
+
definition["maxLength"] = len_constraint.max_value
|
|
201
|
+
|
|
202
|
+
if (
|
|
203
|
+
primitive_type == intermediate.PrimitiveType.STR
|
|
204
|
+
and pattern_constraints is not None
|
|
205
|
+
and len(pattern_constraints) > 0
|
|
206
|
+
):
|
|
207
|
+
if len(pattern_constraints) == 1:
|
|
208
|
+
definition["pattern"] = fix_pattern(pattern_constraints[0].pattern)
|
|
209
|
+
else:
|
|
210
|
+
all_of = [definition] # type: List[MutableMapping[str, Any]]
|
|
211
|
+
|
|
212
|
+
for pattern_constraint in pattern_constraints:
|
|
213
|
+
all_of.append(
|
|
214
|
+
collections.OrderedDict(
|
|
215
|
+
[
|
|
216
|
+
(
|
|
217
|
+
"pattern",
|
|
218
|
+
fix_pattern(pattern_constraint.pattern),
|
|
219
|
+
)
|
|
220
|
+
]
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
definition = collections.OrderedDict([("allOf", all_of)])
|
|
225
|
+
|
|
226
|
+
return definition
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
230
|
+
def _define_constraints(
|
|
231
|
+
type_annotation: intermediate.TypeAnnotation,
|
|
232
|
+
len_constraint: Optional[infer_for_schema.LenConstraint],
|
|
233
|
+
pattern_constraints: Optional[Sequence[infer_for_schema.PatternConstraint]],
|
|
234
|
+
fix_pattern: Callable[[str], str],
|
|
235
|
+
) -> Tuple[Optional[MutableMapping[str, Any]], Optional[Error]]:
|
|
236
|
+
"""
|
|
237
|
+
Generate only the constraints for the given ``type_annotation``.
|
|
238
|
+
|
|
239
|
+
The type is generated in a separated function, `_generate_type`.
|
|
240
|
+
|
|
241
|
+
The ``fix_pattern`` determines how the pattern should be translated for
|
|
242
|
+
the regex engine. For example, some JSON schema verification engines expect only
|
|
243
|
+
characters below Basic Multilingual Plane (BMP), and use surrogate pairs to
|
|
244
|
+
represent characters above BMP.
|
|
245
|
+
|
|
246
|
+
If there are no constraints, an empty mapping is returned.
|
|
247
|
+
"""
|
|
248
|
+
if isinstance(type_annotation, intermediate.PrimitiveTypeAnnotation):
|
|
249
|
+
return (
|
|
250
|
+
_define_constraints_for_primitive_type(
|
|
251
|
+
primitive_type=type_annotation.a_type,
|
|
252
|
+
len_constraint=len_constraint,
|
|
253
|
+
pattern_constraints=pattern_constraints,
|
|
254
|
+
fix_pattern=fix_pattern,
|
|
255
|
+
),
|
|
256
|
+
None,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
elif isinstance(type_annotation, intermediate.OurTypeAnnotation):
|
|
260
|
+
if isinstance(type_annotation.our_type, intermediate.Enumeration):
|
|
261
|
+
return collections.OrderedDict(), None
|
|
262
|
+
|
|
263
|
+
elif isinstance(type_annotation.our_type, intermediate.ConstrainedPrimitive):
|
|
264
|
+
# NOTE (mristin, 2022-02-11):
|
|
265
|
+
# We in-line the constraints from the constrained primitives directly
|
|
266
|
+
# in the properties. We do not want to introduce separate definitions
|
|
267
|
+
# for them as that would make it more difficult for downstream code
|
|
268
|
+
# generators to generate meaningful code (*e.g.*, code generators for
|
|
269
|
+
# OpenAPI3).
|
|
270
|
+
return (
|
|
271
|
+
_define_constraints_for_primitive_type(
|
|
272
|
+
primitive_type=type_annotation.our_type.constrainee,
|
|
273
|
+
len_constraint=len_constraint,
|
|
274
|
+
pattern_constraints=pattern_constraints,
|
|
275
|
+
fix_pattern=fix_pattern,
|
|
276
|
+
),
|
|
277
|
+
None,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
elif isinstance(type_annotation.our_type, intermediate.Class):
|
|
281
|
+
# NOTE (mristin, 2023-02-06):
|
|
282
|
+
# There are no constraints for class itself in JSON schema. We define
|
|
283
|
+
# constraints only per properties at the moment.
|
|
284
|
+
return collections.OrderedDict(), None
|
|
285
|
+
|
|
286
|
+
else:
|
|
287
|
+
assert_never(type_annotation.our_type)
|
|
288
|
+
|
|
289
|
+
elif isinstance(type_annotation, intermediate.ListTypeAnnotation):
|
|
290
|
+
# NOTE (mristin, 2021-12-02):
|
|
291
|
+
# We do not propagate the inference of constraints to sub-lists
|
|
292
|
+
# so in this case we set all the constraint on the ``items`` to none.
|
|
293
|
+
# This behavior might change in the future when we encounter such
|
|
294
|
+
# constraints and have more context available.
|
|
295
|
+
|
|
296
|
+
definition = collections.OrderedDict()
|
|
297
|
+
|
|
298
|
+
if len_constraint is not None:
|
|
299
|
+
if len_constraint.min_value is not None:
|
|
300
|
+
assert (
|
|
301
|
+
"minItems" not in definition
|
|
302
|
+
), "Unexpected property 'minItems' in the JSON type definition"
|
|
303
|
+
|
|
304
|
+
definition["minItems"] = len_constraint.min_value
|
|
305
|
+
|
|
306
|
+
if len_constraint.max_value is not None:
|
|
307
|
+
assert (
|
|
308
|
+
"maxItems" not in definition
|
|
309
|
+
), "Unexpected property 'maxItems' in the JSON type definition"
|
|
310
|
+
|
|
311
|
+
definition["maxItems"] = len_constraint.max_value
|
|
312
|
+
|
|
313
|
+
return definition, None
|
|
314
|
+
|
|
315
|
+
elif isinstance(type_annotation, intermediate.OptionalTypeAnnotation):
|
|
316
|
+
raise NotImplementedError(
|
|
317
|
+
f"(mristin, 2021-11-10):\n"
|
|
318
|
+
f"Nested optional values are unexpected in the JSON schema. "
|
|
319
|
+
f"We did not implement them at the moment since we need more information "
|
|
320
|
+
f"about the context.\n\n"
|
|
321
|
+
f"This feature needs yet to be implemented.\n\n"
|
|
322
|
+
f"{type_annotation=}"
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
else:
|
|
326
|
+
raise NotImplementedError(
|
|
327
|
+
f"(mristin, 2021-11-10):\n"
|
|
328
|
+
f"We implemented only a subset of possible type annotations "
|
|
329
|
+
f"to be represented in a JSON schema since we lacked more information "
|
|
330
|
+
f"about the context.\n\n"
|
|
331
|
+
f"This feature needs yet to be implemented.\n\n"
|
|
332
|
+
f"{type_annotation=}"
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
337
|
+
def _define_properties(
|
|
338
|
+
cls: intermediate.ClassUnion,
|
|
339
|
+
constraints_by_property: infer_for_schema.ConstraintsByProperty,
|
|
340
|
+
fix_pattern: Callable[[str], str],
|
|
341
|
+
) -> Tuple[Optional[MutableMapping[str, Any]], Optional[List[Error]]]:
|
|
342
|
+
"""
|
|
343
|
+
Generate the definitions of the meta-model properties for the given ``cls``.
|
|
344
|
+
|
|
345
|
+
The property ``modelType`` is defined separately as we need to distinguish
|
|
346
|
+
cases where it is set (concrete class) and not (abstract class, or stub of
|
|
347
|
+
a concrete class with descendants).
|
|
348
|
+
|
|
349
|
+
The ``fix_pattern`` determines how the pattern should be translated for
|
|
350
|
+
the regex engine. For example, some JSON schema verification engines expect only
|
|
351
|
+
characters below Basic Multilingual Plane (BMP), and use surrogate pairs to
|
|
352
|
+
represent characters above BMP.
|
|
353
|
+
"""
|
|
354
|
+
errors = [] # type: List[Error]
|
|
355
|
+
|
|
356
|
+
properties = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
357
|
+
|
|
358
|
+
for prop in cls.properties:
|
|
359
|
+
prop_name = naming.json_property(prop.name)
|
|
360
|
+
|
|
361
|
+
len_constraint = constraints_by_property.len_constraints_by_property.get(
|
|
362
|
+
prop, None
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
pattern_constraints = constraints_by_property.patterns_by_property.get(
|
|
366
|
+
prop, None
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
type_anno = intermediate.beneath_optional(prop.type_annotation)
|
|
370
|
+
|
|
371
|
+
definition = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
372
|
+
|
|
373
|
+
# NOTE (mristin, 2023-02-06):
|
|
374
|
+
# The properties are inherited through ``allOf``. We can not change the type
|
|
375
|
+
# of property in the children as this would result in a conflict and
|
|
376
|
+
# unsatisfiable schema. Therefore, we define the type for a property only
|
|
377
|
+
# at the parent class, where the property is defined for the first time.
|
|
378
|
+
if prop.specified_for is cls:
|
|
379
|
+
property_definition, error = _define_type(type_annotation=type_anno)
|
|
380
|
+
|
|
381
|
+
if error is not None:
|
|
382
|
+
errors.append(error)
|
|
383
|
+
else:
|
|
384
|
+
assert property_definition is not None
|
|
385
|
+
definition.update(property_definition)
|
|
386
|
+
|
|
387
|
+
constraints_definition, error = _define_constraints(
|
|
388
|
+
type_annotation=type_anno,
|
|
389
|
+
len_constraint=len_constraint,
|
|
390
|
+
pattern_constraints=pattern_constraints,
|
|
391
|
+
fix_pattern=fix_pattern,
|
|
392
|
+
)
|
|
393
|
+
if error is not None:
|
|
394
|
+
errors.append(error)
|
|
395
|
+
else:
|
|
396
|
+
assert constraints_definition is not None
|
|
397
|
+
definition.update(constraints_definition)
|
|
398
|
+
|
|
399
|
+
# NOTE (mristin, 2023-02-06):
|
|
400
|
+
# We do not want to pollute the schema with empty definitions. An empty
|
|
401
|
+
# definition results if there are no constraints and the property is inherited
|
|
402
|
+
# from an ancestor class through ``allOf``.
|
|
403
|
+
if len(definition) > 0:
|
|
404
|
+
properties[prop_name] = definition
|
|
405
|
+
|
|
406
|
+
if len(errors) > 0:
|
|
407
|
+
return None, errors
|
|
408
|
+
|
|
409
|
+
return properties, None
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def _list_required_properties(cls: intermediate.ClassUnion) -> List[Identifier]:
|
|
413
|
+
"""
|
|
414
|
+
List all the properties which are required.
|
|
415
|
+
|
|
416
|
+
Only the meta-model properties are listed, so this list might not be exhaustive.
|
|
417
|
+
For example, the JSON property ``modelType`` is not listed here.
|
|
418
|
+
"""
|
|
419
|
+
required = [] # type: List[Identifier]
|
|
420
|
+
for prop in cls.properties:
|
|
421
|
+
# NOTE (mristin, 2023-02-06):
|
|
422
|
+
# We stack the inheritance as ``allOf``. This will impose the stacking
|
|
423
|
+
# of the required fields as well, so whenever you add a field to
|
|
424
|
+
# a child ``required`` constraint, it will *extend* the list of
|
|
425
|
+
# the required fields, *not* replace it.
|
|
426
|
+
if prop.specified_for is not cls:
|
|
427
|
+
continue
|
|
428
|
+
|
|
429
|
+
if not isinstance(prop.type_annotation, intermediate.OptionalTypeAnnotation):
|
|
430
|
+
prop_name = naming.json_property(prop.name)
|
|
431
|
+
required.append(prop_name)
|
|
432
|
+
|
|
433
|
+
return required
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _define_all_of_for_inheritance(
|
|
437
|
+
cls: intermediate.ClassUnion,
|
|
438
|
+
) -> List[MutableMapping[str, Any]]:
|
|
439
|
+
"""Generate ``allOf`` definition as inheritance."""
|
|
440
|
+
all_of = [] # type: List[MutableMapping[str, Any]]
|
|
441
|
+
|
|
442
|
+
for inheritance in cls.inheritances:
|
|
443
|
+
if isinstance(inheritance, intermediate.AbstractClass):
|
|
444
|
+
all_of.append(
|
|
445
|
+
{"$ref": f"#/definitions/{naming.json_model_type(inheritance.name)}"}
|
|
446
|
+
)
|
|
447
|
+
elif isinstance(inheritance, intermediate.ConcreteClass):
|
|
448
|
+
# NOTE (mristin, 2023-03-13):
|
|
449
|
+
# We distinguish between two definitions corresponding to the same concrete
|
|
450
|
+
# class:
|
|
451
|
+
#
|
|
452
|
+
# 1) One definition defines only the class in abstract, so that
|
|
453
|
+
# it can be inherited. The abstract definition lacks the ``modelType``
|
|
454
|
+
# constant, as that would conflict in inheritance.
|
|
455
|
+
# 2) The other definition corresponds to the concrete definition of
|
|
456
|
+
# the class that an instance has to fulfill. This definition includes
|
|
457
|
+
# the constant ``modelType``.
|
|
458
|
+
#
|
|
459
|
+
# We had to separate these two definitions to avoid conflicts in
|
|
460
|
+
# ``modelType`` constant between a parent concrete class and a child
|
|
461
|
+
# concrete class.
|
|
462
|
+
all_of.append(
|
|
463
|
+
{
|
|
464
|
+
"$ref": f"#/definitions/"
|
|
465
|
+
f"{naming.json_model_type(inheritance.name)}_abstract"
|
|
466
|
+
}
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
return all_of
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
@require(lambda cls: len(cls.concrete_descendants) > 0)
|
|
473
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
474
|
+
def _generate_inheritable_definition(
|
|
475
|
+
cls: intermediate.ClassUnion,
|
|
476
|
+
constraints_by_property: infer_for_schema.ConstraintsByProperty,
|
|
477
|
+
fix_pattern: Callable[[str], str],
|
|
478
|
+
) -> Tuple[Optional[MutableMapping[str, Any]], Optional[List[Error]]]:
|
|
479
|
+
"""
|
|
480
|
+
Generate a definition of ``cls`` for inheritance through ``allOf``.
|
|
481
|
+
|
|
482
|
+
The ``fix_pattern`` determines how the pattern should be translated for
|
|
483
|
+
the respective JSON schema engine.
|
|
484
|
+
|
|
485
|
+
The definitions are to be *extended* with the resulting mapping.
|
|
486
|
+
"""
|
|
487
|
+
all_of = _define_all_of_for_inheritance(cls)
|
|
488
|
+
|
|
489
|
+
errors = [] # type: List[Error]
|
|
490
|
+
|
|
491
|
+
properties, properties_error = _define_properties(
|
|
492
|
+
cls=cls,
|
|
493
|
+
constraints_by_property=constraints_by_property,
|
|
494
|
+
fix_pattern=fix_pattern,
|
|
495
|
+
)
|
|
496
|
+
if properties_error is not None:
|
|
497
|
+
errors.extend(properties_error)
|
|
498
|
+
|
|
499
|
+
if len(errors) > 0:
|
|
500
|
+
return None, errors
|
|
501
|
+
|
|
502
|
+
assert properties is not None
|
|
503
|
+
|
|
504
|
+
required = _list_required_properties(cls)
|
|
505
|
+
|
|
506
|
+
if cls.serialization.with_model_type and not any(
|
|
507
|
+
inheritance.serialization.with_model_type for inheritance in cls.inheritances
|
|
508
|
+
):
|
|
509
|
+
# NOTE (mristin, 2023-03-13):
|
|
510
|
+
# This is going to be an abstract definition for inheritance, so we can not pin
|
|
511
|
+
# the ``modelType`` to a fixed, constant value.
|
|
512
|
+
assert "modelType" not in properties
|
|
513
|
+
properties["modelType"] = {"$ref": "#/definitions/ModelType"}
|
|
514
|
+
|
|
515
|
+
required.append(Identifier("modelType"))
|
|
516
|
+
|
|
517
|
+
definition = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
518
|
+
if len(cls.inheritances) == 0:
|
|
519
|
+
definition["type"] = "object"
|
|
520
|
+
|
|
521
|
+
if len(properties) > 0:
|
|
522
|
+
definition["properties"] = properties
|
|
523
|
+
|
|
524
|
+
if len(required) > 0:
|
|
525
|
+
definition["required"] = required
|
|
526
|
+
|
|
527
|
+
if len(definition) > 0:
|
|
528
|
+
all_of.append(definition)
|
|
529
|
+
|
|
530
|
+
definition_name: str
|
|
531
|
+
if isinstance(cls, intermediate.AbstractClass):
|
|
532
|
+
definition_name = naming.json_model_type(cls.name)
|
|
533
|
+
elif isinstance(cls, intermediate.ConcreteClass):
|
|
534
|
+
definition_name = f"{naming.json_model_type(cls.name)}_abstract"
|
|
535
|
+
else:
|
|
536
|
+
assert_never(cls)
|
|
537
|
+
|
|
538
|
+
result = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
539
|
+
|
|
540
|
+
if len(all_of) == 0:
|
|
541
|
+
result[definition_name] = {"type": "object"}
|
|
542
|
+
elif len(all_of) == 1:
|
|
543
|
+
result[definition_name] = all_of[0]
|
|
544
|
+
else:
|
|
545
|
+
result[definition_name] = {"allOf": all_of}
|
|
546
|
+
|
|
547
|
+
return result, None
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
@require(lambda cls: len(cls.concrete_descendants) > 0)
|
|
551
|
+
def _generate_choice_definition(
|
|
552
|
+
cls: intermediate.ClassUnion,
|
|
553
|
+
) -> MutableMapping[str, Any]:
|
|
554
|
+
"""
|
|
555
|
+
Generate the definition of dispatching through ``oneOf``.
|
|
556
|
+
|
|
557
|
+
The definitions are to be *extended* with the resulting mapping.
|
|
558
|
+
"""
|
|
559
|
+
one_of = [] # type: List[Mapping[str, Any]]
|
|
560
|
+
if isinstance(cls, intermediate.ConcreteClass):
|
|
561
|
+
one_of.append({"$ref": f"#/definitions/{naming.json_model_type(cls.name)}"})
|
|
562
|
+
|
|
563
|
+
for descendant in cls.concrete_descendants:
|
|
564
|
+
one_of.append(
|
|
565
|
+
{"$ref": f"#/definitions/{naming.json_model_type(descendant.name)}"}
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
return {f"{naming.json_model_type(cls.name)}_choice": {"oneOf": one_of}}
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
572
|
+
def _generate_concrete_definition(
|
|
573
|
+
cls: intermediate.ClassUnion,
|
|
574
|
+
constraints_by_property: infer_for_schema.ConstraintsByProperty,
|
|
575
|
+
fix_pattern: Callable[[str], str],
|
|
576
|
+
) -> Tuple[Optional[MutableMapping[str, Any]], Optional[List[Error]]]:
|
|
577
|
+
"""
|
|
578
|
+
Generate the definition of a concrete class to be matched by an instance.
|
|
579
|
+
|
|
580
|
+
The ``fix_pattern`` determines how the pattern should be translated for
|
|
581
|
+
the respective JSON schema engine.
|
|
582
|
+
"""
|
|
583
|
+
# NOTE (mristin, 2023-03-13):
|
|
584
|
+
# We distinguish between two definitions corresponding to the same concrete
|
|
585
|
+
# class:
|
|
586
|
+
#
|
|
587
|
+
# 1) One definition defines only the class in abstract, so that
|
|
588
|
+
# it can be inherited. The abstract definition lacks the ``modelType``
|
|
589
|
+
# constant, as that would conflict in inheritance.
|
|
590
|
+
# 2) The other definition corresponds to the concrete definition of
|
|
591
|
+
# the class that an instance has to fulfill. This definition includes
|
|
592
|
+
# the constant ``modelType``.
|
|
593
|
+
#
|
|
594
|
+
# We had to separate these two definitions to avoid conflicts in
|
|
595
|
+
# ``modelType`` constant between a parent concrete class and a child
|
|
596
|
+
# concrete class.
|
|
597
|
+
|
|
598
|
+
model_type = naming.json_model_type(cls.name)
|
|
599
|
+
|
|
600
|
+
if len(cls.concrete_descendants) > 0:
|
|
601
|
+
assert cls.serialization.with_model_type, (
|
|
602
|
+
f"Expected model type to be included in a class with concrete descendants "
|
|
603
|
+
f"{cls.name!r}"
|
|
604
|
+
)
|
|
605
|
+
|
|
606
|
+
all_of = [
|
|
607
|
+
{"$ref": f"#/definitions/{model_type}_abstract"},
|
|
608
|
+
{"properties": {"modelType": {"const": model_type}}},
|
|
609
|
+
] # type: List[MutableMapping[str, Any]]
|
|
610
|
+
|
|
611
|
+
return {model_type: {"allOf": all_of}}, None
|
|
612
|
+
|
|
613
|
+
all_of = _define_all_of_for_inheritance(cls)
|
|
614
|
+
|
|
615
|
+
errors = [] # type: List[Error]
|
|
616
|
+
|
|
617
|
+
properties, properties_error = _define_properties(
|
|
618
|
+
cls=cls,
|
|
619
|
+
constraints_by_property=constraints_by_property,
|
|
620
|
+
fix_pattern=fix_pattern,
|
|
621
|
+
)
|
|
622
|
+
if properties_error is not None:
|
|
623
|
+
errors.extend(properties_error)
|
|
624
|
+
|
|
625
|
+
if len(errors) > 0:
|
|
626
|
+
return None, errors
|
|
627
|
+
|
|
628
|
+
assert properties is not None
|
|
629
|
+
|
|
630
|
+
required = _list_required_properties(cls)
|
|
631
|
+
|
|
632
|
+
if cls.serialization.with_model_type:
|
|
633
|
+
properties["modelType"] = {"const": model_type}
|
|
634
|
+
|
|
635
|
+
definition = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
636
|
+
if len(cls.inheritances) == 0:
|
|
637
|
+
definition["type"] = "object"
|
|
638
|
+
|
|
639
|
+
if len(properties) > 0:
|
|
640
|
+
definition["properties"] = properties
|
|
641
|
+
|
|
642
|
+
if len(required) > 0:
|
|
643
|
+
definition["required"] = required
|
|
644
|
+
|
|
645
|
+
all_of.append(definition)
|
|
646
|
+
|
|
647
|
+
model_type = naming.json_model_type(cls.name)
|
|
648
|
+
|
|
649
|
+
result = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
650
|
+
|
|
651
|
+
if len(all_of) == 0:
|
|
652
|
+
result[model_type] = {"type": "object"}
|
|
653
|
+
elif len(all_of) == 1:
|
|
654
|
+
result[model_type] = all_of[0]
|
|
655
|
+
else:
|
|
656
|
+
result[model_type] = {"allOf": all_of}
|
|
657
|
+
|
|
658
|
+
return result, None
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
class Definitions:
|
|
662
|
+
"""Store definitions of the schema as we go."""
|
|
663
|
+
|
|
664
|
+
def __init__(self) -> None:
|
|
665
|
+
"""Initialize as empty."""
|
|
666
|
+
self._definitions = collections.OrderedDict() # type: MutableMapping[str, Any]
|
|
667
|
+
|
|
668
|
+
def get(self) -> Mapping[str, Any]:
|
|
669
|
+
"""Get the content."""
|
|
670
|
+
return self._definitions
|
|
671
|
+
|
|
672
|
+
def update_for(
|
|
673
|
+
self, our_type: intermediate.OurType, extension: Mapping[str, Any]
|
|
674
|
+
) -> Optional[Error]:
|
|
675
|
+
"""Update the definitions with ``extension`` related to ``our_type``."""
|
|
676
|
+
for key, definition in extension.items():
|
|
677
|
+
if key in self._definitions:
|
|
678
|
+
return Error(
|
|
679
|
+
our_type.parsed.node,
|
|
680
|
+
f"One of the JSON definitions, {key}, "
|
|
681
|
+
f"for our type {our_type.name} has been "
|
|
682
|
+
f"already provided in the definitions; "
|
|
683
|
+
f"did you already perhaps define it in another "
|
|
684
|
+
f"implementation-specific snippet?",
|
|
685
|
+
)
|
|
686
|
+
|
|
687
|
+
self._definitions[key] = definition
|
|
688
|
+
|
|
689
|
+
return None
|
|
690
|
+
|
|
691
|
+
def update(self, extension: Mapping[str, Any]) -> Optional[Error]:
|
|
692
|
+
"""Update the definitions with ``extension`` unrelated to any of our types."""
|
|
693
|
+
for key, definition in extension.items():
|
|
694
|
+
if key in self._definitions:
|
|
695
|
+
return Error(
|
|
696
|
+
None,
|
|
697
|
+
f"One of the JSON definitions, {key}, "
|
|
698
|
+
f"has been already provided in the definitions; "
|
|
699
|
+
f"did you already perhaps define it in another "
|
|
700
|
+
f"implementation-specific snippet?",
|
|
701
|
+
)
|
|
702
|
+
|
|
703
|
+
self._definitions[key] = definition
|
|
704
|
+
|
|
705
|
+
return None
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
709
|
+
def generate(
|
|
710
|
+
symbol_table: intermediate.SymbolTable,
|
|
711
|
+
spec_impls: specific_implementations.SpecificImplementations,
|
|
712
|
+
fix_pattern: Callable[[str], str],
|
|
713
|
+
) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
|
|
714
|
+
"""
|
|
715
|
+
Generate the JSON schema based on the symbol table.
|
|
716
|
+
|
|
717
|
+
The ``fix_pattern`` determines how the pattern should be translated for
|
|
718
|
+
the respective JSON schema engine.
|
|
719
|
+
|
|
720
|
+
This function is intended to be used not only by aas-core-codegen, but also for
|
|
721
|
+
downstream clients. For example, the downstream clients should use this function
|
|
722
|
+
to customize how patterns should be rendered / fixed for the respective regex
|
|
723
|
+
engine.
|
|
724
|
+
"""
|
|
725
|
+
schema_base_key = specific_implementations.ImplementationKey("schema_base.json")
|
|
726
|
+
|
|
727
|
+
schema_base_json = spec_impls.get(schema_base_key, None)
|
|
728
|
+
if schema_base_json is None:
|
|
729
|
+
return None, [
|
|
730
|
+
Error(
|
|
731
|
+
None,
|
|
732
|
+
f"The implementation snippet for the base schema "
|
|
733
|
+
f"is missing: {schema_base_key}",
|
|
734
|
+
)
|
|
735
|
+
]
|
|
736
|
+
|
|
737
|
+
schema: MutableMapping[str, Any]
|
|
738
|
+
|
|
739
|
+
try:
|
|
740
|
+
# noinspection PyTypeChecker
|
|
741
|
+
schema = json.loads(schema_base_json, object_pairs_hook=collections.OrderedDict)
|
|
742
|
+
except json.JSONDecodeError as err:
|
|
743
|
+
return None, [
|
|
744
|
+
Error(
|
|
745
|
+
None, f"Failed to parse the base schema from {schema_base_key}: {err}"
|
|
746
|
+
)
|
|
747
|
+
]
|
|
748
|
+
|
|
749
|
+
if "$id" in schema:
|
|
750
|
+
return None, [
|
|
751
|
+
Error(
|
|
752
|
+
None,
|
|
753
|
+
f"Unexpected property '$id' in the base JSON schema "
|
|
754
|
+
f"from: {schema_base_key}",
|
|
755
|
+
)
|
|
756
|
+
]
|
|
757
|
+
|
|
758
|
+
# NOTE (mristin, 2022-08-25):
|
|
759
|
+
# We use the same namespace in all the schemas for the consistency.
|
|
760
|
+
schema["$id"] = symbol_table.meta_model.xml_namespace
|
|
761
|
+
|
|
762
|
+
if "definitions" in schema:
|
|
763
|
+
return None, [
|
|
764
|
+
Error(
|
|
765
|
+
None,
|
|
766
|
+
f"The property ``definitions`` unexpected in the base JSON schema "
|
|
767
|
+
f"from: {schema_base_key}",
|
|
768
|
+
)
|
|
769
|
+
]
|
|
770
|
+
|
|
771
|
+
errors = [] # type: List[Error]
|
|
772
|
+
|
|
773
|
+
definitions = Definitions()
|
|
774
|
+
|
|
775
|
+
constraints_by_class, some_errors = infer_for_schema.infer_constraints_by_class(
|
|
776
|
+
symbol_table=symbol_table
|
|
777
|
+
)
|
|
778
|
+
|
|
779
|
+
if some_errors is not None:
|
|
780
|
+
errors.extend(some_errors)
|
|
781
|
+
|
|
782
|
+
if len(errors) > 0:
|
|
783
|
+
return None, errors
|
|
784
|
+
|
|
785
|
+
assert constraints_by_class is not None
|
|
786
|
+
|
|
787
|
+
ids_of_our_types_in_properties = (
|
|
788
|
+
intermediate.collect_ids_of_our_types_in_properties(symbol_table=symbol_table)
|
|
789
|
+
)
|
|
790
|
+
|
|
791
|
+
for our_type in symbol_table.our_types:
|
|
792
|
+
if (
|
|
793
|
+
isinstance(
|
|
794
|
+
our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
|
|
795
|
+
)
|
|
796
|
+
and our_type.is_implementation_specific
|
|
797
|
+
):
|
|
798
|
+
implementation_key = specific_implementations.ImplementationKey(
|
|
799
|
+
f"{our_type.name}.json"
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
code = spec_impls.get(implementation_key, None)
|
|
803
|
+
if code is None:
|
|
804
|
+
errors.append(
|
|
805
|
+
Error(
|
|
806
|
+
our_type.parsed.node,
|
|
807
|
+
f"The implementation is missing "
|
|
808
|
+
f"for the implementation-specific class: {implementation_key}",
|
|
809
|
+
)
|
|
810
|
+
)
|
|
811
|
+
continue
|
|
812
|
+
|
|
813
|
+
try:
|
|
814
|
+
# noinspection PyTypeChecker
|
|
815
|
+
extension = json.loads(code, object_pairs_hook=collections.OrderedDict)
|
|
816
|
+
except Exception as err:
|
|
817
|
+
errors.append(
|
|
818
|
+
Error(
|
|
819
|
+
our_type.parsed.node,
|
|
820
|
+
f"Failed to parse the JSON out of "
|
|
821
|
+
f"the specific implementation {implementation_key}: {err}",
|
|
822
|
+
)
|
|
823
|
+
)
|
|
824
|
+
continue
|
|
825
|
+
|
|
826
|
+
if not isinstance(extension, dict):
|
|
827
|
+
errors.append(
|
|
828
|
+
Error(
|
|
829
|
+
our_type.parsed.node,
|
|
830
|
+
f"Expected the implementation-specific snippet "
|
|
831
|
+
f"at {implementation_key} to be a JSON object, "
|
|
832
|
+
f"but got: {type(extension)}",
|
|
833
|
+
)
|
|
834
|
+
)
|
|
835
|
+
continue
|
|
836
|
+
|
|
837
|
+
update_error = definitions.update_for(
|
|
838
|
+
our_type=our_type, extension=extension
|
|
839
|
+
)
|
|
840
|
+
if update_error is not None:
|
|
841
|
+
errors.append(update_error)
|
|
842
|
+
|
|
843
|
+
else:
|
|
844
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
845
|
+
update_error = definitions.update_for(
|
|
846
|
+
our_type=our_type,
|
|
847
|
+
extension=_define_for_enumeration(enumeration=our_type),
|
|
848
|
+
)
|
|
849
|
+
if update_error is not None:
|
|
850
|
+
errors.append(update_error)
|
|
851
|
+
|
|
852
|
+
elif isinstance(our_type, intermediate.ConstrainedPrimitive):
|
|
853
|
+
# NOTE (mristin, 2022-02-11):
|
|
854
|
+
# We in-line the constraints from the constrained primitives directly
|
|
855
|
+
# in the properties. We do not want to introduce separate definitions
|
|
856
|
+
# for them as that would make it more difficult for downstream code
|
|
857
|
+
# generators to generate meaningful code (*e.g.*, code generators for
|
|
858
|
+
# OpenAPI3).
|
|
859
|
+
continue
|
|
860
|
+
|
|
861
|
+
elif isinstance(
|
|
862
|
+
our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
|
|
863
|
+
):
|
|
864
|
+
if len(our_type.concrete_descendants) > 0:
|
|
865
|
+
# region Inheritable
|
|
866
|
+
inheritable, definition_errors = _generate_inheritable_definition(
|
|
867
|
+
cls=our_type,
|
|
868
|
+
constraints_by_property=constraints_by_class[our_type],
|
|
869
|
+
fix_pattern=fix_pattern,
|
|
870
|
+
)
|
|
871
|
+
|
|
872
|
+
if definition_errors is not None:
|
|
873
|
+
errors.extend(definition_errors)
|
|
874
|
+
continue
|
|
875
|
+
|
|
876
|
+
assert inheritable is not None
|
|
877
|
+
update_error = definitions.update_for(
|
|
878
|
+
our_type=our_type, extension=inheritable
|
|
879
|
+
)
|
|
880
|
+
if update_error is not None:
|
|
881
|
+
errors.append(update_error)
|
|
882
|
+
# endregion
|
|
883
|
+
|
|
884
|
+
# region Choice
|
|
885
|
+
if isinstance(our_type, intermediate.ConcreteClass) or (
|
|
886
|
+
isinstance(our_type, intermediate.AbstractClass)
|
|
887
|
+
and id(our_type) in ids_of_our_types_in_properties
|
|
888
|
+
):
|
|
889
|
+
update_error = definitions.update_for(
|
|
890
|
+
our_type=our_type,
|
|
891
|
+
extension=_generate_choice_definition(cls=our_type),
|
|
892
|
+
)
|
|
893
|
+
if update_error is not None:
|
|
894
|
+
errors.append(update_error)
|
|
895
|
+
# endregion
|
|
896
|
+
|
|
897
|
+
if isinstance(our_type, intermediate.ConcreteClass):
|
|
898
|
+
definition, definition_errors = _generate_concrete_definition(
|
|
899
|
+
cls=our_type,
|
|
900
|
+
constraints_by_property=constraints_by_class[our_type],
|
|
901
|
+
fix_pattern=fix_pattern,
|
|
902
|
+
)
|
|
903
|
+
if definition_errors is not None:
|
|
904
|
+
errors.extend(definition_errors)
|
|
905
|
+
continue
|
|
906
|
+
|
|
907
|
+
assert definition is not None
|
|
908
|
+
|
|
909
|
+
update_error = definitions.update_for(
|
|
910
|
+
our_type=our_type, extension=definition
|
|
911
|
+
)
|
|
912
|
+
if update_error is not None:
|
|
913
|
+
errors.append(update_error)
|
|
914
|
+
else:
|
|
915
|
+
assert isinstance(our_type, intermediate.AbstractClass)
|
|
916
|
+
|
|
917
|
+
# We do not generate any concrete definition for an abstract class.
|
|
918
|
+
pass
|
|
919
|
+
else:
|
|
920
|
+
assert_never(our_type)
|
|
921
|
+
|
|
922
|
+
if len(errors) > 0:
|
|
923
|
+
return None, errors
|
|
924
|
+
|
|
925
|
+
model_types = sorted(
|
|
926
|
+
naming.json_model_type(cls.name)
|
|
927
|
+
for cls in symbol_table.concrete_classes
|
|
928
|
+
if cls.serialization.with_model_type
|
|
929
|
+
) # type: List[Identifier]
|
|
930
|
+
|
|
931
|
+
definitions.update(
|
|
932
|
+
{
|
|
933
|
+
"ModelType": collections.OrderedDict(
|
|
934
|
+
[("type", "string"), ("enum", model_types)]
|
|
935
|
+
)
|
|
936
|
+
}
|
|
937
|
+
)
|
|
938
|
+
|
|
939
|
+
definitions_mapping = definitions.get()
|
|
940
|
+
|
|
941
|
+
schema["definitions"] = collections.OrderedDict(
|
|
942
|
+
[
|
|
943
|
+
(name, definitions_mapping[name])
|
|
944
|
+
for name in sorted(definitions_mapping.keys())
|
|
945
|
+
]
|
|
946
|
+
)
|
|
947
|
+
|
|
948
|
+
return Stripped(json.dumps(schema, indent=2)), None
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
def execute(context: run.Context, stdout: TextIO, stderr: TextIO) -> int:
|
|
952
|
+
"""Generate the code."""
|
|
953
|
+
code, errors = generate(
|
|
954
|
+
symbol_table=context.symbol_table,
|
|
955
|
+
spec_impls=context.spec_impls,
|
|
956
|
+
fix_pattern=fix_pattern_for_utf16,
|
|
957
|
+
)
|
|
958
|
+
|
|
959
|
+
if errors is not None:
|
|
960
|
+
run.write_error_report(
|
|
961
|
+
message=f"Failed to generate the JSON Schema "
|
|
962
|
+
f"based on {context.model_path}",
|
|
963
|
+
errors=[context.lineno_columner.error_message(error) for error in errors],
|
|
964
|
+
stderr=stderr,
|
|
965
|
+
)
|
|
966
|
+
return 1
|
|
967
|
+
|
|
968
|
+
assert code is not None
|
|
969
|
+
|
|
970
|
+
pth = context.output_dir / "schema.json"
|
|
971
|
+
try:
|
|
972
|
+
pth.write_text(code, encoding="utf-8")
|
|
973
|
+
except Exception as exception:
|
|
974
|
+
run.write_error_report(
|
|
975
|
+
message=f"Failed to write the JSON schema to {pth}",
|
|
976
|
+
errors=[str(exception)],
|
|
977
|
+
stderr=stderr,
|
|
978
|
+
)
|
|
979
|
+
return 1
|
|
980
|
+
|
|
981
|
+
stdout.write(f"Code generated to: {context.output_dir}\n")
|
|
982
|
+
return 0
|