@autorest/python 5.16.0 → 5.17.0

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.
Files changed (92) hide show
  1. package/ChangeLog.md +43 -3
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +1 -1
  4. package/autorest/codegen/__init__.py +48 -209
  5. package/autorest/codegen/models/__init__.py +116 -83
  6. package/autorest/codegen/models/base_builder.py +49 -88
  7. package/autorest/codegen/models/base_model.py +1 -1
  8. package/autorest/codegen/models/{base_schema.py → base_type.py} +56 -40
  9. package/autorest/codegen/models/client.py +157 -48
  10. package/autorest/codegen/models/code_model.py +108 -254
  11. package/autorest/codegen/models/combined_type.py +107 -0
  12. package/autorest/codegen/models/{constant_schema.py → constant_type.py} +49 -40
  13. package/autorest/codegen/models/credential_types.py +224 -0
  14. package/autorest/codegen/models/{dictionary_schema.py → dictionary_type.py} +41 -31
  15. package/autorest/codegen/models/enum_type.py +195 -0
  16. package/autorest/codegen/models/imports.py +23 -0
  17. package/autorest/codegen/models/list_type.py +134 -0
  18. package/autorest/codegen/models/lro_operation.py +77 -156
  19. package/autorest/codegen/models/lro_paging_operation.py +28 -11
  20. package/autorest/codegen/models/model_type.py +239 -0
  21. package/autorest/codegen/models/operation.py +303 -269
  22. package/autorest/codegen/models/operation_group.py +48 -89
  23. package/autorest/codegen/models/paging_operation.py +80 -123
  24. package/autorest/codegen/models/parameter.py +289 -396
  25. package/autorest/codegen/models/parameter_list.py +348 -360
  26. package/autorest/codegen/models/primitive_types.py +544 -0
  27. package/autorest/codegen/models/property.py +109 -139
  28. package/autorest/codegen/models/request_builder.py +105 -88
  29. package/autorest/codegen/models/request_builder_parameter.py +112 -100
  30. package/autorest/codegen/models/response.py +325 -0
  31. package/autorest/codegen/models/utils.py +12 -19
  32. package/autorest/codegen/serializers/__init__.py +46 -37
  33. package/autorest/codegen/serializers/builder_serializer.py +604 -1146
  34. package/autorest/codegen/serializers/client_serializer.py +83 -88
  35. package/autorest/codegen/serializers/general_serializer.py +5 -64
  36. package/autorest/codegen/serializers/import_serializer.py +7 -4
  37. package/autorest/codegen/serializers/metadata_serializer.py +15 -104
  38. package/autorest/codegen/serializers/model_base_serializer.py +40 -32
  39. package/autorest/codegen/serializers/model_generic_serializer.py +8 -6
  40. package/autorest/codegen/serializers/model_init_serializer.py +2 -4
  41. package/autorest/codegen/serializers/model_python3_serializer.py +22 -16
  42. package/autorest/codegen/serializers/operation_groups_serializer.py +4 -13
  43. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  44. package/autorest/codegen/serializers/request_builders_serializer.py +12 -29
  45. package/autorest/codegen/serializers/utils.py +0 -142
  46. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  47. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
  48. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  49. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  50. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  51. package/autorest/codegen/templates/init.py.jinja2 +2 -2
  52. package/autorest/codegen/templates/lro_operation.py.jinja2 +4 -1
  53. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +4 -1
  54. package/autorest/codegen/templates/metadata.json.jinja2 +33 -33
  55. package/autorest/codegen/templates/model.py.jinja2 +23 -24
  56. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  57. package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
  58. package/autorest/codegen/templates/operation.py.jinja2 +6 -8
  59. package/autorest/codegen/templates/operation_group.py.jinja2 +7 -7
  60. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
  61. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  62. package/autorest/codegen/templates/paging_operation.py.jinja2 +2 -2
  63. package/autorest/codegen/templates/request_builder.py.jinja2 +13 -11
  64. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  65. package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
  66. package/autorest/jsonrpc/server.py +15 -3
  67. package/autorest/m4reformatter/__init__.py +1108 -0
  68. package/autorest/multiapi/models/code_model.py +1 -1
  69. package/autorest/multiapi/serializers/__init__.py +4 -4
  70. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  71. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  72. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +3 -3
  73. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  74. package/autorest/postprocess/__init__.py +202 -0
  75. package/autorest/postprocess/get_all.py +19 -0
  76. package/autorest/postprocess/venvtools.py +73 -0
  77. package/autorest/preprocess/__init__.py +209 -0
  78. package/autorest/preprocess/helpers.py +54 -0
  79. package/autorest/{namer → preprocess}/python_mappings.py +21 -16
  80. package/package.json +2 -2
  81. package/autorest/codegen/models/credential_model.py +0 -55
  82. package/autorest/codegen/models/credential_schema.py +0 -95
  83. package/autorest/codegen/models/credential_schema_policy.py +0 -73
  84. package/autorest/codegen/models/enum_schema.py +0 -225
  85. package/autorest/codegen/models/list_schema.py +0 -135
  86. package/autorest/codegen/models/object_schema.py +0 -303
  87. package/autorest/codegen/models/primitive_schemas.py +0 -495
  88. package/autorest/codegen/models/request_builder_parameter_list.py +0 -249
  89. package/autorest/codegen/models/schema_request.py +0 -55
  90. package/autorest/codegen/models/schema_response.py +0 -141
  91. package/autorest/namer/__init__.py +0 -23
  92. package/autorest/namer/name_converter.py +0 -509
