@typespec/http-client-python 0.28.2 → 0.28.3
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.
- package/dist/emitter/code-model.d.ts.map +1 -1
- package/dist/emitter/code-model.js +6 -6
- package/dist/emitter/code-model.js.map +1 -1
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +27 -28
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/lib.d.ts +4 -1
- package/dist/emitter/lib.d.ts.map +1 -1
- package/dist/emitter/lib.js.map +1 -1
- package/dist/emitter/system-requirements.js +6 -4
- package/dist/emitter/system-requirements.js.map +1 -1
- package/dist/emitter/types.d.ts +2 -5
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js +55 -58
- package/dist/emitter/types.js.map +1 -1
- package/dist/emitter/utils.d.ts.map +1 -1
- package/dist/emitter/utils.js +16 -17
- package/dist/emitter/utils.js.map +1 -1
- package/emitter/src/code-model.ts +6 -13
- package/emitter/src/emitter.ts +29 -31
- package/emitter/src/lib.ts +4 -0
- package/emitter/src/system-requirements.ts +4 -4
- package/emitter/src/types.ts +67 -57
- package/emitter/src/utils.ts +16 -18
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/Build-Packages.ps1 +62 -37
- package/eng/scripts/Check-GitChanges.ps1 +30 -3
- package/eng/scripts/Functions.ps1 +54 -15
- package/eng/scripts/Generate.ps1 +42 -8
- package/eng/scripts/Generation.psm1 +44 -15
- package/eng/scripts/Initialize-Repository.ps1 +29 -11
- package/eng/scripts/Test-Packages.ps1 +47 -31
- package/eng/scripts/ci/config/eslint-ci.config.mjs +54 -0
- package/eng/scripts/ci/dev_requirements.txt +1 -0
- package/eng/scripts/ci/format.ts +232 -2
- package/eng/scripts/ci/lint.ts +216 -20
- package/eng/scripts/ci/regenerate-common.ts +18 -14
- package/eng/scripts/ci/regenerate.ts +305 -68
- package/eng/scripts/ci/run-tests.ts +402 -0
- package/eng/scripts/ci/run_mypy.py +4 -3
- package/eng/scripts/ci/run_pylint.py +4 -3
- package/eng/scripts/ci/run_pyright.py +4 -3
- package/eng/scripts/ci/typecheck.ts +225 -0
- package/eng/scripts/ci/util.py +1 -1
- package/eng/scripts/ci/utils.ts +5 -5
- package/eng/scripts/setup/__pycache__/package_manager.cpython-311.pyc +0 -0
- package/eng/scripts/setup/__pycache__/venvtools.cpython-311.pyc +0 -0
- package/eng/scripts/setup/build.ts +1 -1
- package/eng/scripts/setup/build_pygen_wheel.py +1 -0
- package/eng/scripts/setup/install.py +1 -0
- package/eng/scripts/setup/prepare.py +1 -0
- package/eng/scripts/setup/prepare.ts +1 -1
- package/eng/scripts/setup/run_tsp.py +3 -3
- package/eng/scripts/setup/system-requirements.ts +8 -4
- package/eng/scripts/setup/venvtools.py +1 -0
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +157 -64
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +157 -64
- package/package.json +48 -42
- package/eng/scripts/ci/run-ci.ts +0 -89
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_commonproperties_async.py +0 -94
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_largeheader_async.py +0 -30
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_nonresource_async.py +0 -36
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +0 -205
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_resource_async.py +0 -478
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_access_async.py +0 -101
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_api_version_header_async.py +0 -18
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_api_version_path_async.py +0 -18
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_api_version_query_async.py +0 -18
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_default_value_async.py +0 -46
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py +0 -58
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_location_async.py +0 -82
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_deserialize_empty_string_as_null_async.py +0 -20
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_flatten_async.py +0 -115
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_hierrarchy_building_async.py +0 -53
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_next_link_verb_async.py +0 -28
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_override_async.py +0 -106
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_usage_async.py +0 -38
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_basic_async.py +0 -76
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_lro_rpc_async.py +0 -22
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_lro_standard_async.py +0 -39
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_model_async.py +0 -33
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_page_async.py +0 -80
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_scalar_async.py +0 -41
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_traits_async.py +0 -87
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_encode_duration_async.py +0 -19
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_example_basic_async.py +0 -30
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_payload_pageable_async.py +0 -19
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_method_subscription_id_async.py +0 -248
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_async.py +0 -110
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_multi_service_shared_models_async.py +0 -132
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_special_headers_client_request_id_async.py +0 -30
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_versioning_previewversion_async.py +0 -53
- package/generator/test/azure/mock_api_tests/asynctests/test_client_namespace_async.py +0 -34
- package/generator/test/azure/mock_api_tests/asynctests/test_client_naming_async.py +0 -69
- package/generator/test/azure/mock_api_tests/asynctests/test_client_naming_enum_conflict_async.py +0 -37
- package/generator/test/azure/mock_api_tests/asynctests/test_client_overload_async.py +0 -27
- package/generator/test/azure/mock_api_tests/asynctests/test_client_structure_async.py +0 -64
- package/generator/test/azure/mock_api_tests/asynctests/test_client_structure_clientoperationgroup_async.py +0 -31
- package/generator/test/azure/mock_api_tests/asynctests/test_encode_duration_async.py +0 -63
- package/generator/test/azure/mock_api_tests/asynctests/test_encode_numeric_async.py +0 -35
- package/generator/test/azure/mock_api_tests/asynctests/test_parameters_basic_async.py +0 -24
- package/generator/test/azure/mock_api_tests/asynctests/test_parameters_spread_async.py +0 -76
- package/generator/test/azure/mock_api_tests/asynctests/test_payload_content_negotiation_async.py +0 -37
- package/generator/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py +0 -216
- package/generator/test/azure/mock_api_tests/asynctests/test_resiliency_srv_driven_async.py +0 -130
- package/generator/test/azure/mock_api_tests/asynctests/test_serialization_encoded_name_json_async.py +0 -24
- package/generator/test/azure/mock_api_tests/asynctests/test_service_multi_service_async.py +0 -31
- package/generator/test/azure/mock_api_tests/asynctests/test_special_words_async.py +0 -71
- package/generator/test/azure/mock_api_tests/conftest.py +0 -207
- package/generator/test/azure/mock_api_tests/data/image.jpg +0 -0
- package/generator/test/azure/mock_api_tests/data/image.png +0 -0
- package/generator/test/azure/mock_api_tests/test_azure_arm_commonproperties.py +0 -89
- package/generator/test/azure/mock_api_tests/test_azure_arm_largeheader.py +0 -27
- package/generator/test/azure/mock_api_tests/test_azure_arm_nonresource.py +0 -34
- package/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +0 -180
- package/generator/test/azure/mock_api_tests/test_azure_arm_resource.py +0 -436
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_access.py +0 -92
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_api_version_header.py +0 -17
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_api_version_path.py +0 -17
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_api_version_query.py +0 -17
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_default_value.py +0 -42
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_initialization.py +0 -51
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_location.py +0 -70
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_deserialize_empty_string_as_null.py +0 -19
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_flatten.py +0 -104
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_hierrarchy_building.py +0 -45
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_next_link_verb.py +0 -27
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_override.py +0 -102
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_usage.py +0 -32
- package/generator/test/azure/mock_api_tests/test_azure_core_basic.py +0 -70
- package/generator/test/azure/mock_api_tests/test_azure_core_lro_rpc.py +0 -20
- package/generator/test/azure/mock_api_tests/test_azure_core_lro_standard.py +0 -32
- package/generator/test/azure/mock_api_tests/test_azure_core_model.py +0 -30
- package/generator/test/azure/mock_api_tests/test_azure_core_page.py +0 -71
- package/generator/test/azure/mock_api_tests/test_azure_core_scalar.py +0 -35
- package/generator/test/azure/mock_api_tests/test_azure_core_traits.py +0 -85
- package/generator/test/azure/mock_api_tests/test_azure_encode_duration.py +0 -18
- package/generator/test/azure/mock_api_tests/test_azure_example_basic.py +0 -29
- package/generator/test/azure/mock_api_tests/test_azure_payload_pageable.py +0 -18
- package/generator/test/azure/mock_api_tests/test_azure_resource_manager_method_subscription_id.py +0 -235
- package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service.py +0 -104
- package/generator/test/azure/mock_api_tests/test_azure_resource_manager_multi_service_shared_models.py +0 -128
- package/generator/test/azure/mock_api_tests/test_azure_special_headers_client_request_id.py +0 -29
- package/generator/test/azure/mock_api_tests/test_azure_versioning_previewversion.py +0 -50
- package/generator/test/azure/mock_api_tests/test_clear_output_folder.py +0 -23
- package/generator/test/azure/mock_api_tests/test_client_namespace.py +0 -32
- package/generator/test/azure/mock_api_tests/test_client_naming.py +0 -57
- package/generator/test/azure/mock_api_tests/test_client_naming_enum_conflict.py +0 -35
- package/generator/test/azure/mock_api_tests/test_client_overload.py +0 -25
- package/generator/test/azure/mock_api_tests/test_client_structure.py +0 -60
- package/generator/test/azure/mock_api_tests/test_client_structure_clientoperationgroup.py +0 -29
- package/generator/test/azure/mock_api_tests/test_encode_duration.py +0 -60
- package/generator/test/azure/mock_api_tests/test_encode_numeric.py +0 -31
- package/generator/test/azure/mock_api_tests/test_model_base_flatten_compatibility.py +0 -251
- package/generator/test/azure/mock_api_tests/test_parameters_basic.py +0 -22
- package/generator/test/azure/mock_api_tests/test_parameters_spread.py +0 -66
- package/generator/test/azure/mock_api_tests/test_payload_content_negotiation.py +0 -33
- package/generator/test/azure/mock_api_tests/test_payload_multipart.py +0 -198
- package/generator/test/azure/mock_api_tests/test_resiliency_srv_driven.py +0 -124
- package/generator/test/azure/mock_api_tests/test_serialization_encoded_name_json.py +0 -21
- package/generator/test/azure/mock_api_tests/test_service_multi_service.py +0 -29
- package/generator/test/azure/mock_api_tests/test_special_words.py +0 -63
- package/generator/test/azure/requirements.txt +0 -125
- package/generator/test/azure/tox.ini +0 -64
- package/generator/test/data/image.jpg +0 -0
- package/generator/test/data/image.png +0 -0
- package/generator/test/dev_requirements.txt +0 -8
- package/generator/test/generic_mock_api_tests/asynctests/test_authentication_async.py +0 -140
- package/generator/test/generic_mock_api_tests/asynctests/test_encode_array_async.py +0 -139
- package/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py +0 -132
- package/generator/test/generic_mock_api_tests/asynctests/test_encode_datetime_async.py +0 -127
- package/generator/test/generic_mock_api_tests/asynctests/test_headasboolean_async.py +0 -35
- package/generator/test/generic_mock_api_tests/asynctests/test_parameters_body_optionality_async.py +0 -30
- package/generator/test/generic_mock_api_tests/asynctests/test_parameters_collection_format_async.py +0 -38
- package/generator/test/generic_mock_api_tests/asynctests/test_parameters_path_async.py +0 -24
- package/generator/test/generic_mock_api_tests/asynctests/test_parameters_query_async.py +0 -18
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_json_merge_patch_async.py +0 -98
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_media_type_async.py +0 -27
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py +0 -134
- package/generator/test/generic_mock_api_tests/asynctests/test_payload_xml_async.py +0 -150
- package/generator/test/generic_mock_api_tests/asynctests/test_response_status_code_range_async.py +0 -38
- package/generator/test/generic_mock_api_tests/asynctests/test_routes_async.py +0 -331
- package/generator/test/generic_mock_api_tests/asynctests/test_server_endpoint_not_defined_async.py +0 -18
- package/generator/test/generic_mock_api_tests/asynctests/test_server_path_multiple_async.py +0 -25
- package/generator/test/generic_mock_api_tests/asynctests/test_server_path_single_async.py +0 -18
- package/generator/test/generic_mock_api_tests/asynctests/test_server_versions_not_versioned_async.py +0 -28
- package/generator/test/generic_mock_api_tests/asynctests/test_server_versions_versioned_async.py +0 -34
- package/generator/test/generic_mock_api_tests/asynctests/test_special_headers_conditional_request_async.py +0 -38
- package/generator/test/generic_mock_api_tests/asynctests/test_special_headers_repeatability_async.py +0 -19
- package/generator/test/generic_mock_api_tests/asynctests/test_specs_documentation_async.py +0 -59
- package/generator/test/generic_mock_api_tests/asynctests/test_streaming_jsonl_async.py +0 -27
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py +0 -127
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py +0 -98
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py +0 -25
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +0 -27
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_file_async.py +0 -59
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py +0 -32
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py +0 -70
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py +0 -85
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py +0 -34
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py +0 -34
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py +0 -67
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py +0 -32
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py +0 -47
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py +0 -353
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py +0 -110
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py +0 -197
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py +0 -315
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py +0 -60
- package/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py +0 -90
- package/generator/test/generic_mock_api_tests/asynctests/test_versioning_added_async.py +0 -36
- package/generator/test/generic_mock_api_tests/asynctests/test_versioning_made_optional_async.py +0 -21
- package/generator/test/generic_mock_api_tests/asynctests/test_versioning_removed_async.py +0 -39
- package/generator/test/generic_mock_api_tests/asynctests/test_versioning_renamed_from_async.py +0 -29
- package/generator/test/generic_mock_api_tests/asynctests/test_versioning_return_type_changed_from_async.py +0 -18
- package/generator/test/generic_mock_api_tests/asynctests/test_versioning_type_changed_from_async.py +0 -22
- package/generator/test/generic_mock_api_tests/conftest.py +0 -75
- package/generator/test/generic_mock_api_tests/data/image.jpg +0 -0
- package/generator/test/generic_mock_api_tests/data/image.png +0 -0
- package/generator/test/generic_mock_api_tests/test_authentication.py +0 -130
- package/generator/test/generic_mock_api_tests/test_encode_array.py +0 -126
- package/generator/test/generic_mock_api_tests/test_encode_bytes.py +0 -128
- package/generator/test/generic_mock_api_tests/test_encode_datetime.py +0 -123
- package/generator/test/generic_mock_api_tests/test_headasboolean.py +0 -33
- package/generator/test/generic_mock_api_tests/test_parameters_body_optionality.py +0 -27
- package/generator/test/generic_mock_api_tests/test_parameters_collection_format.py +0 -33
- package/generator/test/generic_mock_api_tests/test_parameters_path.py +0 -22
- package/generator/test/generic_mock_api_tests/test_parameters_query.py +0 -17
- package/generator/test/generic_mock_api_tests/test_payload_json_merge_patch.py +0 -93
- package/generator/test/generic_mock_api_tests/test_payload_media_type.py +0 -25
- package/generator/test/generic_mock_api_tests/test_payload_pageable.py +0 -99
- package/generator/test/generic_mock_api_tests/test_payload_xml.py +0 -135
- package/generator/test/generic_mock_api_tests/test_response_status_code_range.py +0 -36
- package/generator/test/generic_mock_api_tests/test_routes.py +0 -285
- package/generator/test/generic_mock_api_tests/test_server_endpoint_not_defined.py +0 -17
- package/generator/test/generic_mock_api_tests/test_server_path_multiple.py +0 -21
- package/generator/test/generic_mock_api_tests/test_server_path_single.py +0 -17
- package/generator/test/generic_mock_api_tests/test_server_versions_not_versioned.py +0 -25
- package/generator/test/generic_mock_api_tests/test_server_versions_versioned.py +0 -30
- package/generator/test/generic_mock_api_tests/test_special_headers_conditional_request.py +0 -34
- package/generator/test/generic_mock_api_tests/test_special_headers_repeatability.py +0 -18
- package/generator/test/generic_mock_api_tests/test_specs_documentation.py +0 -51
- package/generator/test/generic_mock_api_tests/test_streaming_jsonl.py +0 -25
- package/generator/test/generic_mock_api_tests/test_typetest_array.py +0 -111
- package/generator/test/generic_mock_api_tests/test_typetest_dictionary.py +0 -86
- package/generator/test/generic_mock_api_tests/test_typetest_enum_extensible.py +0 -23
- package/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py +0 -25
- package/generator/test/generic_mock_api_tests/test_typetest_file.py +0 -52
- package/generator/test/generic_mock_api_tests/test_typetest_model_empty.py +0 -29
- package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py +0 -58
- package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py +0 -79
- package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_not_discriminated.py +0 -31
- package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_recursive.py +0 -32
- package/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_single_discriminator.py +0 -60
- package/generator/test/generic_mock_api_tests/test_typetest_model_usage.py +0 -28
- package/generator/test/generic_mock_api_tests/test_typetest_model_visibility.py +0 -40
- package/generator/test/generic_mock_api_tests/test_typetest_property_additionalproperties.py +0 -314
- package/generator/test/generic_mock_api_tests/test_typetest_property_nullable.py +0 -102
- package/generator/test/generic_mock_api_tests/test_typetest_property_optional.py +0 -174
- package/generator/test/generic_mock_api_tests/test_typetest_property_valuetypes.py +0 -286
- package/generator/test/generic_mock_api_tests/test_typetest_scalar.py +0 -53
- package/generator/test/generic_mock_api_tests/test_typetest_union.py +0 -80
- package/generator/test/generic_mock_api_tests/test_typetest_union_discriminated.py +0 -290
- package/generator/test/generic_mock_api_tests/test_versioning_added.py +0 -33
- package/generator/test/generic_mock_api_tests/test_versioning_made_optional.py +0 -20
- package/generator/test/generic_mock_api_tests/test_versioning_removed.py +0 -37
- package/generator/test/generic_mock_api_tests/test_versioning_renamed_from.py +0 -27
- package/generator/test/generic_mock_api_tests/test_versioning_return_type_changed_from.py +0 -17
- package/generator/test/generic_mock_api_tests/test_versioning_type_changed_from.py +0 -21
- package/generator/test/unbranded/mock_api_tests/asynctests/test_auth_flow_async.py +0 -19
- package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_duration_async.py +0 -63
- package/generator/test/unbranded/mock_api_tests/asynctests/test_encode_numeric_async.py +0 -35
- package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_basic_async.py +0 -24
- package/generator/test/unbranded/mock_api_tests/asynctests/test_parameters_spread_async.py +0 -76
- package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_content_negotiation_async.py +0 -37
- package/generator/test/unbranded/mock_api_tests/asynctests/test_payload_multipart_async.py +0 -218
- package/generator/test/unbranded/mock_api_tests/asynctests/test_serialization_encoded_name_json_async.py +0 -24
- package/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py +0 -73
- package/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py +0 -24
- package/generator/test/unbranded/mock_api_tests/conftest.py +0 -91
- package/generator/test/unbranded/mock_api_tests/data/image.jpg +0 -0
- package/generator/test/unbranded/mock_api_tests/data/image.png +0 -0
- package/generator/test/unbranded/mock_api_tests/test_auth_flow.py +0 -17
- package/generator/test/unbranded/mock_api_tests/test_encode_duration.py +0 -60
- package/generator/test/unbranded/mock_api_tests/test_encode_numeric.py +0 -32
- package/generator/test/unbranded/mock_api_tests/test_parameters_basic.py +0 -22
- package/generator/test/unbranded/mock_api_tests/test_parameters_spread.py +0 -66
- package/generator/test/unbranded/mock_api_tests/test_payload_content_negotiation.py +0 -33
- package/generator/test/unbranded/mock_api_tests/test_payload_multipart.py +0 -200
- package/generator/test/unbranded/mock_api_tests/test_serialization_encoded_name_json.py +0 -22
- package/generator/test/unbranded/mock_api_tests/test_special_words.py +0 -66
- package/generator/test/unbranded/mock_api_tests/test_unbranded.py +0 -65
- package/generator/test/unbranded/requirements.txt +0 -69
- package/generator/test/unbranded/tox.ini +0 -64
- package/generator/test/unittests/conftest.py +0 -15
- package/generator/test/unittests/requirements.txt +0 -3
- package/generator/test/unittests/test_enums.py +0 -89
- package/generator/test/unittests/test_model_base_serialization.py +0 -4906
- package/generator/test/unittests/test_model_base_xml_serialization.py +0 -1239
- package/generator/test/unittests/test_name_converter.py +0 -35
- package/generator/test/unittests/test_optional_return_type.py +0 -268
- package/generator/test/unittests/test_parameter_ordering.py +0 -104
- package/generator/test/unittests/test_sort_schema.py +0 -93
- package/generator/test/unittests/tox.ini +0 -5
- /package/eng/scripts/ci/{mypy.ini → config/mypy.ini} +0 -0
- /package/eng/scripts/ci/{pylintrc → config/pylintrc} +0 -0
- /package/eng/scripts/ci/{pyproject.toml → config/pyproject.toml} +0 -0
- /package/eng/scripts/ci/{pyrightconfig.json → config/pyrightconfig.json} +0 -0
package/emitter/src/emitter.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { emitCodeModel } from "./code-model.js";
|
|
|
10
10
|
import { saveCodeModelAsYaml } from "./external-process.js";
|
|
11
11
|
import { PythonEmitterOptions, PythonSdkContext, reportDiagnostic } from "./lib.js";
|
|
12
12
|
import { runPython3 } from "./run-python3.js";
|
|
13
|
-
import { disableGenerationMap, simpleTypesMap, typesMap } from "./types.js";
|
|
14
13
|
import { getRootNamespace, md2Rst } from "./utils.js";
|
|
15
14
|
|
|
16
15
|
function addDefaultOptions(sdkContext: PythonSdkContext) {
|
|
@@ -59,6 +58,9 @@ async function createPythonSdkContext(
|
|
|
59
58
|
return {
|
|
60
59
|
...sdkContext,
|
|
61
60
|
__endpointPathParameters: [],
|
|
61
|
+
__typesMap: new Map(),
|
|
62
|
+
__simpleTypesMap: new Map(),
|
|
63
|
+
__disableGenerationMap: new Set(),
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
66
|
|
|
@@ -100,12 +102,6 @@ function walkThroughNodes(yamlMap: Record<string, any>): Record<string, any> {
|
|
|
100
102
|
return yamlMap;
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
function cleanAllCache() {
|
|
104
|
-
typesMap.clear();
|
|
105
|
-
simpleTypesMap.clear();
|
|
106
|
-
disableGenerationMap.clear();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
105
|
export async function $onEmit(context: EmitContext<PythonEmitterOptions>) {
|
|
110
106
|
try {
|
|
111
107
|
await onEmitMain(context);
|
|
@@ -124,9 +120,6 @@ export async function $onEmit(context: EmitContext<PythonEmitterOptions>) {
|
|
|
124
120
|
}
|
|
125
121
|
|
|
126
122
|
async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
|
|
127
|
-
// clean all cache to make sure emitter could work in watch mode
|
|
128
|
-
cleanAllCache();
|
|
129
|
-
|
|
130
123
|
const program = context.program;
|
|
131
124
|
const sdkContext = await createPythonSdkContext(context);
|
|
132
125
|
const root = path.join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
@@ -168,7 +161,7 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
|
|
|
168
161
|
try {
|
|
169
162
|
await runPython3(path.join(root, "/eng/scripts/setup/install.py"));
|
|
170
163
|
await runPython3(path.join(root, "/eng/scripts/setup/prepare.py"));
|
|
171
|
-
} catch
|
|
164
|
+
} catch {
|
|
172
165
|
// if the python env is not ready, we use pyodide instead
|
|
173
166
|
resolvedOptions["use-pyodide"] = true;
|
|
174
167
|
}
|
|
@@ -250,7 +243,7 @@ async function onEmitMain(context: EmitContext<PythonEmitterOptions>) {
|
|
|
250
243
|
execSync(
|
|
251
244
|
`${venvPath} -m black --line-length=120 --quiet --fast ${outputDir} --exclude "${excludePattern}"`,
|
|
252
245
|
);
|
|
253
|
-
checkForPylintIssues(outputDir, excludePattern);
|
|
246
|
+
await checkForPylintIssues(outputDir, excludePattern);
|
|
254
247
|
}
|
|
255
248
|
}
|
|
256
249
|
}
|
|
@@ -269,7 +262,7 @@ async function setupPyodideCall(root: string) {
|
|
|
269
262
|
if (lockAge > 300) {
|
|
270
263
|
fs.unlinkSync(micropipLockPath);
|
|
271
264
|
}
|
|
272
|
-
} catch
|
|
265
|
+
} catch {
|
|
273
266
|
// ignore
|
|
274
267
|
}
|
|
275
268
|
}
|
|
@@ -288,14 +281,14 @@ async function setupPyodideCall(root: string) {
|
|
|
288
281
|
fs.closeSync(fd);
|
|
289
282
|
fs.unlinkSync(micropipLockPath);
|
|
290
283
|
break;
|
|
291
|
-
} catch
|
|
284
|
+
} catch {
|
|
292
285
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
293
286
|
}
|
|
294
287
|
}
|
|
295
288
|
return pyodide;
|
|
296
289
|
}
|
|
297
290
|
|
|
298
|
-
function checkForPylintIssues(outputDir: string, excludePattern: string) {
|
|
291
|
+
async function checkForPylintIssues(outputDir: string, excludePattern: string) {
|
|
299
292
|
const excludeRegex = new RegExp(excludePattern);
|
|
300
293
|
|
|
301
294
|
const shouldExcludePath = (filePath: string): boolean => {
|
|
@@ -304,9 +297,8 @@ function checkForPylintIssues(outputDir: string, excludePattern: string) {
|
|
|
304
297
|
return excludeRegex.test(normalizedPath);
|
|
305
298
|
};
|
|
306
299
|
|
|
307
|
-
const processFile = (filePath: string) => {
|
|
308
|
-
let fileContent;
|
|
309
|
-
fileContent = fs.readFileSync(filePath, "utf-8");
|
|
300
|
+
const processFile = async (filePath: string) => {
|
|
301
|
+
let fileContent = await fs.promises.readFile(filePath, "utf-8");
|
|
310
302
|
const pylintDisables: string[] = [];
|
|
311
303
|
const lineEnding = fileContent.includes("\r\n") && os.platform() === "win32" ? "\r\n" : "\n";
|
|
312
304
|
const lines: string[] = fileContent.split(lineEnding);
|
|
@@ -321,32 +313,38 @@ function checkForPylintIssues(outputDir: string, excludePattern: string) {
|
|
|
321
313
|
fileContent = lines[0].includes("pylint: disable=")
|
|
322
314
|
? [lines[0] + "," + pylintDisables.join(",")].concat(lines.slice(1)).join(lineEnding)
|
|
323
315
|
: `# pylint: disable=${pylintDisables.join(",")}${lineEnding}` + fileContent;
|
|
316
|
+
await fs.promises.writeFile(filePath, fileContent);
|
|
324
317
|
}
|
|
325
318
|
}
|
|
326
|
-
|
|
327
|
-
fs.writeFileSync(filePath, fileContent);
|
|
328
319
|
};
|
|
329
320
|
|
|
330
|
-
const
|
|
321
|
+
const collectPythonFiles = async (dir: string): Promise<string[]> => {
|
|
331
322
|
if (shouldExcludePath(dir)) {
|
|
332
|
-
return;
|
|
323
|
+
return [];
|
|
333
324
|
}
|
|
334
325
|
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
326
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
327
|
+
|
|
328
|
+
const promises = entries.map(async (entry) => {
|
|
329
|
+
const filePath = path.join(dir, entry.name);
|
|
338
330
|
|
|
339
331
|
if (shouldExcludePath(filePath)) {
|
|
340
|
-
return;
|
|
332
|
+
return [];
|
|
341
333
|
}
|
|
342
334
|
|
|
343
|
-
if (
|
|
344
|
-
|
|
345
|
-
} else if (
|
|
346
|
-
|
|
335
|
+
if (entry.isDirectory()) {
|
|
336
|
+
return collectPythonFiles(filePath);
|
|
337
|
+
} else if (entry.name.endsWith(".py")) {
|
|
338
|
+
return [filePath];
|
|
347
339
|
}
|
|
340
|
+
return [];
|
|
348
341
|
});
|
|
342
|
+
|
|
343
|
+
const results = await Promise.all(promises);
|
|
344
|
+
return results.flat();
|
|
349
345
|
};
|
|
350
346
|
|
|
351
|
-
|
|
347
|
+
// Collect all Python files first, then process in parallel
|
|
348
|
+
const pythonFiles = await collectPythonFiles(outputDir);
|
|
349
|
+
await Promise.all(pythonFiles.map(processFile));
|
|
352
350
|
}
|
package/emitter/src/lib.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SdkContext,
|
|
3
|
+
SdkType,
|
|
3
4
|
UnbrandedSdkEmitterOptions,
|
|
4
5
|
} from "@azure-tools/typespec-client-generator-core";
|
|
5
6
|
import { createTypeSpecLibrary, JSONSchemaType, paramMessage } from "@typespec/compiler";
|
|
@@ -28,6 +29,9 @@ export interface PythonEmitterOptions {
|
|
|
28
29
|
|
|
29
30
|
export interface PythonSdkContext extends SdkContext<PythonEmitterOptions> {
|
|
30
31
|
__endpointPathParameters: Record<string, any>[];
|
|
32
|
+
__typesMap: Map<SdkType, Record<string, any>>;
|
|
33
|
+
__simpleTypesMap: Map<string | null, Record<string, any>>;
|
|
34
|
+
__disableGenerationMap: Set<SdkType>;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export const PythonEmitterOptionsSchema: JSONSchemaType<PythonEmitterOptions> = {
|
|
@@ -16,8 +16,8 @@ const execute = (
|
|
|
16
16
|
options.onCreate(cp);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
options.onStdOutData
|
|
20
|
-
options.onStdErrData
|
|
19
|
+
if (options.onStdOutData) cp.stdout.on("data", options.onStdOutData);
|
|
20
|
+
if (options.onStdErrData) cp.stderr.on("data", options.onStdErrData);
|
|
21
21
|
|
|
22
22
|
let err = "";
|
|
23
23
|
let out = "";
|
|
@@ -34,7 +34,7 @@ const execute = (
|
|
|
34
34
|
cp.on("error", (err) => {
|
|
35
35
|
reject(err);
|
|
36
36
|
});
|
|
37
|
-
cp.on("close", (code,
|
|
37
|
+
cp.on("close", (code, _signal) =>
|
|
38
38
|
resolve({
|
|
39
39
|
stdout: out,
|
|
40
40
|
stderr: err,
|
|
@@ -110,7 +110,7 @@ const tryPython = async (
|
|
|
110
110
|
`"${PRINT_PYTHON_VERSION_SCRIPT}"`,
|
|
111
111
|
]);
|
|
112
112
|
return validateVersionRequirement(resolution, result.stdout.trim(), requirement);
|
|
113
|
-
} catch
|
|
113
|
+
} catch {
|
|
114
114
|
return {
|
|
115
115
|
error: true,
|
|
116
116
|
...resolution,
|
package/emitter/src/types.ts
CHANGED
|
@@ -28,10 +28,6 @@ import {
|
|
|
28
28
|
getImplementation,
|
|
29
29
|
} from "./utils.js";
|
|
30
30
|
|
|
31
|
-
export const typesMap = new Map<SdkType, Record<string, any>>();
|
|
32
|
-
export const simpleTypesMap = new Map<string | null, Record<string, any>>();
|
|
33
|
-
export const disableGenerationMap = new Set<SdkType>();
|
|
34
|
-
|
|
35
31
|
export interface CredentialType {
|
|
36
32
|
kind: "Credential";
|
|
37
33
|
scheme: HttpAuth;
|
|
@@ -59,13 +55,16 @@ function isEmptyModel(type: SdkType): boolean {
|
|
|
59
55
|
);
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
export function getSimpleTypeResult(
|
|
58
|
+
export function getSimpleTypeResult(
|
|
59
|
+
context: PythonSdkContext,
|
|
60
|
+
result: Record<string, any>,
|
|
61
|
+
): Record<string, any> {
|
|
63
62
|
const key = dump(result, { sortKeys: true });
|
|
64
|
-
const value =
|
|
63
|
+
const value = context.__simpleTypesMap.get(key);
|
|
65
64
|
if (value) {
|
|
66
65
|
result = value;
|
|
67
66
|
} else {
|
|
68
|
-
|
|
67
|
+
context.__simpleTypesMap.set(key, result);
|
|
69
68
|
}
|
|
70
69
|
return result;
|
|
71
70
|
}
|
|
@@ -82,16 +81,16 @@ export function getType(
|
|
|
82
81
|
case "enum":
|
|
83
82
|
return emitEnum(context, type);
|
|
84
83
|
case "constant":
|
|
85
|
-
return emitConstant(type)!;
|
|
84
|
+
return emitConstant(context, type)!;
|
|
86
85
|
case "array":
|
|
87
86
|
case "dict":
|
|
88
87
|
return emitArrayOrDict(context, type)!;
|
|
89
88
|
case "utcDateTime":
|
|
90
89
|
case "offsetDateTime":
|
|
91
90
|
case "duration":
|
|
92
|
-
return emitDurationOrDateType(type);
|
|
91
|
+
return emitDurationOrDateType(context, type);
|
|
93
92
|
case "enumvalue":
|
|
94
|
-
return emitEnumMember(type, emitEnum(context, type.enumType));
|
|
93
|
+
return emitEnumMember(context, type, emitEnum(context, type.enumType));
|
|
95
94
|
case "credential":
|
|
96
95
|
return emitCredential(context, type);
|
|
97
96
|
case "bytes":
|
|
@@ -116,7 +115,7 @@ export function getType(
|
|
|
116
115
|
case "decimal128":
|
|
117
116
|
case "string":
|
|
118
117
|
case "url":
|
|
119
|
-
return emitBuiltInType(type);
|
|
118
|
+
return emitBuiltInType(context, type);
|
|
120
119
|
case "unknown":
|
|
121
120
|
return KnownTypes.any;
|
|
122
121
|
case "nullable":
|
|
@@ -133,12 +132,12 @@ function emitMultiPartFile(
|
|
|
133
132
|
type: MultiPartFileType,
|
|
134
133
|
): Record<string, any> {
|
|
135
134
|
if (type.type.kind === "array") {
|
|
136
|
-
return getSimpleTypeResult({
|
|
135
|
+
return getSimpleTypeResult(context, {
|
|
137
136
|
type: "list",
|
|
138
137
|
elementType: getType(context, createMultiPartFileType(type.type.valueType)),
|
|
139
138
|
});
|
|
140
139
|
}
|
|
141
|
-
return getSimpleTypeResult({
|
|
140
|
+
return getSimpleTypeResult(context, {
|
|
142
141
|
type: type.kind,
|
|
143
142
|
description: type.type.summary ? type.type.summary : type.type.doc,
|
|
144
143
|
});
|
|
@@ -183,7 +182,7 @@ function emitCredential(
|
|
|
183
182
|
},
|
|
184
183
|
};
|
|
185
184
|
}
|
|
186
|
-
return getSimpleTypeResult(credential_type);
|
|
185
|
+
return getSimpleTypeResult(context, credential_type);
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
function visibilityMapping(visibility?: Visibility[]): string[] | undefined {
|
|
@@ -211,14 +210,14 @@ function createMultiPartFileType(type: SdkType): MultiPartFileType {
|
|
|
211
210
|
return { kind: "multipartfile", type };
|
|
212
211
|
}
|
|
213
212
|
|
|
214
|
-
function addDisableGenerationMap(type: SdkType): void {
|
|
215
|
-
if (
|
|
213
|
+
function addDisableGenerationMap(context: PythonSdkContext, type: SdkType): void {
|
|
214
|
+
if (context.__disableGenerationMap.has(type)) return;
|
|
216
215
|
|
|
217
|
-
|
|
216
|
+
context.__disableGenerationMap.add(type);
|
|
218
217
|
if (type.kind === "model" && type.baseModel) {
|
|
219
|
-
addDisableGenerationMap(type.baseModel);
|
|
218
|
+
addDisableGenerationMap(context, type.baseModel);
|
|
220
219
|
} else if (type.kind === "array") {
|
|
221
|
-
addDisableGenerationMap(type.valueType);
|
|
220
|
+
addDisableGenerationMap(context, type.valueType);
|
|
222
221
|
}
|
|
223
222
|
}
|
|
224
223
|
|
|
@@ -231,7 +230,7 @@ function emitProperty(
|
|
|
231
230
|
if (isMultipartFileInput) {
|
|
232
231
|
sourceType = createMultiPartFileType(property.type);
|
|
233
232
|
// Python convert all the type of file part to FileType so clear these models' usage so that they won't be generated
|
|
234
|
-
addDisableGenerationMap(property.type);
|
|
233
|
+
addDisableGenerationMap(context, property.type);
|
|
235
234
|
}
|
|
236
235
|
return {
|
|
237
236
|
clientName: camelToSnakeCase(property.name),
|
|
@@ -257,8 +256,8 @@ function emitModel(context: PythonSdkContext, type: SdkModelType): Record<string
|
|
|
257
256
|
if (isEmptyModel(type)) {
|
|
258
257
|
return KnownTypes.any;
|
|
259
258
|
}
|
|
260
|
-
if (
|
|
261
|
-
return
|
|
259
|
+
if (context.__typesMap.has(type)) {
|
|
260
|
+
return context.__typesMap.get(type)!;
|
|
262
261
|
}
|
|
263
262
|
if (type.crossLanguageDefinitionId === "Azure.Core.Foundations.Error") {
|
|
264
263
|
return {
|
|
@@ -275,7 +274,7 @@ function emitModel(context: PythonSdkContext, type: SdkModelType): Record<string
|
|
|
275
274
|
};
|
|
276
275
|
}
|
|
277
276
|
if (type.external) {
|
|
278
|
-
return getSimpleTypeResult({
|
|
277
|
+
return getSimpleTypeResult(context, {
|
|
279
278
|
type: "external",
|
|
280
279
|
externalTypeInfo: type.external,
|
|
281
280
|
});
|
|
@@ -299,7 +298,7 @@ function emitModel(context: PythonSdkContext, type: SdkModelType): Record<string
|
|
|
299
298
|
clientNamespace: getClientNamespace(context, type.namespace),
|
|
300
299
|
};
|
|
301
300
|
|
|
302
|
-
|
|
301
|
+
context.__typesMap.set(type, newValue);
|
|
303
302
|
newValue.parents = type.baseModel ? [getType(context, type.baseModel)] : newValue.parents;
|
|
304
303
|
for (const property of type.properties.values()) {
|
|
305
304
|
if (property.kind === "property" && !isHttpMetadata(context, property)) {
|
|
@@ -309,7 +308,7 @@ function emitModel(context: PythonSdkContext, type: SdkModelType): Record<string
|
|
|
309
308
|
if (type.discriminatedSubtypes && property.discriminator) {
|
|
310
309
|
newValue.properties[newValue.properties.length - 1].isPolymorphic = true;
|
|
311
310
|
if (property.type.kind === "string") {
|
|
312
|
-
newValue.properties[newValue.properties.length - 1].type = getConstantType(null);
|
|
311
|
+
newValue.properties[newValue.properties.length - 1].type = getConstantType(context, null);
|
|
313
312
|
}
|
|
314
313
|
}
|
|
315
314
|
}
|
|
@@ -322,25 +321,28 @@ function emitModel(context: PythonSdkContext, type: SdkModelType): Record<string
|
|
|
322
321
|
return newValue;
|
|
323
322
|
}
|
|
324
323
|
|
|
325
|
-
function getConstantFromEnumValueType(
|
|
326
|
-
|
|
324
|
+
function getConstantFromEnumValueType(
|
|
325
|
+
context: PythonSdkContext,
|
|
326
|
+
type: SdkEnumValueType,
|
|
327
|
+
): Record<string, any> {
|
|
328
|
+
return getSimpleTypeResult(context, {
|
|
327
329
|
type: "constant",
|
|
328
330
|
value: type.value,
|
|
329
|
-
valueType: emitBuiltInType(type.valueType),
|
|
331
|
+
valueType: emitBuiltInType(context, type.valueType),
|
|
330
332
|
});
|
|
331
333
|
}
|
|
332
334
|
|
|
333
335
|
function emitEnum(context: PythonSdkContext, type: SdkEnumType): Record<string, any> {
|
|
334
|
-
if (
|
|
335
|
-
return
|
|
336
|
+
if (context.__typesMap.has(type)) {
|
|
337
|
+
return context.__typesMap.get(type)!;
|
|
336
338
|
}
|
|
337
339
|
if (type.isGeneratedName) {
|
|
338
340
|
const types = [];
|
|
339
341
|
for (const value of type.values) {
|
|
340
|
-
types.push(getConstantFromEnumValueType(value));
|
|
342
|
+
types.push(getConstantFromEnumValueType(context, value));
|
|
341
343
|
}
|
|
342
344
|
if (!type.isFixed) {
|
|
343
|
-
types.push(emitBuiltInType(type.valueType));
|
|
345
|
+
types.push(emitBuiltInType(context, type.valueType));
|
|
344
346
|
}
|
|
345
347
|
|
|
346
348
|
const newValue = {
|
|
@@ -350,7 +352,7 @@ function emitEnum(context: PythonSdkContext, type: SdkEnumType): Record<string,
|
|
|
350
352
|
types,
|
|
351
353
|
xmlMetadata: {},
|
|
352
354
|
};
|
|
353
|
-
|
|
355
|
+
context.__typesMap.set(type, newValue);
|
|
354
356
|
return newValue;
|
|
355
357
|
}
|
|
356
358
|
const values: Record<string, any>[] = [];
|
|
@@ -361,16 +363,16 @@ function emitEnum(context: PythonSdkContext, type: SdkEnumType): Record<string,
|
|
|
361
363
|
description: (type.summary ? type.summary : type.doc) ?? `Type of ${name}`,
|
|
362
364
|
internal: type.access === "internal",
|
|
363
365
|
type: type.kind,
|
|
364
|
-
valueType: emitBuiltInType(type.valueType),
|
|
366
|
+
valueType: emitBuiltInType(context, type.valueType),
|
|
365
367
|
values,
|
|
366
368
|
xmlMetadata: {},
|
|
367
369
|
crossLanguageDefinitionId: type.crossLanguageDefinitionId,
|
|
368
370
|
clientNamespace: getClientNamespace(context, type.namespace),
|
|
369
371
|
};
|
|
370
372
|
for (const value of type.values) {
|
|
371
|
-
newValue.values.push(emitEnumMember(value, newValue));
|
|
373
|
+
newValue.values.push(emitEnumMember(context, value, newValue));
|
|
372
374
|
}
|
|
373
|
-
|
|
375
|
+
context.__typesMap.set(type, newValue);
|
|
374
376
|
return newValue;
|
|
375
377
|
}
|
|
376
378
|
|
|
@@ -382,15 +384,16 @@ function enumName(name: string): string {
|
|
|
382
384
|
}
|
|
383
385
|
|
|
384
386
|
function emitEnumMember(
|
|
387
|
+
context: PythonSdkContext,
|
|
385
388
|
type: SdkEnumValueType,
|
|
386
389
|
enumType: Record<string, any>,
|
|
387
390
|
): Record<string, any> {
|
|
388
|
-
if (
|
|
389
|
-
return
|
|
391
|
+
if (context.__typesMap.has(type)) {
|
|
392
|
+
return context.__typesMap.get(type)!;
|
|
390
393
|
}
|
|
391
394
|
// python don't generate enum created by TCGC, so we shall not generate type for enum member of the enum, either.
|
|
392
395
|
if (type.enumType.isGeneratedName) {
|
|
393
|
-
return getConstantFromEnumValueType(type);
|
|
396
|
+
return getConstantFromEnumValueType(context, type);
|
|
394
397
|
}
|
|
395
398
|
|
|
396
399
|
const result = {
|
|
@@ -401,14 +404,17 @@ function emitEnumMember(
|
|
|
401
404
|
type: type.kind,
|
|
402
405
|
valueType: enumType["valueType"],
|
|
403
406
|
};
|
|
404
|
-
|
|
407
|
+
context.__typesMap.set(type, result);
|
|
405
408
|
return result;
|
|
406
409
|
}
|
|
407
410
|
|
|
408
|
-
function emitDurationOrDateType(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
411
|
+
function emitDurationOrDateType(
|
|
412
|
+
context: PythonSdkContext,
|
|
413
|
+
type: SdkDurationType | SdkDateTimeType,
|
|
414
|
+
): Record<string, any> {
|
|
415
|
+
return getSimpleTypeResult(context, {
|
|
416
|
+
...emitBuiltInType(context, type),
|
|
417
|
+
wireType: emitBuiltInType(context, type.wireType),
|
|
412
418
|
});
|
|
413
419
|
}
|
|
414
420
|
|
|
@@ -417,17 +423,17 @@ function emitArrayOrDict(
|
|
|
417
423
|
type: SdkArrayType | SdkDictionaryType,
|
|
418
424
|
): Record<string, any> {
|
|
419
425
|
const kind = type.kind === "array" ? "list" : type.kind;
|
|
420
|
-
return getSimpleTypeResult({
|
|
426
|
+
return getSimpleTypeResult(context, {
|
|
421
427
|
type: kind,
|
|
422
428
|
elementType: getType(context, type.valueType),
|
|
423
429
|
});
|
|
424
430
|
}
|
|
425
431
|
|
|
426
|
-
function emitConstant(type: SdkConstantType) {
|
|
427
|
-
return getSimpleTypeResult({
|
|
432
|
+
function emitConstant(context: PythonSdkContext, type: SdkConstantType) {
|
|
433
|
+
return getSimpleTypeResult(context, {
|
|
428
434
|
type: type.kind,
|
|
429
435
|
value: type.value,
|
|
430
|
-
valueType: emitBuiltInType(type.valueType),
|
|
436
|
+
valueType: emitBuiltInType(context, type.valueType),
|
|
431
437
|
});
|
|
432
438
|
}
|
|
433
439
|
|
|
@@ -461,12 +467,13 @@ const sdkScalarKindToPythonKind: Record<string, string> = {
|
|
|
461
467
|
};
|
|
462
468
|
|
|
463
469
|
function emitBuiltInType(
|
|
470
|
+
context: PythonSdkContext,
|
|
464
471
|
type: SdkBuiltInType | SdkDurationType | SdkDateTimeType,
|
|
465
472
|
): Record<string, any> {
|
|
466
473
|
if (type.encode) {
|
|
467
474
|
if (type.kind === "duration") {
|
|
468
475
|
if (type.encode === "ISO8601") {
|
|
469
|
-
return getSimpleTypeResult({
|
|
476
|
+
return getSimpleTypeResult(context, {
|
|
470
477
|
type: type.kind,
|
|
471
478
|
encode: type.encode,
|
|
472
479
|
});
|
|
@@ -474,13 +481,13 @@ function emitBuiltInType(
|
|
|
474
481
|
}
|
|
475
482
|
if (type.kind === "utcDateTime" || type.kind === "offsetDateTime") {
|
|
476
483
|
if (type.encode === "unixTimestamp") {
|
|
477
|
-
return getSimpleTypeResult({
|
|
484
|
+
return getSimpleTypeResult(context, {
|
|
478
485
|
type: "unixtime",
|
|
479
486
|
encode: type.encode,
|
|
480
487
|
});
|
|
481
488
|
}
|
|
482
489
|
if (type.encode === "rfc3339" || type.encode === "rfc7231") {
|
|
483
|
-
return getSimpleTypeResult({
|
|
490
|
+
return getSimpleTypeResult(context, {
|
|
484
491
|
type: type.kind,
|
|
485
492
|
encode: type.encode,
|
|
486
493
|
});
|
|
@@ -489,21 +496,21 @@ function emitBuiltInType(
|
|
|
489
496
|
|
|
490
497
|
// fallback to wire type for unknown or unsupported encode
|
|
491
498
|
if ("wireType" in type && type.wireType !== undefined) {
|
|
492
|
-
return getSimpleTypeResult({
|
|
499
|
+
return getSimpleTypeResult(context, {
|
|
493
500
|
type: sdkScalarKindToPythonKind[type.wireType.kind] || type.wireType.kind,
|
|
494
501
|
encode: type.encode,
|
|
495
502
|
});
|
|
496
503
|
}
|
|
497
504
|
}
|
|
498
505
|
|
|
499
|
-
return getSimpleTypeResult({
|
|
506
|
+
return getSimpleTypeResult(context, {
|
|
500
507
|
type: sdkScalarKindToPythonKind[type.kind] || type.kind, // TODO: switch to kind
|
|
501
508
|
encode: type.encode,
|
|
502
509
|
});
|
|
503
510
|
}
|
|
504
511
|
|
|
505
512
|
function emitUnion(context: PythonSdkContext, type: SdkUnionType): Record<string, any> {
|
|
506
|
-
return getSimpleTypeResult({
|
|
513
|
+
return getSimpleTypeResult(context, {
|
|
507
514
|
name: type.isGeneratedName ? undefined : type.name,
|
|
508
515
|
snakeCaseName: type.isGeneratedName ? undefined : camelToSnakeCase(type.name),
|
|
509
516
|
description: type.isGeneratedName ? "" : `Type of ${type.name}`,
|
|
@@ -515,8 +522,11 @@ function emitUnion(context: PythonSdkContext, type: SdkUnionType): Record<string
|
|
|
515
522
|
});
|
|
516
523
|
}
|
|
517
524
|
|
|
518
|
-
export function getConstantType(
|
|
519
|
-
|
|
525
|
+
export function getConstantType(
|
|
526
|
+
context: PythonSdkContext,
|
|
527
|
+
key: string | null,
|
|
528
|
+
): Record<string, any> {
|
|
529
|
+
const cache = context.__simpleTypesMap.get(key);
|
|
520
530
|
if (cache) {
|
|
521
531
|
return cache;
|
|
522
532
|
}
|
|
@@ -527,7 +537,7 @@ export function getConstantType(key: string | null): Record<string, any> {
|
|
|
527
537
|
valueType: KnownTypes.string,
|
|
528
538
|
xmlMetadata: {},
|
|
529
539
|
};
|
|
530
|
-
|
|
540
|
+
context.__simpleTypesMap.set(key, type);
|
|
531
541
|
return type;
|
|
532
542
|
}
|
|
533
543
|
|
package/emitter/src/utils.ts
CHANGED
|
@@ -213,7 +213,7 @@ export function emitParamBase<TServiceOperation extends SdkServiceOperation>(
|
|
|
213
213
|
let type = getType(context, parameter.type);
|
|
214
214
|
if (parameter.isApiVersionParam) {
|
|
215
215
|
if (parameter.clientDefaultValue) {
|
|
216
|
-
type = getSimpleTypeResult({
|
|
216
|
+
type = getSimpleTypeResult(context, {
|
|
217
217
|
type: "constant",
|
|
218
218
|
value: parameter.clientDefaultValue,
|
|
219
219
|
valueType: type,
|
|
@@ -262,6 +262,7 @@ export function capitalize(name: string): string {
|
|
|
262
262
|
return name[0].toUpperCase() + name.slice(1);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
+
// Library namespaces that should not be used as client namespaces
|
|
265
266
|
const LIB_NAMESPACE = [
|
|
266
267
|
"azure.core",
|
|
267
268
|
"azure.resourcemanager",
|
|
@@ -272,29 +273,25 @@ const LIB_NAMESPACE = [
|
|
|
272
273
|
];
|
|
273
274
|
|
|
274
275
|
export function getRootNamespace(context: PythonSdkContext): string {
|
|
275
|
-
let rootNamespace = "";
|
|
276
276
|
if (context.sdkPackage.clients.length > 0) {
|
|
277
|
-
|
|
278
|
-
} else if (context.sdkPackage.models.length > 0) {
|
|
279
|
-
const result = context.sdkPackage.models
|
|
280
|
-
.map((model) => model.namespace)
|
|
281
|
-
.filter((namespace) => !LIB_NAMESPACE.includes(namespace));
|
|
282
|
-
if (result.length > 0) {
|
|
283
|
-
result.sort();
|
|
284
|
-
rootNamespace = result[0];
|
|
285
|
-
}
|
|
277
|
+
return context.sdkPackage.clients[0].namespace.toLowerCase();
|
|
286
278
|
} else if (context.sdkPackage.namespaces.length > 0) {
|
|
287
|
-
|
|
279
|
+
return context.sdkPackage.namespaces[0].fullName.toLowerCase();
|
|
288
280
|
}
|
|
281
|
+
return "";
|
|
282
|
+
}
|
|
289
283
|
|
|
290
|
-
|
|
284
|
+
function isLibraryNamespace(namespace: string): boolean {
|
|
285
|
+
const ns = namespace.toLowerCase();
|
|
286
|
+
return LIB_NAMESPACE.some((lib) => ns.startsWith(lib));
|
|
291
287
|
}
|
|
292
288
|
|
|
293
289
|
export function getClientNamespace(context: PythonSdkContext, clientNamespace: string) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
290
|
+
// Namespace precedence: @clientNamespace > --namespace > original namespace
|
|
291
|
+
// These are resolved by TCGC and passed in as clientNamespace.
|
|
292
|
+
// However, models from library namespaces (azure.core, azure.resourcemanager, etc.)
|
|
293
|
+
// should use the SDK's root namespace instead.
|
|
294
|
+
if (clientNamespace === "" || isLibraryNamespace(clientNamespace)) {
|
|
298
295
|
return getRootNamespace(context);
|
|
299
296
|
}
|
|
300
297
|
return clientNamespace.toLowerCase();
|
|
@@ -320,7 +317,7 @@ function parseToken(token: Token): string {
|
|
|
320
317
|
case "codespan":
|
|
321
318
|
parsed += `\`\`${token.text}\`\``;
|
|
322
319
|
break;
|
|
323
|
-
case "code":
|
|
320
|
+
case "code": {
|
|
324
321
|
let codeBlockStyle = token.codeBlockStyle;
|
|
325
322
|
if (codeBlockStyle === undefined) {
|
|
326
323
|
codeBlockStyle = token.raw.split("\n")[0].replace("```", "").trim();
|
|
@@ -331,6 +328,7 @@ function parseToken(token: Token): string {
|
|
|
331
328
|
}
|
|
332
329
|
parsed += `\n\n.. code-block:: ${codeBlockStyle ?? ""}\n\n ${token.text.split("\n").join("\n ")}`;
|
|
333
330
|
break;
|
|
331
|
+
}
|
|
334
332
|
case "link":
|
|
335
333
|
if (token.href !== undefined) {
|
|
336
334
|
parsed += `\`${token.text} <${token.href}>\`_`;
|