Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions autorest/codegen/models/dictionary_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, Optional
from .base_schema import BaseSchema
from .imports import FileImport, ImportType, TypingSection

Expand All @@ -25,7 +25,6 @@ def __init__(
) -> None:
super(DictionarySchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
self.element_type = element_type
self.nullable_items = self.yaml_data.get("nullableItems", False)

@property
def serialization_type(self) -> str:
Expand Down Expand Up @@ -61,13 +60,6 @@ def docstring_type(self) -> str:
"""
return f"dict[str, {self.element_type.docstring_type}]"

@property
def validation_map(self) -> Optional[Dict[str, Union[bool, int, str]]]:
validation_map: Dict[str, Union[bool, int, str]] = {}
if self.nullable_items:
validation_map["nullable_items"] = True
return validation_map or None

def xml_serialization_ctxt(self) -> Optional[str]:
raise NotImplementedError("Dictionary schema does not support XML serialization.")

Expand Down
19 changes: 11 additions & 8 deletions autorest/codegen/models/list_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ def __init__(
namespace: str,
yaml_data: Dict[str, Any],
element_type: BaseSchema,
*,
max_items: Optional[int] = None,
min_items: Optional[int] = None,
unique_items: Optional[int] = None,
) -> None:
super(ListSchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
self.element_type = element_type

self.max_items = self.yaml_data.get("maxItems", False)
self.min_items = self.yaml_data.get("minItems", False)
self.unique_items = self.yaml_data.get("uniqueItems", False)
self.nullable_items = self.yaml_data.get("nullableItems", False)
self.max_items = max_items
self.min_items = min_items
self.unique_items = unique_items

@property
def serialization_type(self) -> str:
Expand Down Expand Up @@ -53,8 +55,6 @@ def validation_map(self) -> Optional[Dict[str, Union[bool, int, str]]]:
validation_map["min_items"] = self.min_items
if self.unique_items:
validation_map["unique"] = True
if self.nullable_items:
validation_map["nullable_items"] = True
return validation_map or None

@property
Expand Down Expand Up @@ -94,7 +94,10 @@ def from_yaml(cls, namespace: str, yaml_data: Dict[str, Any], **kwargs) -> "List
return cls(
namespace=namespace,
yaml_data=yaml_data,
element_type=element_type
element_type=element_type,
max_items=yaml_data.get("maxItems"),
min_items=yaml_data.get("minItems"),
unique_items=yaml_data.get("uniqueItems"),
)

def imports(self) -> FileImport:
Expand Down
3 changes: 0 additions & 3 deletions autorest/codegen/models/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ def __init__(
validation_map["readonly"] = True
if self.constant:
validation_map["constant"] = True
if self.yaml_data.get("nullable", False):
validation_map["nullable"] = 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)
Expand Down
9 changes: 0 additions & 9 deletions autorest/codegen/models/schema_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ def __init__(
self.status_codes = status_codes
self.headers = headers
self.binary = binary
self.nullable = self.yaml_data.get("nullable", False)

@property
def operation_type_annotation(self) -> str:
if not self.schema:
return "None"
if self.nullable:
return f"Optional[{self.schema.operation_type_annotation}]"
return self.schema.operation_type_annotation

@property
def has_body(self) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions autorest/codegen/templates/operation_tools.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{%- if return_type -%}
{{ return_type }}
{%- else -%}
{{ ((return_type_wrapper | join("[") + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~
(operation.responses | selectattr('has_body') | map(attribute='operation_type_annotation') | unique | join(', ')) ~
("]" if operation.responses | selectattr('has_body') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ("]" if operation.has_optional_return_type else "") ~ ( ("]" * return_type_wrapper | count ) if return_type_wrapper else "")
{{ ((return_type_wrapper | join("[") + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~
(operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | join(', ')) ~
("]" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ("]" if operation.has_optional_return_type else "") ~ ( ("]" * return_type_wrapper | count ) if return_type_wrapper else "")
if operation.responses | selectattr('has_body') | first
else ((return_type_wrapper | join("[") + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ "None" ~ ("]" if operation.has_optional_return_type else "") ~ ( ("]" * return_type_wrapper | count ) if return_type_wrapper else "") }}{%- endif -%}{% endmacro %}
{# get async mypy typing #}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"@autorest/autorest": "^3.0.0",
"@microsoft.azure/autorest.testserver": "^2.10.58"
"@microsoft.azure/autorest.testserver": "^2.10.56"
},
"files": [
"autorest/**/*.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, client, config, serializer, deserializer) -> None:
async def get_null(
self,
**kwargs
) -> Optional[datetime.timedelta]:
) -> datetime.timedelta:
"""Get null duration value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: timedelta, or the result of cls(response)
:rtype: ~datetime.timedelta
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.timedelta]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def get_null(
self,
**kwargs # type: Any
):
# type: (...) -> Optional[datetime.timedelta]
# type: (...) -> datetime.timedelta
"""Get null duration value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: timedelta, or the result of cls(response)
:rtype: ~datetime.timedelta
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.timedelta]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ async def put_false(
async def get_null(
self,
**kwargs
) -> Optional[bool]:
) -> bool:
"""Get null Boolean value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: bool, or the result of cls(response)
:rtype: bool
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[bool]]
cls = kwargs.pop('cls', None) # type: ClsType[bool]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ def get_null(
self,
**kwargs # type: Any
):
# type: (...) -> Optional[bool]
# type: (...) -> bool
"""Get null Boolean value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: bool, or the result of cls(response)
:rtype: bool
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[bool]]
cls = kwargs.pop('cls', None) # type: ClsType[bool]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class Basic(msrest.serialization.Model):
:type color: str or ~bodycomplex.models.CMYKColors
"""