@@ -3,131 +3,164 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Dict
6
+ from typing import Any, Dict, Union
7
7
  from .base_model import BaseModel
8
8
  from .code_model import CodeModel
9
- from .credential_schema import AzureKeyCredentialSchema, TokenCredentialSchema
10
- from .object_schema import ObjectSchema, get_object_schema, HiddenModelObjectSchema
11
- from .dictionary_schema import DictionarySchema
12
- from .list_schema import ListSchema
13
- from .primitive_schemas import (
14
- get_primitive_schema,
15
- AnySchema,
16
- PrimitiveSchema,
17
- IOSchema,
9
+ from .model_type import ModelType
10
+ from .dictionary_type import DictionaryType
11
+ from .list_type import ListType
12
+ from .combined_type import CombinedType
13
+ from .primitive_types import (
14
+ ByteArraySchema,
15
+ DateType,
16
+ DatetimeType,
17
+ DurationType,
18
+ IntegerType,
19
+ FloatType,
20
+ StringType,
21
+ TimeType,
22
+ AnyType,
23
+ PrimitiveType,
24
+ BinaryType,
25
+ BooleanType,
26
+ AnyObjectType,
27
+ UnixTimeType,
18
28
  )
19
- from .enum_schema import EnumSchema, HiddenModelEnumSchema, get_enum_schema
20
- from .base_schema import BaseSchema
21
- from .constant_schema import ConstantSchema
29
+ from .enum_type import EnumType
30
+ from .base_type import BaseType
31
+ from .constant_type import ConstantType
22
32
  from .imports import FileImport, ImportType, TypingSection
23
33
  from .lro_operation import LROOperation
24
34
  from .paging_operation import PagingOperation
25
35
  from .parameter import (
26
36
  Parameter,
27
- ParameterStyle,
28
- ParameterLocation,
29
37
  ParameterMethodLocation,
38
+ ParameterLocation,
39
+ BodyParameter,
40
+ ParameterDelimeter,
41
+ MultipartBodyParameter,
42
+ ClientParameter,
43
+ ConfigParameter,
30
44
  )
31
45
  from .operation import Operation
32
46
  from .property import Property
33
47
  from .operation_group import OperationGroup
34
- from .schema_response import SchemaResponse
35
- from .parameter_list import ParameterList, GlobalParameterList
36
- from .request_builder import RequestBuilder
48
+ from .response import Response
49
+ from .parameter_list import (
50
+ ParameterList,
51
+ ClientGlobalParameterList,
52
+ ConfigGlobalParameterList,
53
+ )
54
+ from .request_builder import (
55
+ RequestBuilder,
56
+ OverloadedRequestBuilder,
57
+ RequestBuilderBase,
58
+ )
37
59
  from .base_builder import BaseBuilder
38
60
  from .lro_paging_operation import LROPagingOperation
39
- from .request_builder_parameter import RequestBuilderParameter
40
- from .schema_request import SchemaRequest
61
+ from .request_builder_parameter import (
62
+ RequestBuilderParameter,
63
+ RequestBuilderBodyParameter,
64
+ )
65
+ from .credential_types import (
66
+ TokenCredentialType,
67
+ AzureKeyCredentialType,
68
+ ARMChallengeAuthenticationPolicyType,
69
+ BearerTokenCredentialPolicyType,
70
+ AzureKeyCredentialPolicyType,
71
+ CredentialType,
72
+ )
41
73
 
42
74
  __all__ = [
43
- "AzureKeyCredentialSchema",
44
- "AnySchema",
75
+ "AzureKeyCredentialPolicyType",
76
+ "AnyType",
45
77
  "BaseModel",
46
- "BaseSchema",
78
+ "BaseType",
47
79
  "CodeModel",
48
- "ConstantSchema",
49
- "ObjectSchema",
50
- "DictionarySchema",
51
- "ListSchema",
52
- "EnumSchema",
53
- "HiddenModelEnumSchema",
80
+ "ConstantType",
81
+ "ModelType",
82
+ "DictionaryType",
83
+ "ListType",
84
+ "EnumType",
54
85
  "FileImport",
55
86
  "ImportType",
56
87
  "TypingSection",
57
- "PrimitiveSchema",
88
+ "PrimitiveType",
58
89
  "LROOperation",
59
90
  "Operation",
60
91
  "PagingOperation",
61
92
  "Parameter",
62
93
  "ParameterList",
63
- "ParameterLocation",
64
94
  "OperationGroup",
65
95
  "Property",
66
96
  "RequestBuilder",
67
- "SchemaResponse",
68
- "TokenCredentialSchema",
97
+ "Response",
98
+ "TokenCredentialType",
69
99
  "LROPagingOperation",
70
100
  "BaseBuilder",
71
- "SchemaRequest",
72
101
  "RequestBuilderParameter",
73
- "HiddenModelObjectSchema",
74
- "ParameterStyle",
75
- "IOSchema",
76
- "GlobalParameterList",
102
+ "BinaryType",
103
+ "ClientGlobalParameterList",
104
+ "ConfigGlobalParameterList",
77
105
  "ParameterMethodLocation",
106
+ "ParameterLocation",
107
+ "OverloadedRequestBuilder",
108
+ "RequestBuilderBase",
109
+ "BodyParameter",
110
+ "RequestBuilderBodyParameter",
111
+ "ParameterDelimeter",
112
+ "MultipartBodyParameter",
113
+ "CredentialType",
114
+ "ClientParameter",
115
+ "ConfigParameter",
78
116
  ]
79
117
 
118
+ TYPE_TO_OBJECT = {
119
+ "integer": IntegerType,
120
+ "float": FloatType,
121
+ "string": StringType,
122
+ "list": ListType,
123
+ "dict": DictionaryType,
124
+ "constant": ConstantType,
125
+ "enum": EnumType,
126
+ "binary": BinaryType,
127
+ "any": AnyType,
128
+ "datetime": DatetimeType,
129
+ "time": TimeType,
130
+ "duration": DurationType,
131
+ "date": DateType,
132
+ "byte-array": ByteArraySchema,
133
+ "boolean": BooleanType,
134
+ "combined": CombinedType,
135
+ "OAuth2": TokenCredentialType,
136
+ "Key": AzureKeyCredentialType,
137
+ "ARMChallengeAuthenticationPolicy": ARMChallengeAuthenticationPolicyType,
138
+ "BearerTokenCredentialPolicy": BearerTokenCredentialPolicyType,
139
+ "AzureKeyCredentialPolicy": AzureKeyCredentialPolicyType,
140
+ "any-object": AnyObjectType,
141
+ "unixtime": UnixTimeType,
142
+ }
80
143
 
81
- def _generate_as_object_schema(yaml_data: Dict[str, Any]) -> bool:
82
- if (
83
- yaml_data.get("properties")
84
- or yaml_data.get("discriminator")
85
- or yaml_data.get("parents")
86
- and yaml_data["parents"].get("immediate")
87
- ):
88
- return True
89
- return False
90
144
 
91
-
92
- def build_schema(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseSchema:
145
+ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
93
146
  yaml_id = id(yaml_data)
94
147
  try:
95
- return code_model.lookup_schema(yaml_id)
148
+ return code_model.lookup_type(yaml_id)
96
149
  except KeyError:
97
150
  # Not created yet, let's create it and add it to the index
98
151
  pass
99
- schema: BaseSchema
100
- schema_type = yaml_data["type"]
101
- if schema_type == "constant":
102
- schema = ConstantSchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
103
- code_model.primitives[yaml_id] = schema
104
-
105
- elif schema_type in ["choice", "sealed-choice"]:
106
- schema = get_enum_schema(code_model).from_yaml(
107
- yaml_data=yaml_data, code_model=code_model
108
- )
109
- code_model.enums[yaml_id] = schema
110
-
111
- elif schema_type == "array":
112
- schema = ListSchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
113
- code_model.primitives[yaml_id] = schema
114
-
115
- elif schema_type == "dictionary":
116
- schema = DictionarySchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
117
- code_model.primitives[yaml_id] = schema
118
-
119
- elif schema_type in ["object", "and", "group", "any-object"]:
120
- if _generate_as_object_schema(yaml_data):
121
- # To avoid infinite loop, create the right instance in memory,
122
- # put it in the index, and then parse the object.
123
- schema = get_object_schema(code_model)(yaml_data, code_model, "_", "")
124
- code_model.schemas[yaml_id] = schema
125
- schema.fill_instance_from_yaml(yaml_data=yaml_data, code_model=code_model)
126
- else:
127
- schema = AnySchema.from_yaml(yaml_data=yaml_data, code_model=code_model)
128
- code_model.primitives[yaml_id] = schema
152
+ if yaml_data["type"] == "model":
153
+ # need to special case model to avoid recursion
154
+ response = ModelType(yaml_data, code_model)
155
+ code_model.types_map[yaml_id] = response
156
+ response.fill_instance_from_yaml(yaml_data, code_model)
129
157
  else:
130
- schema = get_primitive_schema(yaml_data=yaml_data, code_model=code_model)
131
- code_model.primitives[yaml_id] = schema
158
+ response = TYPE_TO_OBJECT[yaml_data["type"]].from_yaml(yaml_data, code_model) # type: ignore
159
+ code_model.types_map[yaml_id] = response
160
+ return response
161
+
132
162
 
133
- return schema
163
+ RequestBuilderType = Union[RequestBuilder, OverloadedRequestBuilder]
164
+ ParameterType = Union[
165
+ Parameter, RequestBuilderParameter, ClientParameter, ConfigParameter
166
+ ]
@@ -3,66 +3,32 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Callable, Dict, List, Optional, Union, TYPE_CHECKING
6
+ from abc import abstractmethod
7
+ from typing import Any, Dict, List, Optional, TypeVar, Union, TYPE_CHECKING, Generic
7
8
  from .base_model import BaseModel
8
- from .schema_response import SchemaResponse
9
- from .schema_request import SchemaRequest
9
+ from .parameter_list import (
10
+ ParameterList,
11
+ RequestBuilderParameterList,
12
+ OverloadedRequestBuilderParameterList,
13
+ )
14
+
15
+ ParameterListType = TypeVar(
16
+ "ParameterListType",
17
+ bound=Union[
18
+ ParameterList,
19
+ RequestBuilderParameterList,
20
+ OverloadedRequestBuilderParameterList,
21
+ ],
22
+ )
23
+
10
24
 
11
25
  if TYPE_CHECKING:
12
26
  from .code_model import CodeModel
27
+ from .operation import Operation
28
+ from .request_builder import RequestBuilder
13
29
 
14
30
 
15
- _M4_HEADER_PARAMETERS = ["content_type", "accept"]
16
-
17
-
18
- def create_parameters(
19
- yaml_data: Dict[str, Any], code_model, parameter_creator: Callable
20
- ):
21
- multiple_requests = len(yaml_data["requests"]) > 1
22
-
23
- multiple_content_type_parameters = []
24
- parameters = [
25
- parameter_creator(yaml, code_model=code_model)
26
- for yaml in yaml_data.get("parameters", [])
27
- ]
28
-
29
- for request in yaml_data["requests"]:
30
- for yaml in request.get("parameters", []):
31
- parameter = parameter_creator(yaml, code_model=code_model)
32
- name = yaml["language"]["python"]["name"]
33
- if name in _M4_HEADER_PARAMETERS:
34
- parameters.append(parameter)
35
- elif multiple_requests:
36
- parameter.has_multiple_content_types = True
37
- multiple_content_type_parameters.append(parameter)
38
- else:
39
- parameters.append(parameter)
40
-
41
- if multiple_content_type_parameters:
42
- body_parameters_name_set = set(
43
- p.serialized_name for p in multiple_content_type_parameters
44
- )
45
- if len(body_parameters_name_set) > 1:
46
- raise ValueError(
47
- f"The body parameter with multiple media types has different names: {body_parameters_name_set}"
48
- )
49
-
50
- parameters_index = {id(parameter.yaml_data): parameter for parameter in parameters}
51
-
52
- # Need to connect the groupBy and originalParameter
53
- for parameter in parameters:
54
- parameter_grouped_by_id = id(parameter.grouped_by)
55
- if parameter_grouped_by_id in parameters_index:
56
- parameter.grouped_by = parameters_index[parameter_grouped_by_id]
57
-
58
- parameter_original_id = id(parameter.original_parameter)
59
- if parameter_original_id in parameters_index:
60
- parameter.original_parameter = parameters_index[parameter_original_id]
61
-
62
- return parameters, multiple_content_type_parameters
63
-
64
-
65
- class BaseBuilder(BaseModel):
31
+ class BaseBuilder(Generic[ParameterListType], BaseModel):
66
32
  """Base class for Operations and Request Builders"""
67
33
 
68
34
  def __init__(
@@ -70,26 +36,27 @@ class BaseBuilder(BaseModel):
70
36
  yaml_data: Dict[str, Any],
71
37
  code_model: "CodeModel",
72
38
  name: str,
73
- description: str,
74
- parameters,
75
- schema_requests: List[SchemaRequest],
76
- responses: Optional[List[SchemaResponse]] = None,
77
- summary: Optional[str] = None,
39
+ parameters: ParameterListType,
78
40
  *,
41
+ overloads=None,
79
42
  abstract: bool = False,
80
43
  want_tracing: bool = True,
81
44
  ) -> None:
82
45
  super().__init__(yaml_data=yaml_data, code_model=code_model)
83
46
  self.name = name
84
- self._description = description
47
+ self._description: str = yaml_data.get("description", "")
85
48
  self.parameters = parameters
86
- self.responses = responses or []
87
- self._summary = summary
88
- self.schema_requests = schema_requests
49
+ self.overloads: Union[List["Operation"], List["RequestBuilder"]] = (
50
+ overloads or []
51
+ )
52
+ self._summary: str = yaml_data.get("summary", "")
89
53
  # for operations where we don't know what to do, we mark them as abstract so users implement
90
54
  # in patch.py
91
55
  self.abstract = abstract
92
56
  self.want_tracing = want_tracing
57
+ self.group_name: str = yaml_data["groupName"]
58
+ self.is_overload: bool = yaml_data["isOverload"]
59
+ self.api_versions: List[str] = yaml_data["apiVersions"]
93
60
 
94
61
  @property
95
62
  def summary(self) -> Optional[str]:
@@ -97,6 +64,22 @@ class BaseBuilder(BaseModel):
97
64
  return None
98
65
  return self._summary
99
66
 
67
+ @property
68
+ def pylint_disable(self) -> str:
69
+ return ""
70
+
71
+ @abstractmethod
72
+ def response_type_annotation(self, **kwargs) -> str:
73
+ ...
74
+
75
+ @abstractmethod
76
+ def response_docstring_text(self, **kwargs) -> str:
77
+ ...
78
+
79
+ @abstractmethod
80
+ def response_docstring_type(self, **kwargs) -> str:
81
+ ...
82
+
100
83
  @property
101
84
  def description(self) -> str:
102
85
  if self.abstract:
@@ -104,31 +87,9 @@ class BaseBuilder(BaseModel):
104
87
  f'You need to write a custom operation for "{self.name}". Please refer to '
105
88
  "https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
106
89
  )
107
- return self._description
108
-
109
- @property
110
- def default_content_type_declaration(self) -> str:
111
- return f'"{self.parameters.default_content_type}"'
112
-
113
- def get_response_from_status(
114
- self, status_code: Optional[Union[str, int]]
115
- ) -> SchemaResponse:
116
- for response in self.responses:
117
- if status_code in response.status_codes:
118
- return response
119
- raise ValueError(f"Incorrect status code {status_code}, operation {self.name}")
120
-
121
- @property
122
- def success_status_code(self) -> List[Union[str, int]]:
123
- """The list of all successfull status code."""
124
- return [
125
- code
126
- for response in self.responses
127
- for code in response.status_codes
128
- if code != "default"
129
- ]
90
+ return self._description or self.name
130
91
 
131
- def method_signature(self, is_python3_file: bool) -> List[str]:
92
+ def method_signature(self, is_python3_file: bool, async_mode: bool) -> List[str]:
132
93
  if self.abstract:
133
94
  return ["*args,", "**kwargs"]
134
- return self.parameters.method_signature(is_python3_file)
95
+ return self.parameters.method_signature(is_python3_file, async_mode)
@@ -10,7 +10,7 @@ if TYPE_CHECKING:
10
10
 
11
11
 
12
12
  class BaseModel:
13
- """This is the base class for model that are based on some YAML data.
13
+ """This is the base class for model representations that are based on some YAML data.
14
14
 
15
15
  :param yaml_data: the yaml data for this schema
16
16
  :type yaml_data: dict[str, Any]
@@ -4,7 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from abc import ABC, abstractmethod
7
- from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING
7
+ from typing import Any, Dict, List, Optional, TYPE_CHECKING
8
8
 
9
9
  from .base_model import BaseModel
10
10
  from .imports import FileImport
@@ -13,8 +13,8 @@ if TYPE_CHECKING:
13
13
  from .code_model import CodeModel
14
14
 
15
15
 
16
- class BaseSchema(BaseModel, ABC):
17
- """This is the base class for all schema models.
16
+ class BaseType(BaseModel, ABC):
17
+ """This is the base class for all types.
18
18
 
19
19
  :param yaml_data: the yaml data for this schema
20
20
  :type yaml_data: dict[str, Any]
@@ -22,26 +22,33 @@ class BaseSchema(BaseModel, ABC):
22
22
 
23
23
  def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
24
24
  super().__init__(yaml_data, code_model)
25
- self.default_value = yaml_data.get("defaultValue", None)
26
- self.xml_metadata = yaml_data.get("serialization", {}).get("xml", {})
27
- self.api_versions = set(
28
- value_dict["version"] for value_dict in yaml_data.get("apiVersions", [])
29
- )
25
+ self.type = yaml_data["type"] # the type discriminator
26
+ self.api_versions: List[str] = yaml_data.get(
27
+ "apiVersions", []
28
+ ) # api versions this type is in.
30
29
 
31
30
  @classmethod
32
31
  def from_yaml(
33
32
  cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
34
- ) -> "BaseSchema":
33
+ ) -> "BaseType":
35
34
  return cls(yaml_data=yaml_data, code_model=code_model)
