@autorest/python 5.13.0 → 5.16.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 (101) hide show
  1. package/ChangeLog.md +67 -0
  2. package/autorest/__init__.py +1 -2
  3. package/autorest/black/__init__.py +12 -5
  4. package/autorest/codegen/__init__.py +239 -105
  5. package/autorest/codegen/models/__init__.py +29 -18
  6. package/autorest/codegen/models/base_builder.py +48 -11
  7. package/autorest/codegen/models/base_model.py +6 -4
  8. package/autorest/codegen/models/base_schema.py +21 -24
  9. package/autorest/codegen/models/client.py +70 -20
  10. package/autorest/codegen/models/code_model.py +144 -129
  11. package/autorest/codegen/models/constant_schema.py +32 -16
  12. package/autorest/codegen/models/credential_model.py +55 -0
  13. package/autorest/codegen/models/credential_schema.py +21 -16
  14. package/autorest/codegen/models/credential_schema_policy.py +11 -15
  15. package/autorest/codegen/models/dictionary_schema.py +27 -24
  16. package/autorest/codegen/models/enum_schema.py +41 -62
  17. package/autorest/codegen/models/imports.py +72 -41
  18. package/autorest/codegen/models/list_schema.py +40 -18
  19. package/autorest/codegen/models/lro_operation.py +61 -25
  20. package/autorest/codegen/models/lro_paging_operation.py +5 -6
  21. package/autorest/codegen/models/object_schema.py +113 -59
  22. package/autorest/codegen/models/operation.py +251 -111
  23. package/autorest/codegen/models/operation_group.py +67 -32
  24. package/autorest/codegen/models/paging_operation.py +48 -21
  25. package/autorest/codegen/models/parameter.py +182 -90
  26. package/autorest/codegen/models/parameter_list.py +184 -163
  27. package/autorest/codegen/models/primitive_schemas.py +89 -70
  28. package/autorest/codegen/models/property.py +49 -31
  29. package/autorest/codegen/models/request_builder.py +67 -32
  30. package/autorest/codegen/models/request_builder_parameter.py +54 -23
  31. package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
  32. package/autorest/codegen/models/schema_request.py +16 -6
  33. package/autorest/codegen/models/schema_response.py +35 -17
  34. package/autorest/codegen/models/utils.py +24 -1
  35. package/autorest/codegen/serializers/__init__.py +273 -89
  36. package/autorest/codegen/serializers/builder_serializer.py +711 -333
  37. package/autorest/codegen/serializers/client_serializer.py +114 -43
  38. package/autorest/codegen/serializers/general_serializer.py +84 -25
  39. package/autorest/codegen/serializers/import_serializer.py +93 -31
  40. package/autorest/codegen/serializers/metadata_serializer.py +73 -24
  41. package/autorest/codegen/serializers/model_base_serializer.py +42 -14
  42. package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
  43. package/autorest/codegen/serializers/model_init_serializer.py +5 -1
  44. package/autorest/codegen/serializers/model_python3_serializer.py +9 -8
  45. package/autorest/codegen/serializers/operation_groups_serializer.py +20 -8
  46. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  47. package/autorest/codegen/serializers/patch_serializer.py +14 -2
  48. package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
  49. package/autorest/codegen/serializers/utils.py +60 -21
  50. package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
  51. package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
  52. package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
  53. package/autorest/codegen/templates/README.md.jinja2 +105 -0
  54. package/autorest/codegen/templates/config.py.jinja2 +4 -4
  55. package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
  56. package/autorest/codegen/templates/enum.py.jinja2 +1 -1
  57. package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
  58. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  59. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  60. package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
  61. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
  62. package/autorest/codegen/templates/metadata.json.jinja2 +10 -9
  63. package/autorest/codegen/templates/model.py.jinja2 +1 -6
  64. package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
  65. package/autorest/codegen/templates/operation.py.jinja2 +8 -11
  66. package/autorest/codegen/templates/operation_group.py.jinja2 +15 -18
  67. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
  68. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  69. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  70. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  71. package/autorest/codegen/templates/request_builder.py.jinja2 +19 -14
  72. package/autorest/codegen/templates/setup.py.jinja2 +79 -20
  73. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  74. package/autorest/jsonrpc/__init__.py +7 -12
  75. package/autorest/jsonrpc/localapi.py +4 -3
  76. package/autorest/jsonrpc/server.py +13 -6
  77. package/autorest/jsonrpc/stdstream.py +13 -6
  78. package/autorest/m2r/__init__.py +5 -8
  79. package/autorest/multiapi/__init__.py +24 -14
  80. package/autorest/multiapi/models/client.py +21 -11
  81. package/autorest/multiapi/models/code_model.py +23 -10
  82. package/autorest/multiapi/models/config.py +4 -1
  83. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  84. package/autorest/multiapi/models/global_parameter.py +2 -1
  85. package/autorest/multiapi/models/global_parameters.py +14 -8
  86. package/autorest/multiapi/models/imports.py +35 -18
  87. package/autorest/multiapi/models/mixin_operation.py +5 -5
  88. package/autorest/multiapi/models/operation_group.py +2 -1
  89. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  90. package/autorest/multiapi/serializers/__init__.py +18 -23
  91. package/autorest/multiapi/serializers/import_serializer.py +47 -15
  92. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  93. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
  94. package/autorest/multiapi/utils.py +3 -3
  95. package/autorest/namer/__init__.py +2 -4
  96. package/autorest/namer/name_converter.py +200 -103
  97. package/autorest/namer/python_mappings.py +10 -22
  98. package/package.json +3 -3
  99. package/run-python3.js +2 -3
  100. package/venvtools.py +1 -1
  101. package/autorest/codegen/models/rest.py +0 -42
@@ -4,25 +4,27 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from collections.abc import MutableSequence
7
- from copy import copy
8
7
  import logging
9
8
  from typing import cast, List, Callable, Optional, TypeVar, Dict, TYPE_CHECKING
10
9
 
11
- from .parameter import Parameter, ParameterLocation
10
+ from .parameter import Parameter, ParameterLocation, ParameterMethodLocation
12
11
  from .base_schema import BaseSchema
13
- from .dictionary_schema import DictionarySchema
14
- from .primitive_schemas import AnySchema, StringSchema
12
+ from .primitive_schemas import StringSchema
15
13
  from .utils import JSON_REGEXP
16
14
 
17
15
  if TYPE_CHECKING:
18
16
  from .schema_request import SchemaRequest
17
+ from .code_model import CodeModel
19
18
 
20
- T = TypeVar('T')
19
+ T = TypeVar("T")
21
20
  OrderedSet = Dict[T, None]
22
21
 
23
22
  _LOGGER = logging.getLogger(__name__)
24
23
 
25
- def _method_signature_helper(positional: List[str], keyword_only: Optional[List[str]], kwarg_params: List[str]):
24
+
25
+ def _method_signature_helper(
26
+ positional: List[str], keyword_only: Optional[List[str]], kwarg_params: List[str]
27
+ ):
26
28
  keyword_only = keyword_only or []
27
29
  return positional + keyword_only + kwarg_params
28
30
 
@@ -30,7 +32,7 @@ def _method_signature_helper(positional: List[str], keyword_only: Optional[List[
30
32
  class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
31
33
  def __init__(
32
34
  self,
33
- code_model,
35
+ code_model: "CodeModel",
34
36
  parameters: Optional[List[Parameter]] = None,
35
37
  schema_requests: Optional[List["SchemaRequest"]] = None,
36
38
  ) -> None:
@@ -61,9 +63,17 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
61
63
  # Parameter helpers
62
64
 
63
65
  def has_any_location(self, location: ParameterLocation) -> bool:
64
- return bool([parameter for parameter in self.parameters if parameter.location == location])
66
+ return bool(
67
+ [
68
+ parameter
69
+ for parameter in self.parameters
70
+ if parameter.location == location
71
+ ]
72
+ )
65
73
 
66
- def get_from_predicate(self, predicate: Callable[[Parameter], bool]) -> List[Parameter]:
74
+ def get_from_predicate(
75
+ self, predicate: Callable[[Parameter], bool]
76
+ ) -> List[Parameter]:
67
77
  return [parameter for parameter in self.parameters if predicate(parameter)]
68
78
 
69
79
  def get_from_location(self, location: ParameterLocation) -> List[Parameter]:
@@ -72,9 +82,7 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
72
82
  @property
73
83
  def content_types(self) -> List[str]:
74
84
  ordered_set = {
75
- m: None
76
- for request in self.schema_requests
77
- for m in request.content_types
85
+ m: None for request in self.schema_requests for m in request.content_types
78
86
  }
79
87
  return list(ordered_set.keys())
80
88
 
@@ -116,7 +124,10 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
116
124
  # TODO add 'and parameter.location == "Method"' as requirement to this check once
117
125
  # I can use send_request on operations.
118
126
  # Don't want to duplicate code from send_request.
119
- return parameter.location == ParameterLocation.Uri and parameter.rest_api_name != "$host"
127
+ return (
128
+ parameter.location == ParameterLocation.Uri
129
+ and parameter.rest_api_name != "$host"
130
+ )
120
131
 
121
132
  @property
122
133
  def implementation(self) -> str:
@@ -139,23 +150,26 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
139
150
  headers = self.get_from_location(ParameterLocation.Header)
140
151
  if not headers:
141
152
  return headers
142
- return list({
143
- header.serialized_name: header
144
- for header in headers
145
- }.values())
153
+ return list({header.serialized_name: header for header in headers}.values())
146
154
 
147
155
  @property
148
156
  def grouped(self) -> List[Parameter]:
149
- return self.get_from_predicate(lambda parameter: cast(bool, parameter.grouped_by))
157
+ return self.get_from_predicate(
158
+ lambda parameter: cast(bool, parameter.grouped_by)
159
+ )
150
160
 
151
161
  @property
152
162
  def groupers(self) -> List[Parameter]:
153
163
  groupers: List[Parameter] = []
154
164
  for parameter in self.parameters:
155
- if any([
156
- p for p in self.grouped
157
- if p.grouped_by and id(p.grouped_by.yaml_data) == id(parameter.yaml_data)
158
- ]):
165
+ if any(
166
+ [
167
+ p
168
+ for p in self.grouped
169
+ if p.grouped_by
170
+ and id(p.grouped_by.yaml_data) == id(parameter.yaml_data)
171
+ ]
172
+ ):
159
173
  groupers.append(parameter)
160
174
  return groupers
161
175
 
@@ -167,74 +181,98 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
167
181
  constant from this set of parameters, they are constants on the models and hence they do
168
182
  not have impact on any generation at this level
169
183
  """
170
- return self.get_from_predicate(
171
- lambda parameter: parameter.constant
172
- )
184
+ return self.get_from_predicate(lambda parameter: parameter.constant)
173
185
 
174
186
  @property
175
187
  def multipart(self) -> List[Parameter]:
176
- return self.get_from_predicate(
177
- lambda parameter: parameter.is_multipart and not parameter.is_body_kwarg
178
- )
188
+ return self.get_from_predicate(lambda parameter: parameter.is_multipart)
179
189
 
180
190
  @property
181
191
  def data_inputs(self) -> List[Parameter]:
182
- return self.get_from_predicate(
183
- lambda parameter: parameter.is_data_input and not parameter.is_body_kwarg
184
- )
192
+ return self.get_from_predicate(lambda parameter: parameter.is_data_input)
185
193
 
186
194
  def _filter_out_multiple_content_type(self, kwarg_params):
187
195
  """We don't want multiple content type kwargs in the method signature"""
188
- content_type_params = [k for k in kwarg_params if k.rest_api_name == "Content-Type"]
196
+ content_type_params = [
197
+ k for k in kwarg_params if k.rest_api_name == "Content-Type"
198
+ ]
189
199
  if len(content_type_params) > 1:
190
200
  # we don't want multiple content type params in the method, just one
191
201
  # we'll pick the one with the default content type
192
- kwarg_params = [
193
- k for k in kwarg_params
194
- if not (
195
- k.rest_api_name == "Content-Type"
196
- and k.default_value_declaration != f'"{self.default_content_type}"'
197
- )
198
- ]
202
+ seen_content_type = False
203
+ new_kwarg_params = []
204
+ for k in kwarg_params:
205
+ if k.rest_api_name == "Content-Type":
206
+ if (
207
+ not seen_content_type
208
+ and k.default_value_declaration
209
+ == f'"{self.default_content_type}"'
210
+ ):
211
+ new_kwarg_params.append(k)
212
+ seen_content_type = True
213
+ else:
214
+ continue
215
+ else:
216
+ new_kwarg_params.append(k)
217
+ kwarg_params = new_kwarg_params
199
218
  return kwarg_params
200
219
 
201
220
  @property
202
221
  def method(self) -> List[Parameter]:
203
- """The list of parameter used in method signature.
204
- """
222
+ """The list of parameter used in method signature."""
205
223
  # Client level should not be on Method, etc.
206
224
  parameters_of_this_implementation = self.get_from_predicate(
207
225
  lambda parameter: parameter.implementation == self.implementation
226
+ and parameter.in_method_signature
208
227
  )
209
- positional = [p for p in parameters_of_this_implementation if p.is_positional]
228
+ positional = [
229
+ p
230
+ for p in parameters_of_this_implementation
231
+ if p.method_location == ParameterMethodLocation.POSITIONAL
232
+ ]
210
233
  keyword_only = self._filter_out_multiple_content_type(
211
- [p for p in parameters_of_this_implementation if p.is_keyword_only]
234
+ [
235
+ p
236
+ for p in parameters_of_this_implementation
237
+ if p.method_location == ParameterMethodLocation.KEYWORD_ONLY
238
+ ]
212
239
  )
213
240
  kwargs = self._filter_out_multiple_content_type(
214
- [p for p in parameters_of_this_implementation if p.is_kwarg]
241
+ [
242
+ p
243
+ for p in parameters_of_this_implementation
244
+ if p.method_location
245
+ in (ParameterMethodLocation.KWARG, ParameterMethodLocation.HIDDEN_KWARG)
246
+ ]
215
247
  )
248
+
216
249
  def _sort(params):
217
- return sorted(params, key=lambda x: not x.default_value and x.required, reverse=True)
218
- signature_parameters = (
219
- _sort(positional) + _sort(keyword_only) + _sort(kwargs)
220
- )
221
- return signature_parameters
250
+ return sorted(
251
+ params, key=lambda x: not x.default_value and x.required, reverse=True
252
+ )
222
253
 
254
+ signature_parameters = _sort(positional) + _sort(keyword_only) + _sort(kwargs)
255
+ return signature_parameters
223
256
 
224
257
  def method_signature(self, is_python3_file: bool) -> List[str]:
225
258
  return _method_signature_helper(
226
259
  positional=self.method_signature_positional(is_python3_file),
227
260
  keyword_only=self.method_signature_keyword_only(is_python3_file),
228
- kwarg_params=self.method_signature_kwargs(is_python3_file)
261
+ kwarg_params=self.method_signature_kwargs(is_python3_file),
229
262
  )
230
263
 
231
264
  def method_signature_positional(self, is_python3_file: bool) -> List[str]:
232
- return [parameter.method_signature(is_python3_file) for parameter in self.positional]
265
+ return [
266
+ parameter.method_signature(is_python3_file) for parameter in self.positional
267
+ ]
233
268
 
234
269
  def method_signature_keyword_only(self, is_python3_file: bool) -> List[str]:
235
270
  if not (self.keyword_only and is_python3_file):
236
271
  return []
237
- return ["*,"] + [parameter.method_signature(is_python3_file) for parameter in self.keyword_only]
272
+ return ["*,"] + [
273
+ parameter.method_signature(is_python3_file)
274
+ for parameter in self.keyword_only
275
+ ]
238
276
 
239
277
  @staticmethod
240
278
  def method_signature_kwargs(is_python3_file: bool) -> List[str]:
@@ -242,15 +280,28 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
242
280
 
243
281
  @property
244
282
  def positional(self) -> List[Parameter]:
245
- return [p for p in self.method if p.is_positional]
283
+ return [
284
+ p
285
+ for p in self.method
286
+ if p.method_location == ParameterMethodLocation.POSITIONAL
287
+ ]
246
288
 
247
289
  @property
248
290
  def keyword_only(self) -> List[Parameter]:
249
- return [p for p in self.method if p.is_keyword_only]
291
+ return [
292
+ p
293
+ for p in self.method
294
+ if p.method_location == ParameterMethodLocation.KEYWORD_ONLY
295
+ ]
250
296
 
251
297
  @property
252
298
  def kwargs(self) -> List[Parameter]:
253
- return [p for p in self.method if p.is_kwarg]
299
+ return [
300
+ p
301
+ for p in self.method
302
+ if p.method_location
303
+ in (ParameterMethodLocation.KWARG, ParameterMethodLocation.HIDDEN_KWARG)
304
+ ]
254
305
 
255
306
  def kwargs_to_pop(self, is_python3_file: bool) -> List[Parameter]:
256
307
  kwargs_to_pop = self.kwargs
@@ -258,118 +309,65 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
258
309
  kwargs_to_pop += self.keyword_only
259
310
  return kwargs_to_pop
260
311
 
261
- @property
262
- def call(self) -> List[str]:
263
- retval = [
264
- p.serialized_name for p in self.positional
265
- ]
266
- retval.extend([
267
- f"{p.serialized_name}={p.serialized_name}"
268
- for p in self.keyword_only
269
- ])
312
+ def call(self, is_python3_file: bool) -> List[str]:
313
+ retval = [p.serialized_name for p in self.positional]
314
+ if is_python3_file:
315
+ retval.extend(
316
+ [f"{p.serialized_name}={p.serialized_name}" for p in self.keyword_only]
317
+ )
270
318
  retval.append("**kwargs")
271
319
  return retval
272
320
 
273
321
  @property
274
322
  def is_flattened(self) -> bool:
275
- return cast(bool, self.get_from_predicate(lambda parameter: parameter.flattened))
276
-
277
- def _create_files_or_data_param(
278
- params: List[Parameter], serialized_name: str, description: str
279
- ) -> Parameter:
280
- params[0].need_import = False
281
- param = copy(params[0])
282
- param.serialized_name = serialized_name
283
- param.schema = DictionarySchema(
284
- namespace="",
285
- yaml_data={},
286
- element_type=AnySchema(namespace="", yaml_data={}),
287
- )
288
- param.description = description
289
- return param
290
-
291
- class ParameterOnlyPathAndBodyPositionalList(ParameterList):
292
- # use this to change the files and data parameter in the method
293
-
294
- @property
295
- def method(self) -> List[Parameter]:
296
- method_params = super().method
297
- files_params = [p for p in method_params if p.is_multipart]
298
- data_params = [p for p in method_params if p.is_data_input]
299
- if not (files_params or data_params):
300
- return method_params
301
-
302
- # update files param
303
- file_and_data_params = []
304
- if files_params:
305
- files_param = _create_files_or_data_param(
306
- files_params,
307
- serialized_name="files",
308
- description="Multipart input for files. See the template in our example to find the input shape."
309
- )
310
- file_and_data_params.append(files_param)
311
- if data_params:
312
- data_param = _create_files_or_data_param(
313
- data_params,
314
- serialized_name="data",
315
- description="Form-encoded input for data. See the template in our example to find the input shape."
316
- )
317
- file_and_data_params.append(data_param)
318
- method_params = [p for p in method_params if not p.is_multipart and not p.is_data_input]
319
- positional = [p for p in method_params if p.is_positional]
320
- keyword_only = self._filter_out_multiple_content_type(
321
- [p for p in method_params if p.is_keyword_only]
322
- )
323
- kwargs = self._filter_out_multiple_content_type(
324
- [p for p in method_params if p.is_kwarg]
323
+ return cast(
324
+ bool, self.get_from_predicate(lambda parameter: parameter.flattened)
325
325
  )
326
- return positional + file_and_data_params + keyword_only + kwargs
327
326
 
328
- def get_parameter_list(code_model):
329
- if code_model.options["only_path_and_body_params_positional"]:
330
- return ParameterOnlyPathAndBodyPositionalList
331
- return ParameterList
332
327
 
333
328
  class GlobalParameterList(ParameterList):
334
-
335
329
  @property
336
330
  def implementation(self) -> str:
337
331
  return "Client"
338
332
 
339
333
  @property
340
334
  def method(self) -> List[Parameter]:
341
- """The list of parameter used in method signature.
342
- """
335
+ """The list of parameter used in method signature."""
343
336
  # Client level should not be on Method, etc.
344
- positional = [p for p in self.parameters if p.is_positional]
337
+ positional = [
338
+ p
339
+ for p in self.parameters
340
+ if p.method_location == ParameterMethodLocation.POSITIONAL
341
+ ]
345
342
  keyword_only = self._filter_out_multiple_content_type(
346
- [p for p in self.parameters if p.is_keyword_only]
343
+ [
344
+ p
345
+ for p in self.parameters
346
+ if p.method_location == ParameterMethodLocation.KEYWORD_ONLY
347
+ ]
347
348
  )
348
349
  kwargs = self._filter_out_multiple_content_type(
349
- [p for p in self.parameters if p.is_kwarg]
350
- )
351
- def _sort(params):
352
- return sorted(params, key=lambda x: not x.default_value and x.required, reverse=True)
353
- signature_parameters = (
354
- _sort(positional) + _sort(keyword_only) + _sort(kwargs)
350
+ [
351
+ p
352
+ for p in self.parameters
353
+ if p.method_location
354
+ in (ParameterMethodLocation.KWARG, ParameterMethodLocation.HIDDEN_KWARG)
355
+ ]
355
356
  )
356
- return signature_parameters
357
357
 
358
- @property
359
- def code_model(self):
360
- try:
361
- return self._code_model
362
- except AttributeError:
363
- raise ValueError("You need to first set the code model")
358
+ def _sort(params):
359
+ return sorted(
360
+ params, key=lambda x: not x.default_value and x.required, reverse=True
361
+ )
364
362
 
365
- @code_model.setter
366
- def code_model(self, val):
367
- self._code_model = val
363
+ signature_parameters = _sort(positional) + _sort(keyword_only) + _sort(kwargs)
364
+ return signature_parameters
368
365
 
369
366
  @property
370
367
  def host_variable_name(self) -> str:
371
368
  return (
372
- "endpoint" if self.code_model.options["version_tolerant"]
369
+ "endpoint"
370
+ if self.code_model.options["version_tolerant"]
373
371
  or self.code_model.options["low_level_client"]
374
372
  else "base_url"
375
373
  )
@@ -377,17 +375,17 @@ class GlobalParameterList(ParameterList):
377
375
  @staticmethod
378
376
  def _wanted_path_parameter(parameter: Parameter) -> bool:
379
377
  return (
380
- parameter.location == ParameterLocation.Uri and
381
- parameter.implementation == "Client" and
382
- parameter.rest_api_name != "$host"
378
+ parameter.location == ParameterLocation.Uri
379
+ and parameter.implementation == "Client"
380
+ and parameter.rest_api_name != "$host"
383
381
  )
384
382
 
385
383
  def add_host(self, host_value: Optional[str]) -> None:
386
384
  # only adds if we don't have a parameterized host
387
385
  host_param = Parameter(
388
- self.code_model,
389
386
  yaml_data={},
390
- schema=StringSchema(namespace="", yaml_data={"type": "str"}),
387
+ code_model=self.code_model,
388
+ schema=StringSchema(yaml_data={"type": "str"}, code_model=self.code_model),
391
389
  rest_api_name=self.host_variable_name,
392
390
  serialized_name=self.host_variable_name,
393
391
  description=f"Service URL.",
@@ -397,15 +395,19 @@ class GlobalParameterList(ParameterList):
397
395
  skip_url_encoding=False,
398
396
  constraints=[],
399
397
  client_default_value=host_value,
400
- keyword_only=self.code_model.options["version_tolerant"] or self.code_model.options["low_level_client"],
401
398
  )
399
+ if (
400
+ self.code_model.options["version_tolerant"]
401
+ or self.code_model.options["low_level_client"]
402
+ ):
403
+ host_param.method_location = ParameterMethodLocation.KEYWORD_ONLY
402
404
  self.parameters.append(host_param)
403
405
 
404
406
  def add_credential_global_parameter(self) -> None:
405
407
  credential_parameter = Parameter(
406
- self.code_model,
407
408
  yaml_data={},
408
- schema=self.code_model.credential_schema_policy.credential,
409
+ code_model=self.code_model,
410
+ schema=self.code_model.credential_model.credential_schema_policy.credential,
409
411
  serialized_name="credential",
410
412
  rest_api_name="credential",
411
413
  implementation="Client",
@@ -415,7 +417,10 @@ class GlobalParameterList(ParameterList):
415
417
  skip_url_encoding=True,
416
418
  constraints=[],
417
419
  )
418
- if self.code_model.options["version_tolerant"] or self.code_model.options["low_level_client"]:
420
+ if (
421
+ self.code_model.options["version_tolerant"]
422
+ or self.code_model.options["low_level_client"]
423
+ ):
419
424
  self.parameters.append(credential_parameter)
420
425
  else:
421
426
  self.parameters.insert(0, credential_parameter)
@@ -423,7 +428,11 @@ class GlobalParameterList(ParameterList):
423
428
  @property
424
429
  def host(self) -> Optional[Parameter]:
425
430
  try:
426
- return next(p for p in self.parameters if p.serialized_name == self.host_variable_name)
431
+ return next(
432
+ p
433
+ for p in self.parameters
434
+ if p.serialized_name == self.host_variable_name
435
+ )
427
436
  except StopIteration:
428
437
  return None
429
438
 
@@ -432,8 +441,7 @@ class GlobalParameterList(ParameterList):
432
441
  if self.code_model.service_client.has_parameterized_host:
433
442
  return None
434
443
  return next(
435
- p for p in self.parameters
436
- if p.serialized_name == self.host_variable_name
444
+ p for p in self.parameters if p.serialized_name == self.host_variable_name
437
445
  ).default_value_declaration
438
446
 
439
447
  @property
@@ -447,17 +455,24 @@ class GlobalParameterList(ParameterList):
447
455
 
448
456
  def kwargs_to_pop(self, is_python3_file: bool) -> List[Parameter]:
449
457
  return [
450
- k for k in super().kwargs_to_pop(is_python3_file)
458
+ k
459
+ for k in super().kwargs_to_pop(is_python3_file)
451
460
  if not self._param_is_in_config_method(k.serialized_name)
452
461
  ]
453
462
 
454
463
  def config_kwargs_to_pop(self, is_python3_file: bool) -> List[Parameter]:
455
464
  current_kwargs_to_pop = super().kwargs_to_pop(is_python3_file)
456
- return [k for k in current_kwargs_to_pop if self._param_is_in_config_method(k.serialized_name)]
465
+ return [
466
+ k
467
+ for k in current_kwargs_to_pop
468
+ if self._param_is_in_config_method(k.serialized_name)
469
+ ]
457
470
 
458
471
  @property
459
472
  def config_method(self) -> List[Parameter]:
460
- return [p for p in self.method if self._param_is_in_config_method(p.serialized_name)]
473
+ return [
474
+ p for p in self.method if self._param_is_in_config_method(p.serialized_name)
475
+ ]
461
476
 
462
477
  def client_method_signature(self, is_python3_file: bool) -> List[str]:
463
478
  return self.method_signature(is_python3_file)
@@ -469,17 +484,23 @@ class GlobalParameterList(ParameterList):
469
484
  for p in self.positional
470
485
  if self._param_is_in_config_method(p.serialized_name)
471
486
  ]
472
- keyword_only_params = [p for p in self.keyword_only if self._param_is_in_config_method(p.serialized_name)]
487
+ keyword_only_params = [
488
+ p
489
+ for p in self.keyword_only
490
+ if self._param_is_in_config_method(p.serialized_name)
491
+ ]
473
492
  keyword_only_method_signature = []
474
493
  if is_python3_file:
475
494
  keyword_only_method_signature = (
476
- ["*,"] +
477
- [
478
- p.method_signature(is_python3_file) for p in keyword_only_params
479
- ]
480
- ) if keyword_only_params else []
495
+ (
496
+ ["*,"]
497
+ + [p.method_signature(is_python3_file) for p in keyword_only_params]
498
+ )
499
+ if keyword_only_params
500
+ else []
501
+ )
481
502
  return _method_signature_helper(
482
503
  positional=positional,
483
504
  keyword_only=keyword_only_method_signature,
484
- kwarg_params=self.method_signature_kwargs(is_python3_file)
505
+ kwarg_params=self.method_signature_kwargs(is_python3_file),
485
506
  )