_validation = {
'id': {'nullable': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'int'},
'name': {'key': 'name', 'type': 'str'},
Expand Down Expand Up @@ -369,10 +365,6 @@ class DictionaryWrapper(msrest.serialization.Model):
:type default_program: dict[str, str]
"""

_validation = {
'default_program': {'nullable': True},
}

_attribute_map = {
'default_program': {'key': 'defaultProgram', 'type': '{str}'},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ class Basic(msrest.serialization.Model):
:type color: str or ~bodycomplex.models.CMYKColors
"""

_validation = {
'id': {'nullable': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'int'},
'name': {'key': 'name', 'type': 'str'},
Expand Down Expand Up @@ -418,10 +414,6 @@ class DictionaryWrapper(msrest.serialization.Model):
:type default_program: dict[str, str]
"""

_validation = {
'default_program': {'nullable': True},
}

_attribute_map = {
'default_program': {'key': 'defaultProgram', 'type': '{str}'},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, client, config, serializer, deserializer) -> None:
async def get_null(
self,
**kwargs
) -> Optional[datetime.date]:
) -> datetime.date:
"""Get null date value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: date, or the result of cls(response)
:rtype: ~datetime.date
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.date]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.date]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def get_null(
self,
**kwargs # type: Any
):
# type: (...) -> Optional[datetime.date]
# type: (...) -> datetime.date
"""Get null date value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: date, or the result of cls(response)
:rtype: ~datetime.date
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.date]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.date]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, client, config, serializer, deserializer) -> None:
async def get_null(
self,
**kwargs
) -> Optional[datetime.datetime]:
) -> datetime.datetime:
"""Get null datetime value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: datetime, or the result of cls(response)
:rtype: ~datetime.datetime
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.datetime]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.datetime]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def get_null(
self,
**kwargs # type: Any
):
# type: (...) -> Optional[datetime.datetime]
# type: (...) -> datetime.datetime
"""Get null datetime value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: datetime, or the result of cls(response)
:rtype: ~datetime.datetime
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.datetime]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.datetime]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, client, config, serializer, deserializer) -> None:
async def get_null(
self,
**kwargs
) -> Optional[datetime.datetime]:
) -> datetime.datetime:
"""Get null datetime value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: datetime, or the result of cls(response)
:rtype: ~datetime.datetime
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.datetime]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.datetime]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def get_null(
self,
**kwargs # type: Any
):
# type: (...) -> Optional[datetime.datetime]
# type: (...) -> datetime.datetime
"""Get null datetime value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: datetime, or the result of cls(response)
:rtype: ~datetime.datetime
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.datetime]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.datetime]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, client, config, serializer, deserializer) -> None:
async def get_null(
self,
**kwargs
) -> Optional[datetime.timedelta]:
) -> datetime.timedelta:
"""Get null duration value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: timedelta, or the result of cls(response)
:rtype: ~datetime.timedelta
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.timedelta]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def get_null(
self,
**kwargs # type: Any
):
# type: (...) -> Optional[datetime.timedelta]
# type: (...) -> datetime.timedelta
"""Get null duration value.

:keyword callable cls: A custom type or function that will be passed the direct response
:return: timedelta, or the result of cls(response)
:rtype: ~datetime.timedelta
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[Optional[datetime.timedelta]]
cls = kwargs.pop('cls', None) # type: ClsType[datetime.timedelta]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down
Loading