36
35
 
36
+ def imports( # pylint: disable=no-self-use
37
+ self, **kwargs # pylint: disable=unused-argument
38
+ ) -> FileImport:
39
+ return FileImport()
40
+
37
41
  @property
38
- def extra_description_information(self) -> str:
39
- return ""
42
+ def xml_metadata(self) -> Dict[str, Any]:
43
+ """XML metadata for the type, if the type has it."""
44
+ return self.yaml_data.get("xmlMetadata", {})
40
45
 
41
46
  @property
42
- def has_xml_serialization_ctxt(self) -> bool:
47
+ def is_xml(self) -> bool:
48
+ """Whether the type is an XML type or not. Most likely not."""
43
49
  return bool(self.xml_metadata)
44
50
 
51
+ @property
45
52
  def xml_serialization_ctxt(self) -> Optional[str]:
46
53
  """Return the serialization context in case this schema is used in an operation."""
47
54
  attrs_list = []
@@ -57,12 +64,6 @@ class BaseSchema(BaseModel, ABC):
57
64
  attrs_list.append(f"'text': True")
58
65
  return ", ".join(attrs_list)
59
66
 
60
- def imports(self) -> FileImport: # pylint: disable=no-self-use
61
- return FileImport()
62
-
63
- def model_file_imports(self) -> FileImport:
64
- return self.imports()
65
-
66
67
  @property
