@autorest/python 6.7.0 → 6.7.2

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.
@@ -6,7 +6,6 @@
6
6
  import sys
7
7
  import logging
8
8
  import json
9
- import shutil
10
9
 
11
10
  from collections import defaultdict
12
11
  from pathlib import Path
@@ -174,10 +173,6 @@ class MultiAPI(ReaderAndWriter): # pylint: disable=abstract-method
174
173
  user_specified_default_api=self.user_specified_default_api,
175
174
  )
176
175
 
177
- # In case we are transitioning from a single api generation, clean old folders
178
- shutil.rmtree(str(self.output_folder / "operations"), ignore_errors=True)
179
- shutil.rmtree(str(self.output_folder / "models"), ignore_errors=True)
180
-
181
176
  multiapi_serializer = self.serializer
182
177
  multiapi_serializer.serialize(code_model, self.no_async)
183
178
 
@@ -176,6 +176,37 @@ def update_paging_response(yaml_data: Dict[str, Any]) -> None:
176
176
  )
177
177
 
178
178
 
179
+ HEADERS_HIDE_IN_METHOD = (
180
+ "repeatability-request-id",
181
+ "repeatability-first-sent",
182
+ "x-ms-client-request-id",
183
+ "client-request-id",
184
+ "return-client-request-id",
185
+ )
186
+ HEADERS_CONVERT_IN_METHOD = {
187
+ "if-match": {
188
+ "clientName": "etag",
189
+ "wireName": "etag",
190
+ "description": "check if resource is changed. Set None to skip checking etag.",
191
+ },
192
+ "if-none-match": {
193
+ "clientName": "match_condition",
194
+ "wireName": "match-condition",
195
+ "description": "The match condition to use upon the etag.",
196
+ "type": {
197
+ "type": "azurecore",
198
+ "name": "MatchConditions",
199
+ },
200
+ },
201
+ }
202
+
203
+
204
+ def headers_convert(yaml_data: Dict[str, Any], replace_data: Any) -> None:
205
+ if isinstance(replace_data, dict):
206
+ for k, v in replace_data.items():
207
+ yaml_data[k] = v
208
+
209
+
179
210
  class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
180
211
  """Add Python naming information."""
181
212
 
@@ -242,6 +273,11 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
242
273
  )
243
274
  type["values"].extend(values_to_add)
244
275
 
276
+ # add type for reference
277
+ for v in HEADERS_CONVERT_IN_METHOD.values():
278
+ if isinstance(v, dict) and "type" in v:
279
+ yaml_data.append(v["type"])
280
+
245
281
  def update_client(self, yaml_data: Dict[str, Any]) -> None:
246
282
  yaml_data["description"] = update_description(
247
283
  yaml_data["description"], default_description=yaml_data["name"]
@@ -253,6 +289,21 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
253
289
  if prop_name.endswith("Client"):
254
290
  prop_name = prop_name[: len(prop_name) - len("Client")]
255
291
  yaml_data["builderPadName"] = to_snake_case(prop_name)
292
+ for og in yaml_data["operationGroups"]:
293
+ for o in og["operations"]:
294
+ for p in o["parameters"]:
295
+ if (
296
+ p["location"] == "header"
297
+ and p["wireName"] == "client-request-id"
298
+ ):
299
+ yaml_data["requestIdHeaderName"] = p["wireName"]
300
+ if (
301
+ self.version_tolerant
302
+ and p["location"] == "header"
303
+ and p["clientName"] in ("if_match", "if_none_match")
304
+ ):
305
+ o["hasEtag"] = True
306
+ yaml_data["hasEtag"] = True
256
307
 
257
308
  def get_operation_updater(
258
309
  self, yaml_data: Dict[str, Any]
@@ -282,6 +333,18 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
282
333
  .lower()
283
334
  for prop, param_name in yaml_data["propertyToParameterName"].items()
284
335
  }
336
+ wire_name_lower = (yaml_data.get("wireName") or "").lower()
337
+ if (
338
+ yaml_data["location"] == "header"
339
+ and wire_name_lower in HEADERS_HIDE_IN_METHOD
340
+ ):
341
+ yaml_data["hideInMethod"] = True
342
+ if (
343
+ self.version_tolerant
344
+ and yaml_data["location"] == "header"
345
+ and wire_name_lower in HEADERS_CONVERT_IN_METHOD
346
+ ):
347
+ headers_convert(yaml_data, HEADERS_CONVERT_IN_METHOD[wire_name_lower])
285
348
 
286
349
  def update_operation(
287
350
  self,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.7.0",
3
+ "version": "6.7.2",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {