diff --git a/ChangeLog.md b/ChangeLog.md index 7ac23fb8a42..708857a83f7 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,16 @@ # Change Log +### 2021-06-16 - 5.8.1 + +min Autorest core version: 3.3.0 + +min Modelerfour version: 4.19.1 + +**Bug Fixes** + +- Fix optional properties with constant schemas. Now, properties that have constant schemas but are optional will not have the hardcoded constant value, +but will default to its `x-ms-client-default` or `None` #952 + ### 2021-05-17 - 5.8.0 min Autorest core version: 3.3.0 diff --git a/autorest/codegen/models/object_schema.py b/autorest/codegen/models/object_schema.py index 200e8c13963..996c759e7b8 100644 --- a/autorest/codegen/models/object_schema.py +++ b/autorest/codegen/models/object_schema.py @@ -129,7 +129,6 @@ def fill_instance_from_yaml(self, namespace: str, yaml_data: Dict[str, Any], **k # map of discriminator value to child's name for children_yaml in yaml_data["discriminator"]["immediate"].values(): subtype_map[children_yaml["discriminatorValue"]] = children_yaml["language"]["python"]["name"] - if yaml_data.get("properties"): properties += [ Property.from_yaml(p, has_additional_properties=len(properties) > 0, **kwargs) diff --git a/autorest/codegen/models/parameter.py b/autorest/codegen/models/parameter.py index c3d041c1344..4dff6d3302b 100644 --- a/autorest/codegen/models/parameter.py +++ b/autorest/codegen/models/parameter.py @@ -173,7 +173,7 @@ def in_method_signature(self) -> bool: @property def in_method_code(self) -> bool: - return not (isinstance(self.schema, ConstantSchema) and self.location == ParameterLocation.Other) + return not (self.constant and self.location == ParameterLocation.Other) @property def implementation(self) -> str: diff --git a/autorest/codegen/models/property.py b/autorest/codegen/models/property.py index 426435cab46..43c616fad78 100644 --- a/autorest/codegen/models/property.py +++ b/autorest/codegen/models/property.py @@ -32,26 +32,36 @@ def __init__( self.required: bool = yaml_data.get("required", False) self.readonly: bool = yaml_data.get("readOnly", False) self.is_discriminator: bool = yaml_data.get("isDiscriminator", False) - # this bool doesn't consider you to be constant if you are a discriminator - self.constant: bool = isinstance(self.schema, ConstantSchema) and not self.is_discriminator - if description: self.description = description else: self.description = yaml_data["language"]["python"]["description"] - validation_map: Dict[str, Union[bool, int, str]] = {} + self.client_default_value = client_default_value + + @property + def constant(self) -> bool: + # this bool doesn't consider you to be constant if you are a discriminator + # you also have to be required to be considered a constant + return ( + isinstance(self.schema, ConstantSchema) and + self.required and + not self.is_discriminator + ) + + @property + def validation_map(self) -> Optional[Dict[str, Union[bool, int, str]]]: + retval: Dict[str, Union[bool, int, str]] = {} if self.required: - validation_map["required"] = True + retval["required"] = True if self.readonly: - validation_map["readonly"] = True + retval["readonly"] = True if self.constant: - validation_map["constant"] = True + retval["constant"] = True if self.schema.validation_map: validation_map_from_schema = cast(Dict[str, Union[bool, int, str]], self.schema.validation_map) - validation_map.update(validation_map_from_schema) - self.validation_map = validation_map or None - self.client_default_value = client_default_value + retval.update(validation_map_from_schema) + return retval or None @property def escaped_swagger_name(self) -> str: diff --git a/autorest/codegen/serializers/model_base_serializer.py b/autorest/codegen/serializers/model_base_serializer.py index 01e827c7e17..8a798d86542 100644 --- a/autorest/codegen/serializers/model_base_serializer.py +++ b/autorest/codegen/serializers/model_base_serializer.py @@ -62,14 +62,19 @@ def prop_documentation_string(prop: Property) -> str: description += "." if prop.name == "tags": description = "A set of tags. " + description - if prop.required: + + if prop.constant: + description += f' Has constant value: {prop.constant_declaration}.' + elif prop.required: if description: description = "Required. " + description else: description = "Required. " - if prop.constant: - constant_prop = cast(ConstantSchema, prop.schema) - description += f' Default value: "{constant_prop.value}".' + elif isinstance(prop.schema, ConstantSchema): + description += ( + f" The only acceptable values to pass in are None and {prop.constant_declaration}. " + + f"The default value is {prop.default_value_declaration}." + ) if prop.is_discriminator: description += "Constant filled by server. " if isinstance(prop.schema, EnumSchema): diff --git a/dev_requirements.txt b/dev_requirements.txt index 6c769311074..60f41d2031a 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -7,3 +7,4 @@ pytest ptvsd mypy black +types-PyYAML \ No newline at end of file diff --git a/package.json b/package.json index d0e0e936ac3..846fa4f0754 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@autorest/python", - "version": "5.8.0", + "version": "5.8.1", "description": "The Python extension for generators in AutoRest.", "scripts": { "prepare": "node run-python3.js prepare.py", @@ -28,7 +28,7 @@ }, "devDependencies": { "@autorest/autorest": "^3.0.0", - "@microsoft.azure/autorest.testserver": "^3.0.23" + "@microsoft.azure/autorest.testserver": "^3.0.24" }, "files": [ "autorest/**/*.py", diff --git a/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models.py b/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models.py index 15c69f1847d..7aaa9669255 100644 --- a/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models.py +++ b/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models.py @@ -19,7 +19,7 @@ class Error(msrest.serialization.Model): :param status: :type status: int - :ivar constant_id: Required. Default value: "1". + :ivar constant_id: Has constant value: 1. :vartype constant_id: int :param message: :type message: str diff --git a/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models_py3.py b/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models_py3.py index c8380361c06..806724b999b 100644 --- a/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models_py3.py +++ b/test/azure/Expected/AcceptanceTests/AzureSpecials/azurespecialproperties/models/_models_py3.py @@ -21,7 +21,7 @@ class Error(msrest.serialization.Model): :param status: :type status: int - :ivar constant_id: Required. Default value: "1". + :ivar constant_id: Has constant value: 1. :vartype constant_id: int :param message: :type message: str diff --git a/test/vanilla/AcceptanceTests/asynctests/test_model_flattening.py b/test/vanilla/AcceptanceTests/asynctests/test_model_flattening.py index 0d160557814..bd2de5fe53c 100644 --- a/test/vanilla/AcceptanceTests/asynctests/test_model_flattening.py +++ b/test/vanilla/AcceptanceTests/asynctests/test_model_flattening.py @@ -214,6 +214,7 @@ async def test_model_flattening_simple(self, client): product_id = "123", description = "product description", max_product_display_name = "max name", + capacity="Large", odata_value = "http://foo", generic_value = "https://generic" ) @@ -230,6 +231,7 @@ async def test_model_flattening_with_parameter_flattening(self, client): product_id = "123", description = "product description", max_product_display_name = "max name", + capacity="Large", odata_value = "http://foo" ) simple_product.additional_properties = {} # Not the purpose of this test. This enables the ==. @@ -238,6 +240,7 @@ async def test_model_flattening_with_parameter_flattening(self, client): "123", # product_id "product description", # description "max name", # max_product_display_name + "Large", # capacity None, # generic_value "http://foo", # odata_value ) @@ -252,6 +255,7 @@ async def test_model_flattening_with_grouping(self, client): product_id = "123", description = "product description", max_product_display_name = "max name", + capacity="Large", odata_value = "http://foo" ) simple_product.additional_properties = {} # Not the purpose of this test. This enables the ==. @@ -260,6 +264,7 @@ async def test_model_flattening_with_grouping(self, client): product_id = "123", description = "product description", max_product_display_name="max name", + capacity="Large", odata_value="http://foo", name="groupproduct") diff --git a/test/vanilla/AcceptanceTests/test_model_flattening.py b/test/vanilla/AcceptanceTests/test_model_flattening.py index 0fd477f5c1e..f07085f72e9 100644 --- a/test/vanilla/AcceptanceTests/test_model_flattening.py +++ b/test/vanilla/AcceptanceTests/test_model_flattening.py @@ -208,6 +208,7 @@ def test_model_flattening_simple(self, client): product_id = "123", description = "product description", max_product_display_name = "max name", + capacity="Large", odata_value = "http://foo", generic_value = "https://generic" ) @@ -223,6 +224,7 @@ def test_model_flattening_with_parameter_flattening(self, client): product_id = "123", description = "product description", max_product_display_name = "max name", + capacity="Large", odata_value = "http://foo" ) simple_product.additional_properties = {} # Not the purpose of this test. This enables the ==. @@ -231,6 +233,7 @@ def test_model_flattening_with_parameter_flattening(self, client): "123", # product_id "product description", # description "max name", # max_product_display_name + "Large", # capacity None, # generic_value "http://foo", # odata_value ) @@ -244,6 +247,7 @@ def test_model_flattening_with_grouping(self, client): product_id = "123", description = "product description", max_product_display_name = "max name", + capacity="Large", odata_value = "http://foo" ) simple_product.additional_properties = {} # Not the purpose of this test. This enables the ==. @@ -252,6 +256,7 @@ def test_model_flattening_with_grouping(self, client): product_id = "123", description = "product description", max_product_display_name="max name", + capacity="Large", odata_value="http://foo", name="groupproduct") diff --git a/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models.py b/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models.py index f378cc31f39..50bae4d73a0 100644 --- a/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models.py +++ b/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models.py @@ -37,8 +37,7 @@ class RefColorConstant(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar color_constant: Required. Referenced Color Constant Description. Default value: - "green-color". + :ivar color_constant: Referenced Color Constant Description. Has constant value: "green-color". :vartype color_constant: str :param field1: Sample string. :type field1: str diff --git a/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models_py3.py b/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models_py3.py index 9fa4e50bc63..236df42ec85 100644 --- a/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models_py3.py +++ b/test/vanilla/Expected/AcceptanceTests/BodyString/bodystring/models/_models_py3.py @@ -39,8 +39,7 @@ class RefColorConstant(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar color_constant: Required. Referenced Color Constant Description. Default value: - "green-color". + :ivar color_constant: Referenced Color Constant Description. Has constant value: "green-color". :vartype color_constant: str :param field1: Sample string. :type field1: str diff --git a/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models.py b/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models.py index 49053a757a8..2c36e865ba5 100644 --- a/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models.py +++ b/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models.py @@ -164,47 +164,35 @@ def __init__(self, **kwargs): class NoModelAsStringNoRequiredOneValueDefault(msrest.serialization.Model): """NoModelAsStringNoRequiredOneValueDefault. - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar parameter: Default value: "value1". - :vartype parameter: str + :param parameter: The only acceptable values to pass in are None and "value1". The default + value is "value1". + :type parameter: str """ - _validation = { - "parameter": {"constant": True}, - } - _attribute_map = { "parameter": {"key": "parameter", "type": "str"}, } - parameter = "value1" - def __init__(self, **kwargs): super(NoModelAsStringNoRequiredOneValueDefault, self).__init__(**kwargs) + self.parameter = kwargs.get("parameter", "value1") class NoModelAsStringNoRequiredOneValueNoDefault(msrest.serialization.Model): """NoModelAsStringNoRequiredOneValueNoDefault. - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar parameter: Default value: "value1". - :vartype parameter: str + :param parameter: The only acceptable values to pass in are None and "value1". The default + value is None. + :type parameter: str """ - _validation = { - "parameter": {"constant": True}, - } - _attribute_map = { "parameter": {"key": "parameter", "type": "str"}, } - parameter = "value1" - def __init__(self, **kwargs): super(NoModelAsStringNoRequiredOneValueNoDefault, self).__init__(**kwargs) + self.parameter = kwargs.get("parameter", None) class NoModelAsStringNoRequiredTwoValueDefault(msrest.serialization.Model): @@ -246,7 +234,7 @@ class NoModelAsStringRequiredOneValueDefault(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar parameter: Required. Default value: "value1". + :ivar parameter: Has constant value: "value1". :vartype parameter: str """ @@ -271,7 +259,7 @@ class NoModelAsStringRequiredOneValueNoDefault(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar parameter: Required. Default value: "value1". + :ivar parameter: Has constant value: "value1". :vartype parameter: str """ diff --git a/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models_py3.py b/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models_py3.py index 9faaff8c9db..c62571056ea 100644 --- a/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models_py3.py +++ b/test/vanilla/Expected/AcceptanceTests/Constants/constants/models/_models_py3.py @@ -176,47 +176,35 @@ def __init__(self, *, parameter: Union[str, "ModelAsStringRequiredTwoValueNoDefa class NoModelAsStringNoRequiredOneValueDefault(msrest.serialization.Model): """NoModelAsStringNoRequiredOneValueDefault. - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar parameter: Default value: "value1". - :vartype parameter: str + :param parameter: The only acceptable values to pass in are None and "value1". The default + value is "value1". + :type parameter: str """ - _validation = { - "parameter": {"constant": True}, - } - _attribute_map = { "parameter": {"key": "parameter", "type": "str"}, } - parameter = "value1" - - def __init__(self, **kwargs): + def __init__(self, *, parameter: Optional[str] = "value1", **kwargs): super(NoModelAsStringNoRequiredOneValueDefault, self).__init__(**kwargs) + self.parameter = parameter class NoModelAsStringNoRequiredOneValueNoDefault(msrest.serialization.Model): """NoModelAsStringNoRequiredOneValueNoDefault. - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar parameter: Default value: "value1". - :vartype parameter: str + :param parameter: The only acceptable values to pass in are None and "value1". The default + value is None. + :type parameter: str """ - _validation = { - "parameter": {"constant": True}, - } - _attribute_map = { "parameter": {"key": "parameter", "type": "str"}, } - parameter = "value1" - - def __init__(self, **kwargs): + def __init__(self, *, parameter: Optional[str] = None, **kwargs): super(NoModelAsStringNoRequiredOneValueNoDefault, self).__init__(**kwargs) + self.parameter = parameter class NoModelAsStringNoRequiredTwoValueDefault(msrest.serialization.Model): @@ -262,7 +250,7 @@ class NoModelAsStringRequiredOneValueDefault(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar parameter: Required. Default value: "value1". + :ivar parameter: Has constant value: "value1". :vartype parameter: str """ @@ -287,7 +275,7 @@ class NoModelAsStringRequiredOneValueNoDefault(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar parameter: Required. Default value: "value1". + :ivar parameter: Has constant value: "value1". :vartype parameter: str """ diff --git a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/aio/operations/_auto_rest_resource_flattening_test_service_operations.py b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/aio/operations/_auto_rest_resource_flattening_test_service_operations.py index 1d4f8693d5a..a5f2c554752 100644 --- a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/aio/operations/_auto_rest_resource_flattening_test_service_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/aio/operations/_auto_rest_resource_flattening_test_service_operations.py @@ -454,6 +454,7 @@ async def post_flattened_simple_product( product_id: str, description: Optional[str] = None, max_product_display_name: Optional[str] = None, + capacity: Optional[str] = "Large", generic_value: Optional[str] = None, odata_value: Optional[str] = None, **kwargs: Any @@ -468,6 +469,8 @@ async def post_flattened_simple_product( :type description: str :param max_product_display_name: Display name of product. :type max_product_display_name: str + :param capacity: Capacity of product. For example, 4 people. + :type capacity: str :param generic_value: Generic URL value. :type generic_value: str :param odata_value: URL value. @@ -485,6 +488,7 @@ async def post_flattened_simple_product( product_id=product_id, description=description, max_product_display_name=max_product_display_name, + capacity=capacity, generic_value=generic_value, odata_value=odata_value, ) @@ -565,6 +569,7 @@ async def put_simple_product_with_grouping( product_id=_product_id, description=_description, max_product_display_name=_max_product_display_name, + capacity=capacity, generic_value=_generic_value, odata_value=_odata_value, ) diff --git a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models.py b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models.py index b485c619526..1db7dc4c8bf 100644 --- a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models.py +++ b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models.py @@ -159,8 +159,6 @@ def __init__(self, **kwargs): class FlattenParameterGroup(msrest.serialization.Model): """Parameter group. - Variables are only populated by the server, and will be ignored when sending a request. - All required parameters must be populated in order to send to Azure. :param name: Required. Product name with value 'groupproduct'. @@ -175,8 +173,9 @@ class FlattenParameterGroup(msrest.serialization.Model): :type description: str :param max_product_display_name: Display name of product. :type max_product_display_name: str - :ivar capacity: Capacity of product. For example, 4 people. Default value: "Large". - :vartype capacity: str + :param capacity: Capacity of product. For example, 4 people. The only acceptable values to pass + in are None and "Large". The default value is None. + :type capacity: str :param generic_value: Generic URL value. :type generic_value: str :param odata_value: URL value. @@ -186,7 +185,6 @@ class FlattenParameterGroup(msrest.serialization.Model): _validation = { "name": {"required": True}, "product_id": {"required": True}, - "capacity": {"constant": True}, } _attribute_map = { @@ -200,8 +198,6 @@ class FlattenParameterGroup(msrest.serialization.Model): "odata_value": {"key": "@odata\\.value", "type": "str"}, } - capacity = "Large" - def __init__(self, **kwargs): super(FlattenParameterGroup, self).__init__(**kwargs) self.name = kwargs["name"] @@ -209,6 +205,7 @@ def __init__(self, **kwargs): self.product_id = kwargs["product_id"] self.description = kwargs.get("description", None) self.max_product_display_name = kwargs.get("max_product_display_name", None) + self.capacity = kwargs.get("capacity", None) self.generic_value = kwargs.get("generic_value", None) self.odata_value = kwargs.get("odata_value", None) @@ -291,8 +288,6 @@ def __init__(self, **kwargs): class SimpleProduct(BaseProduct): """The product documentation. - Variables are only populated by the server, and will be ignored when sending a request. - All required parameters must be populated in order to send to Azure. :param product_id: Required. Unique identifier representing a specific product for a given @@ -303,8 +298,9 @@ class SimpleProduct(BaseProduct): :type description: str :param max_product_display_name: Display name of product. :type max_product_display_name: str - :ivar capacity: Capacity of product. For example, 4 people. Default value: "Large". - :vartype capacity: str + :param capacity: Capacity of product. For example, 4 people. The only acceptable values to pass + in are None and "Large". The default value is None. + :type capacity: str :param generic_value: Generic URL value. :type generic_value: str :param odata_value: URL value. @@ -313,7 +309,6 @@ class SimpleProduct(BaseProduct): _validation = { "product_id": {"required": True}, - "capacity": {"constant": True}, } _attribute_map = { @@ -325,11 +320,10 @@ class SimpleProduct(BaseProduct): "odata_value": {"key": "details.max_product_image.@odata\\.value", "type": "str"}, } - capacity = "Large" - def __init__(self, **kwargs): super(SimpleProduct, self).__init__(**kwargs) self.max_product_display_name = kwargs.get("max_product_display_name", None) + self.capacity = kwargs.get("capacity", None) self.generic_value = kwargs.get("generic_value", None) self.odata_value = kwargs.get("odata_value", None) diff --git a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models_py3.py b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models_py3.py index 369cf4238f6..356b1ea37bf 100644 --- a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models_py3.py +++ b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/models/_models_py3.py @@ -177,8 +177,6 @@ def __init__( class FlattenParameterGroup(msrest.serialization.Model): """Parameter group. - Variables are only populated by the server, and will be ignored when sending a request. - All required parameters must be populated in order to send to Azure. :param name: Required. Product name with value 'groupproduct'. @@ -193,8 +191,9 @@ class FlattenParameterGroup(msrest.serialization.Model): :type description: str :param max_product_display_name: Display name of product. :type max_product_display_name: str - :ivar capacity: Capacity of product. For example, 4 people. Default value: "Large". - :vartype capacity: str + :param capacity: Capacity of product. For example, 4 people. The only acceptable values to pass + in are None and "Large". The default value is None. + :type capacity: str :param generic_value: Generic URL value. :type generic_value: str :param odata_value: URL value. @@ -204,7 +203,6 @@ class FlattenParameterGroup(msrest.serialization.Model): _validation = { "name": {"required": True}, "product_id": {"required": True}, - "capacity": {"constant": True}, } _attribute_map = { @@ -218,8 +216,6 @@ class FlattenParameterGroup(msrest.serialization.Model): "odata_value": {"key": "@odata\\.value", "type": "str"}, } - capacity = "Large" - def __init__( self, *, @@ -228,6 +224,7 @@ def __init__( simple_body_product: Optional["SimpleProduct"] = None, description: Optional[str] = None, max_product_display_name: Optional[str] = None, + capacity: Optional[str] = None, generic_value: Optional[str] = None, odata_value: Optional[str] = None, **kwargs @@ -238,6 +235,7 @@ def __init__( self.product_id = product_id self.description = description self.max_product_display_name = max_product_display_name + self.capacity = capacity self.generic_value = generic_value self.odata_value = odata_value @@ -327,8 +325,6 @@ def __init__( class SimpleProduct(BaseProduct): """The product documentation. - Variables are only populated by the server, and will be ignored when sending a request. - All required parameters must be populated in order to send to Azure. :param product_id: Required. Unique identifier representing a specific product for a given @@ -339,8 +335,9 @@ class SimpleProduct(BaseProduct): :type description: str :param max_product_display_name: Display name of product. :type max_product_display_name: str - :ivar capacity: Capacity of product. For example, 4 people. Default value: "Large". - :vartype capacity: str + :param capacity: Capacity of product. For example, 4 people. The only acceptable values to pass + in are None and "Large". The default value is None. + :type capacity: str :param generic_value: Generic URL value. :type generic_value: str :param odata_value: URL value. @@ -349,7 +346,6 @@ class SimpleProduct(BaseProduct): _validation = { "product_id": {"required": True}, - "capacity": {"constant": True}, } _attribute_map = { @@ -361,20 +357,20 @@ class SimpleProduct(BaseProduct): "odata_value": {"key": "details.max_product_image.@odata\\.value", "type": "str"}, } - capacity = "Large" - def __init__( self, *, product_id: str, description: Optional[str] = None, max_product_display_name: Optional[str] = None, + capacity: Optional[str] = None, generic_value: Optional[str] = None, odata_value: Optional[str] = None, **kwargs ): super(SimpleProduct, self).__init__(product_id=product_id, description=description, **kwargs) self.max_product_display_name = max_product_display_name + self.capacity = capacity self.generic_value = generic_value self.odata_value = odata_value diff --git a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/operations/_auto_rest_resource_flattening_test_service_operations.py b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/operations/_auto_rest_resource_flattening_test_service_operations.py index a0c8577211c..0017fddaf60 100644 --- a/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/operations/_auto_rest_resource_flattening_test_service_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/ModelFlattening/modelflattening/operations/_auto_rest_resource_flattening_test_service_operations.py @@ -487,6 +487,7 @@ def post_flattened_simple_product( product_id, # type: str description=None, # type: Optional[str] max_product_display_name=None, # type: Optional[str] + capacity="Large", # type: Optional[str] generic_value=None, # type: Optional[str] odata_value=None, # type: Optional[str] **kwargs # type: Any @@ -502,6 +503,8 @@ def post_flattened_simple_product( :type description: str :param max_product_display_name: Display name of product. :type max_product_display_name: str + :param capacity: Capacity of product. For example, 4 people. + :type capacity: str :param generic_value: Generic URL value. :type generic_value: str :param odata_value: URL value. @@ -519,6 +522,7 @@ def post_flattened_simple_product( product_id=product_id, description=description, max_product_display_name=max_product_display_name, + capacity=capacity, generic_value=generic_value, odata_value=odata_value, ) @@ -602,6 +606,7 @@ def put_simple_product_with_grouping( product_id=_product_id, description=_description, max_product_display_name=_max_product_display_name, + capacity=capacity, generic_value=_generic_value, odata_value=_odata_value, ) diff --git a/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models.py b/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models.py index 650d73eba0f..b517ba12c17 100644 --- a/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models.py +++ b/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models.py @@ -17,7 +17,7 @@ class ChildProduct(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar const_property: Required. Constant string. Default value: "constant". + :ivar const_property: Constant string. Has constant value: "constant". :vartype const_property: str :param count: Count. :type count: int @@ -46,9 +46,9 @@ class ConstantProduct(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar const_property: Required. Constant string. Default value: "constant". + :ivar const_property: Constant string. Has constant value: "constant". :vartype const_property: str - :ivar const_property2: Required. Constant string2. Default value: "constant2". + :ivar const_property2: Constant string2. Has constant value: "constant2". :vartype const_property2: str """ @@ -110,12 +110,13 @@ class Product(msrest.serialization.Model): :type child: ~validation.models.ChildProduct :param const_child: Required. The product documentation. :type const_child: ~validation.models.ConstantProduct - :ivar const_int: Required. Constant int. Default value: "0". + :ivar const_int: Constant int. Has constant value: 0. :vartype const_int: int - :ivar const_string: Required. Constant string. Default value: "constant". + :ivar const_string: Constant string. Has constant value: "constant". :vartype const_string: str - :ivar const_string_as_enum: Constant string as Enum. Default value: "constant_string_as_enum". - :vartype const_string_as_enum: str + :param const_string_as_enum: Constant string as Enum. The only acceptable values to pass in are + None and "constant_string_as_enum". The default value is None. + :type const_string_as_enum: str """ _validation = { @@ -126,7 +127,6 @@ class Product(msrest.serialization.Model): "const_child": {"required": True}, "const_int": {"required": True, "constant": True}, "const_string": {"required": True, "constant": True}, - "const_string_as_enum": {"constant": True}, } _attribute_map = { @@ -142,7 +142,6 @@ class Product(msrest.serialization.Model): const_int = 0 const_string = "constant" - const_string_as_enum = "constant_string_as_enum" def __init__(self, **kwargs): super(Product, self).__init__(**kwargs) @@ -151,3 +150,4 @@ def __init__(self, **kwargs): self.image = kwargs.get("image", None) self.child = kwargs["child"] self.const_child = kwargs["const_child"] + self.const_string_as_enum = kwargs.get("const_string_as_enum", None) diff --git a/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models_py3.py b/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models_py3.py index e8ed1d89950..0e77bb9c137 100644 --- a/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models_py3.py +++ b/test/vanilla/Expected/AcceptanceTests/Validation/validation/models/_models_py3.py @@ -19,7 +19,7 @@ class ChildProduct(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar const_property: Required. Constant string. Default value: "constant". + :ivar const_property: Constant string. Has constant value: "constant". :vartype const_property: str :param count: Count. :type count: int @@ -48,9 +48,9 @@ class ConstantProduct(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :ivar const_property: Required. Constant string. Default value: "constant". + :ivar const_property: Constant string. Has constant value: "constant". :vartype const_property: str - :ivar const_property2: Required. Constant string2. Default value: "constant2". + :ivar const_property2: Constant string2. Has constant value: "constant2". :vartype const_property2: str """ @@ -114,12 +114,13 @@ class Product(msrest.serialization.Model): :type child: ~validation.models.ChildProduct :param const_child: Required. The product documentation. :type const_child: ~validation.models.ConstantProduct - :ivar const_int: Required. Constant int. Default value: "0". + :ivar const_int: Constant int. Has constant value: 0. :vartype const_int: int - :ivar const_string: Required. Constant string. Default value: "constant". + :ivar const_string: Constant string. Has constant value: "constant". :vartype const_string: str - :ivar const_string_as_enum: Constant string as Enum. Default value: "constant_string_as_enum". - :vartype const_string_as_enum: str + :param const_string_as_enum: Constant string as Enum. The only acceptable values to pass in are + None and "constant_string_as_enum". The default value is None. + :type const_string_as_enum: str """ _validation = { @@ -130,7 +131,6 @@ class Product(msrest.serialization.Model): "const_child": {"required": True}, "const_int": {"required": True, "constant": True}, "const_string": {"required": True, "constant": True}, - "const_string_as_enum": {"constant": True}, } _attribute_map = { @@ -146,7 +146,6 @@ class Product(msrest.serialization.Model): const_int = 0 const_string = "constant" - const_string_as_enum = "constant_string_as_enum" def __init__( self, @@ -156,6 +155,7 @@ def __init__( display_names: Optional[List[str]] = None, capacity: Optional[int] = None, image: Optional[str] = None, + const_string_as_enum: Optional[str] = None, **kwargs ): super(Product, self).__init__(**kwargs) @@ -164,3 +164,4 @@ def __init__( self.image = image self.child = child self.const_child = const_child + self.const_string_as_enum = const_string_as_enum