67
68
  @abstractmethod
68
69
  def serialization_type(self) -> str:
@@ -79,14 +80,22 @@ class BaseSchema(BaseModel, ABC):
79
80
  ...
80
81
 
81
82
  @property
83
+ def client_default_value(self) -> Any:
84
+ """Whether there's a client default value for this type"""
85
+ return self.yaml_data.get("clientDefaultValue")
86
+
82
87
  @abstractmethod
83
- def docstring_text(self) -> str:
88
+ def description(self, *, is_operation_file: bool) -> str:
89
+ """The description"""
90
+ ...
91
+
92
+ @abstractmethod
93
+ def docstring_text(self, **kwargs: Any) -> str:
84
94
  """The names used in rtype documentation"""
85
95
  ...
86
96
 
87
- @property
88
97
  @abstractmethod
89
- def docstring_type(self) -> str:
98
+ def docstring_type(self, **kwargs: Any) -> str:
90
99
  """The python type used for RST syntax input.
91
100
 
92
101
  Special case for enum, for instance: 'str or ~namespace.EnumName'
@@ -94,13 +103,22 @@ class BaseSchema(BaseModel, ABC):
94
103
  ...
95
104
 
96
105
  @abstractmethod
97
- def type_annotation(self, *, is_operation_file: bool = False) -> str:
106
+ def type_annotation(self, **kwargs: Any) -> str:
98
107
  """The python type used for type annotation
99
108
 
100
109
  Special case for enum, for instance: Union[str, "EnumName"]
101
110
  """
102
111
  ...
103
112
 
113
+ @property
114
+ def validation(self) -> Optional[Dict[str, Any]]:
115
+ """Whether there's any validation constraints on this type.
116
+
117
+ Even though we generate validation maps if there are validation constraints,
118
+ only SDKs with client-side-validate=true (0.001% libraries, if any) actually raise in this case.
119
+ """
120
+ return None
121
+
104
122
  def get_declaration(self, value: Any) -> str: # pylint: disable=no-self-use
105
123
  """Return the current value from YAML as a Python string that represents the constant.
106
124
 
@@ -114,26 +132,24 @@ class BaseSchema(BaseModel, ABC):
114
132
  """
115
133
  return str(value)
116
134
 
117
- @property
118
- def default_value_declaration(self) -> str:
119
- """Return the default value as string using get_declaration."""
120
- if self.default_value is None:
121
- return "None"
122
- return self.get_declaration(self.default_value)
123
-
124
- @property
125
- def validation_map(
135
+ @abstractmethod
136
+ def get_json_template_representation(
126
137
  self,
127
- ) -> Optional[Dict[str, Union[bool, int, str]]]: # pylint: disable=no-self-use
128
- return None
138
+ *,
139
+ optional: bool = True,
140
+ client_default_value_declaration: Optional[str] = None,
141
+ description: Optional[str] = None,
142
+ ) -> Any:
143
+ """Template of what this schema would look like as JSON input"""
144
+ ...
129
145
 
130
146
  @property
131
- def serialization_constraints(
132
- self,
133
- ) -> Optional[List[str]]: # pylint: disable=no-self-use
134
- return None
135
-
136
147
  @abstractmethod
137
- def get_json_template_representation(self, **kwargs: Any) -> Any:
138
- """Template of what this schema would look like as JSON input"""
148
+ def instance_check_template(self) -> str:
149
+ """Template of what an instance check of a variable for this type would look like"""
139
150
  ...
151
+
152
+ @property
153
+ def serialization_constraints(self) -> List[str]:
154
+ """Whether there are any serialization constraints when serializing this type."""
155
+ return []