@autorest/python 5.12.6 → 5.13.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.
- package/ChangeLog.md +158 -125
- package/autorest/black/__init__.py +3 -0
- package/autorest/codegen/__init__.py +12 -2
- package/autorest/codegen/models/__init__.py +2 -1
- package/autorest/codegen/models/constant_schema.py +0 -4
- package/autorest/codegen/models/operation.py +11 -4
- package/autorest/codegen/models/parameter.py +34 -9
- package/autorest/codegen/models/parameter_list.py +10 -4
- package/autorest/codegen/models/request_builder_parameter.py +5 -0
- package/autorest/codegen/serializers/__init__.py +75 -71
- package/autorest/codegen/serializers/builder_serializer.py +35 -11
- package/autorest/namer/name_converter.py +1 -1
- package/package.json +2 -2
- package/run-python3.js +1 -7
- package/venvtools.py +2 -2
package/ChangeLog.md
CHANGED
|
@@ -1,14 +1,43 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
### 2022-03-03 - 5.13.0
|
|
4
|
+
|
|
5
|
+
| Library | Min Version |
|
|
6
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
7
|
+
| `@autorest/core` | `3.6.2` |
|
|
8
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
9
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
10
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
11
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
12
|
+
|
|
13
|
+
**Breaking Changes in Version Tolerant Generation**
|
|
14
|
+
|
|
15
|
+
- We now generate with optional constant parameters as None by defaulting `--default-optional-constants-to-none` to True #1171
|
|
16
|
+
- Version tolerant paging does not reformat initial query parameters into the next link #1168
|
|
17
|
+
|
|
18
|
+
**New Features**
|
|
19
|
+
|
|
20
|
+
- Add flag `--default-optional-constants-to-none` with which optional constant parameters is default to None #1171
|
|
21
|
+
- Add flag `--reformat-next-link`, determines whether we reformat initial query parameters into the next link. Defaults to `True` for the GA generator, forced to `False` for `--version-tolerant`.
|
|
22
|
+
|
|
23
|
+
**Bug Fixes**
|
|
24
|
+
|
|
25
|
+
- Add default value consistently for parameters #1164
|
|
26
|
+
- Make `content_type` param keyword-only if there are multiple content types #1167
|
|
27
|
+
|
|
28
|
+
**Other Changes**
|
|
29
|
+
|
|
30
|
+
- Drop testing support for 2.7 packages #1175
|
|
31
|
+
|
|
3
32
|
### 2022-02-09 - 5.12.6
|
|
4
33
|
|
|
5
|
-
| Library
|
|
6
|
-
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
34
|
+
| Library | Min Version |
|
|
35
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
36
|
+
| `@autorest/core` | `3.6.2` |
|
|
37
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
38
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
39
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
40
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
12
41
|
|
|
13
42
|
**Bug Fixes**
|
|
14
43
|
|
|
@@ -18,57 +47,57 @@
|
|
|
18
47
|
|
|
19
48
|
### 2022-01-26 - 5.12.5
|
|
20
49
|
|
|
21
|
-
| Library
|
|
22
|
-
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
50
|
+
| Library | Min Version |
|
|
51
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
52
|
+
| `@autorest/core` | `3.6.2` |
|
|
53
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
54
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
55
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
56
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
28
57
|
|
|
29
58
|
**Bug Fixes**
|
|
30
59
|
|
|
31
|
-
- Fix usage of `--black` flag outside of repo
|
|
32
|
-
- Remove unused `metadata` value for `version-tolerant` generations
|
|
60
|
+
- Fix usage of `--black` flag outside of repo #1126
|
|
61
|
+
- Remove unused `metadata` value for `version-tolerant` generations #1127
|
|
33
62
|
|
|
34
63
|
### 2022-01-14 - 5.12.4
|
|
35
64
|
|
|
36
|
-
| Library
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
65
|
+
| Library | Min Version |
|
|
66
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
67
|
+
| `@autorest/core` | `3.6.2` |
|
|
68
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
69
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
70
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
71
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
43
72
|
|
|
44
73
|
**Bug Fixes**
|
|
45
74
|
|
|
46
|
-
- Remove duplicate generation of properties in classes that inherit from multiple classes
|
|
75
|
+
- Remove duplicate generation of properties in classes that inherit from multiple classes #1120
|
|
47
76
|
|
|
48
77
|
### 2022-01-13 - 5.12.3
|
|
49
78
|
|
|
50
|
-
| Library
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
| Library | Min Version |
|
|
80
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
81
|
+
| `@autorest/core` | `3.6.2` |
|
|
82
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
83
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
84
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
85
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
57
86
|
|
|
58
87
|
**Bug Fixes**
|
|
59
88
|
|
|
60
|
-
- Unify multiapi constant behavior with single API version
|
|
61
|
-
- Clean up docstrings by removing descriptions for client constants on methods and request builders
|
|
89
|
+
- Unify multiapi constant behavior with single API version #1119
|
|
90
|
+
- Clean up docstrings by removing descriptions for client constants on methods and request builders #1119
|
|
62
91
|
|
|
63
92
|
### 2022-01-11 - 5.12.2
|
|
64
93
|
|
|
65
|
-
| Library
|
|
66
|
-
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
94
|
+
| Library | Min Version |
|
|
95
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
96
|
+
| `@autorest/core` | `3.6.2` |
|
|
97
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
98
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
99
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
100
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
72
101
|
|
|
73
102
|
**Bug Fixes**
|
|
74
103
|
|
|
@@ -76,81 +105,81 @@
|
|
|
76
105
|
|
|
77
106
|
### 2022-01-10 - 5.12.1
|
|
78
107
|
|
|
79
|
-
| Library
|
|
80
|
-
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
108
|
+
| Library | Min Version |
|
|
109
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
110
|
+
| `@autorest/core` | `3.6.2` |
|
|
111
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
112
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
113
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
114
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
86
115
|
|
|
87
116
|
**Bug Fixes**
|
|
88
117
|
|
|
89
|
-
- Fix support for json merge patch
|
|
118
|
+
- Fix support for json merge patch #1117
|
|
90
119
|
|
|
91
120
|
### 2021-12-06 - 5.12.0
|
|
92
121
|
|
|
93
|
-
| Library
|
|
94
|
-
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
122
|
+
| Library | Min Version |
|
|
123
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
124
|
+
| `@autorest/core` | `3.6.2` |
|
|
125
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
126
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
127
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
128
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
100
129
|
|
|
101
130
|
**Breaking Changes in Version Tolerant Generation**
|
|
102
131
|
|
|
103
132
|
- Remove metadata property for version tolerant and low level client generations #1090
|
|
104
|
-
- Generate SDKs with `--python3-only` defaulting to `True` for version tolerant and low level client
|
|
133
|
+
- Generate SDKs with `--python3-only` defaulting to `True` for version tolerant and low level client #1087
|
|
105
134
|
|
|
106
135
|
**New Features**
|
|
107
136
|
|
|
108
|
-
- Generate a `_patch.py` file if one does not exist. These files are used to customize the generated code
|
|
137
|
+
- Generate a `_patch.py` file if one does not exist. These files are used to customize the generated code #1092
|
|
109
138
|
|
|
110
139
|
**Bug Fixes**
|
|
111
140
|
|
|
112
141
|
- Can now handle body params with names `json`, `content`, `data`, and `files` #1081
|
|
113
|
-
- Improve generated templates for `data` and `files` input body params by adding quotes around the keys
|
|
114
|
-
- Using flag `--python3-only` will get you typed sync client and config files
|
|
115
|
-
- Pin `mistune` dependency to less than `2.x.x` so autorest can be successfully installed
|
|
142
|
+
- Improve generated templates for `data` and `files` input body params by adding quotes around the keys #1082
|
|
143
|
+
- Using flag `--python3-only` will get you typed sync client and config files #1085
|
|
144
|
+
- Pin `mistune` dependency to less than `2.x.x` so autorest can be successfully installed #1106
|
|
116
145
|
|
|
117
146
|
### 2021-11-05 - 5.11.2
|
|
118
147
|
|
|
119
|
-
| Library
|
|
120
|
-
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
| Library | Min Version |
|
|
149
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
150
|
+
| `@autorest/core` | `3.6.2` |
|
|
151
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
152
|
+
| `azure-core` dep of generated code | `1.20.0` |
|
|
153
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
154
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
126
155
|
|
|
127
156
|
**Bug Fixes**
|
|
128
157
|
|
|
129
|
-
- Respect no client side validation for low level client generations
|
|
158
|
+
- Respect no client side validation for low level client generations #1080
|
|
130
159
|
|
|
131
160
|
### 2021-11-05 - 5.11.1
|
|
132
161
|
|
|
133
|
-
| Library
|
|
134
|
-
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
162
|
+
| Library | Min Version |
|
|
163
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
164
|
+
| `@autorest/core` | `3.6.2` |
|
|
165
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
166
|
+
| `azure-core` dep of generated code | `1.20.0` |
|
|
167
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
168
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
140
169
|
|
|
141
170
|
**Bug Fixes**
|
|
142
171
|
|
|
143
|
-
- Hide mixin operations for version tolerant generation
|
|
172
|
+
- Hide mixin operations for version tolerant generation #1071
|
|
144
173
|
|
|
145
174
|
### 2021-11-04 - 5.11.0
|
|
146
175
|
|
|
147
|
-
| Library
|
|
148
|
-
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
176
|
+
| Library | Min Version |
|
|
177
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
178
|
+
| `@autorest/core` | `3.6.2` |
|
|
179
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
180
|
+
| `azure-core` dep of generated code | `1.20.0` |
|
|
181
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
182
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
154
183
|
|
|
155
184
|
**New Features**
|
|
156
185
|
|
|
@@ -164,68 +193,69 @@
|
|
|
164
193
|
|
|
165
194
|
### 2021-11-01 - 5.10.0
|
|
166
195
|
|
|
167
|
-
| Library
|
|
168
|
-
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
196
|
+
| Library | Min Version |
|
|
197
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
198
|
+
| `@autorest/core` | `3.6.2` |
|
|
199
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
200
|
+
| `azure-core` dep of generated code | `1.19.1` |
|
|
201
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
202
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
174
203
|
|
|
175
204
|
**New Features**
|
|
176
205
|
|
|
177
|
-
- Allow users to override constant swagger params with kwarg input
|
|
206
|
+
- Allow users to override constant swagger params with kwarg input #1060
|
|
178
207
|
|
|
179
208
|
### 2021-10-15 - 5.9.3
|
|
180
209
|
|
|
181
|
-
| Library
|
|
182
|
-
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
210
|
+
| Library | Min Version |
|
|
211
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
212
|
+
| `@autorest/core` | `3.6.2` |
|
|
213
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
214
|
+
| `azure-core` dep of generated code | `1.19.0` |
|
|
215
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
216
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
188
217
|
|
|
189
218
|
**Bug Fixes**
|
|
190
219
|
|
|
191
|
-
- Fix generation of form-data inputs
|
|
220
|
+
- Fix generation of form-data inputs #1061
|
|
192
221
|
|
|
193
222
|
### 2021-10-05 - 5.9.2
|
|
194
223
|
|
|
195
|
-
| Library
|
|
196
|
-
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
224
|
+
| Library | Min Version |
|
|
225
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
226
|
+
| `@autorest/core` | `3.6.2` |
|
|
227
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
228
|
+
| `azure-core` dep of generated code | `1.19.0` |
|
|
229
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
230
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
202
231
|
|
|
203
232
|
**New Features**
|
|
233
|
+
|
|
204
234
|
- Updating generated code for `azure-core` release `1.19.0`.
|
|
205
235
|
|
|
206
236
|
### 2021-09-27 - 5.9.1
|
|
207
237
|
|
|
208
|
-
| Library
|
|
209
|
-
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
238
|
+
| Library | Min Version |
|
|
239
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
240
|
+
| `@autorest/core` | `3.6.2` |
|
|
241
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
242
|
+
| `azure-core` dep of generated code | `1.18.0` |
|
|
243
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
244
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
215
245
|
|
|
216
246
|
**New Features**
|
|
217
247
|
|
|
218
248
|
- We have added a **provisional** `rest` layer to our generated code. We have also added the following **provisional** flags listed [here](https://github.com/Azure/autorest.python/wiki/Generating-Low-Level-Client#generate-a-low-level-client). #875
|
|
219
|
-
- With this new release, we are also dropping support for Python 3.5 + async.
|
|
249
|
+
- With this new release, we are also dropping support for Python 3.5 + async. #875
|
|
220
250
|
- For mgmt plan SDK, default policy changes from `BearerTokenCredentialPolicy` to `ARMChallengeAuthenticationPolicy`.
|
|
221
251
|
- We now add tracing by default, the flag `--trace` now defaults to `True` if you have operations.
|
|
222
|
-
- Added flag `--python3-only` for users looking to generate SDKs that only support Python 3
|
|
252
|
+
- Added flag `--python3-only` for users looking to generate SDKs that only support Python 3 #1044
|
|
223
253
|
|
|
224
254
|
**Bug Fixes**
|
|
225
255
|
|
|
226
|
-
- Correctly pad operation groups with reserved names with `Operations`
|
|
227
|
-
- Fix the generated docstrings for input kwargs of models
|
|
228
|
-
- Pass pipeline context to `msrest` in `failsafe_deserialize` so `msrest` has access to the context
|
|
256
|
+
- Correctly pad operation groups with reserved names with `Operations` #1005
|
|
257
|
+
- Fix the generated docstrings for input kwargs of models #1026
|
|
258
|
+
- Pass pipeline context to `msrest` in `failsafe_deserialize` so `msrest` has access to the context #1030
|
|
229
259
|
|
|
230
260
|
### 2021-09-27 - 5.9.0
|
|
231
261
|
|
|
@@ -260,7 +290,7 @@ min Modelerfour version: 4.19.1
|
|
|
260
290
|
|
|
261
291
|
**Bug Fixes**
|
|
262
292
|
|
|
263
|
-
- We are now more lenient with our checks for the content type parameter
|
|
293
|
+
- We are now more lenient with our checks for the content type parameter #956
|
|
264
294
|
|
|
265
295
|
### 2021-06-16 - 5.8.1
|
|
266
296
|
|
|
@@ -271,7 +301,7 @@ min Modelerfour version: 4.19.1
|
|
|
271
301
|
**Bug Fixes**
|
|
272
302
|
|
|
273
303
|
- Fix optional properties with constant schemas. Now, properties that have constant schemas but are optional will not have the hardcoded constant value,
|
|
274
|
-
but will default to its `x-ms-client-default` or `None`
|
|
304
|
+
but will default to its `x-ms-client-default` or `None` #952
|
|
275
305
|
|
|
276
306
|
### 2021-05-17 - 5.8.0
|
|
277
307
|
|
|
@@ -281,7 +311,7 @@ min Modelerfour version: 4.19.1
|
|
|
281
311
|
|
|
282
312
|
**New Features**
|
|
283
313
|
|
|
284
|
-
- Add support for parameters and properties that can be of type "Anything".
|
|
314
|
+
- Add support for parameters and properties that can be of type "Anything". #946
|
|
285
315
|
|
|
286
316
|
### 2021-04-20 - 5.7.0
|
|
287
317
|
|
|
@@ -301,7 +331,7 @@ min Modelerfour version: 4.15.456
|
|
|
301
331
|
|
|
302
332
|
**Bug Fixes**
|
|
303
333
|
|
|
304
|
-
- Fix docstrings so they don't get split on hyphens
|
|
334
|
+
- Fix docstrings so they don't get split on hyphens #931
|
|
305
335
|
|
|
306
336
|
### 2021-04-07 - 5.6.5
|
|
307
337
|
|
|
@@ -311,7 +341,7 @@ min Modelerfour version: 4.15.456
|
|
|
311
341
|
|
|
312
342
|
**Bug Fixes**
|
|
313
343
|
|
|
314
|
-
- Fix regression in multiapi generation for multiapi versions without mixin operations
|
|
344
|
+
- Fix regression in multiapi generation for multiapi versions without mixin operations #928
|
|
315
345
|
|
|
316
346
|
### 2021-03-01 - 5.6.4
|
|
317
347
|
|
|
@@ -320,6 +350,7 @@ min Autorest core version: 3.1.0
|
|
|
320
350
|
min Modelerfour version: 4.15.456
|
|
321
351
|
|
|
322
352
|
**Bug Fixes**
|
|
353
|
+
|
|
323
354
|
- Bump `Autorest core` minimum version to be able to deal with indented `python` blocks in config files
|
|
324
355
|
|
|
325
356
|
### 2021-02-10 - 5.6.3
|
|
@@ -329,7 +360,8 @@ min Autorest core version: 3.0.6372
|
|
|
329
360
|
min Modelerfour version: 4.15.456
|
|
330
361
|
|
|
331
362
|
**Bug Fixes**
|
|
332
|
-
|
|
363
|
+
|
|
364
|
+
- Bump `Autorest core` minimum version to [correctly deal with](https://github.com/Azure/autorest/pull/3860) overriding configs. Fixes submodule-specific code in our multiapi client #880
|
|
333
365
|
|
|
334
366
|
### 2021-02-04 - 5.6.2
|
|
335
367
|
|
|
@@ -338,7 +370,8 @@ Autorest core version: 3.0.6318
|
|
|
338
370
|
Modelerfour version: 4.15.456
|
|
339
371
|
|
|
340
372
|
**Bug Fixes**
|
|
341
|
-
|
|
373
|
+
|
|
374
|
+
- Bump `Modelerfour` minimum version to [correctly deal with](https://github.com/Azure/autorest.modelerfour/pull/385) parameters specified as `'required': false` in swagger #877
|
|
342
375
|
|
|
343
376
|
### 2021-01-27 - 5.6.1
|
|
344
377
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
import logging
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
import os
|
|
8
9
|
import black
|
|
9
10
|
|
|
10
11
|
from .. import Plugin
|
|
@@ -21,6 +22,8 @@ class BlackScriptPlugin(Plugin):
|
|
|
21
22
|
output_folder_uri = self._autorestapi.get_value("outputFolderUri")
|
|
22
23
|
if output_folder_uri.startswith("file:"):
|
|
23
24
|
output_folder_uri = output_folder_uri[5:]
|
|
25
|
+
if os.name == 'nt' and output_folder_uri.startswith("///"):
|
|
26
|
+
output_folder_uri = output_folder_uri[3:]
|
|
24
27
|
self.output_folder = Path(output_folder_uri)
|
|
25
28
|
|
|
26
29
|
def process(self) -> bool:
|
|
@@ -76,6 +76,12 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
|
76
76
|
"If you want operation files, pass in flag --show-operations"
|
|
77
77
|
)
|
|
78
78
|
|
|
79
|
+
if options["reformat_next_link"] and options["version_tolerant"]:
|
|
80
|
+
raise ValueError(
|
|
81
|
+
"--reformat-next-link can not be true for version tolerant generations. "
|
|
82
|
+
"Please remove --reformat-next-link from your call for version tolerant generations."
|
|
83
|
+
)
|
|
84
|
+
|
|
79
85
|
_LOGGER = logging.getLogger(__name__)
|
|
80
86
|
class CodeGenerator(Plugin):
|
|
81
87
|
@staticmethod
|
|
@@ -289,6 +295,10 @@ class CodeGenerator(Plugin):
|
|
|
289
295
|
"low_level_client": low_level_client,
|
|
290
296
|
"combine_operation_files": self._autorestapi.get_boolean_value("combine-operation-files", version_tolerant),
|
|
291
297
|
"python3_only": python3_only,
|
|
298
|
+
"default_optional_constants_to_none": self._autorestapi.get_boolean_value(
|
|
299
|
+
"default-optional-constants-to-none", low_level_client or version_tolerant
|
|
300
|
+
),
|
|
301
|
+
"reformat_next_link": self._autorestapi.get_boolean_value("reformat-next-link", not version_tolerant)
|
|
292
302
|
}
|
|
293
303
|
|
|
294
304
|
if options["builders_visibility"] is None:
|
|
@@ -327,8 +337,8 @@ class CodeGenerator(Plugin):
|
|
|
327
337
|
|
|
328
338
|
code_model = self._create_code_model(yaml_data=yaml_data, options=options)
|
|
329
339
|
|
|
330
|
-
serializer = JinjaSerializer(self._autorestapi)
|
|
331
|
-
serializer.serialize(
|
|
340
|
+
serializer = JinjaSerializer(self._autorestapi, code_model)
|
|
341
|
+
serializer.serialize()
|
|
332
342
|
|
|
333
343
|
return True
|
|
334
344
|
|
|
@@ -17,7 +17,7 @@ from .constant_schema import ConstantSchema
|
|
|
17
17
|
from .imports import FileImport, ImportType, TypingSection
|
|
18
18
|
from .lro_operation import LROOperation
|
|
19
19
|
from .paging_operation import PagingOperation
|
|
20
|
-
from .parameter import Parameter, ParameterStyle
|
|
20
|
+
from .parameter import Parameter, ParameterStyle, ParameterLocation
|
|
21
21
|
from .operation import Operation
|
|
22
22
|
from .property import Property
|
|
23
23
|
from .operation_group import OperationGroup
|
|
@@ -50,6 +50,7 @@ __all__ = [
|
|
|
50
50
|
"PagingOperation",
|
|
51
51
|
"Parameter",
|
|
52
52
|
"ParameterList",
|
|
53
|
+
"ParameterLocation",
|
|
53
54
|
"OperationGroup",
|
|
54
55
|
"Property",
|
|
55
56
|
"RequestBuilder",
|
|
@@ -39,10 +39,6 @@ class ConstantSchema(BaseSchema):
|
|
|
39
39
|
return "None"
|
|
40
40
|
return self.schema.get_declaration(self.value)
|
|
41
41
|
|
|
42
|
-
@property
|
|
43
|
-
def extra_description_information(self) -> str:
|
|
44
|
-
return f"The default value is {self.get_declaration(self.value)}."
|
|
45
|
-
|
|
46
42
|
@property
|
|
47
43
|
def serialization_type(self) -> str:
|
|
48
44
|
"""Returns the serialization value for msrest.
|
|
@@ -303,6 +303,15 @@ class Operation(BaseBuilder): # pylint: disable=too-many-public-methods, too-ma
|
|
|
303
303
|
parameters, multiple_content_type_parameters = create_parameters(
|
|
304
304
|
yaml_data, code_model, parameter_creator
|
|
305
305
|
)
|
|
306
|
+
parameter_list = parameter_list_creator(code_model, parameters, schema_requests)
|
|
307
|
+
multiple_content_type_parameter_list = parameter_list_creator(
|
|
308
|
+
code_model, multiple_content_type_parameters, schema_requests
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
if len(parameter_list.content_types) > 1:
|
|
312
|
+
for p in parameter_list.parameters:
|
|
313
|
+
if p.rest_api_name == "Content-Type":
|
|
314
|
+
p.is_keyword_only = True
|
|
306
315
|
|
|
307
316
|
return cls(
|
|
308
317
|
code_model=code_model,
|
|
@@ -310,10 +319,8 @@ class Operation(BaseBuilder): # pylint: disable=too-many-public-methods, too-ma
|
|
|
310
319
|
name=name,
|
|
311
320
|
description=yaml_data["language"]["python"]["description"],
|
|
312
321
|
api_versions=set(value_dict["version"] for value_dict in yaml_data["apiVersions"]),
|
|
313
|
-
parameters=
|
|
314
|
-
multiple_content_type_parameters=
|
|
315
|
-
code_model, multiple_content_type_parameters, schema_requests
|
|
316
|
-
),
|
|
322
|
+
parameters=parameter_list,
|
|
323
|
+
multiple_content_type_parameters=multiple_content_type_parameter_list,
|
|
317
324
|
schema_requests=schema_requests,
|
|
318
325
|
summary=yaml_data["language"]["python"].get("summary"),
|
|
319
326
|
responses=[SchemaResponse.from_yaml(yaml) for yaml in yaml_data.get("responses", [])],
|
|
@@ -68,7 +68,7 @@ class Parameter(BaseModel): # pylint: disable=too-many-instance-attributes, too
|
|
|
68
68
|
grouped_by: Optional["Parameter"] = None,
|
|
69
69
|
original_parameter: Optional["Parameter"] = None,
|
|
70
70
|
client_default_value: Optional[Any] = None,
|
|
71
|
-
keyword_only: bool =
|
|
71
|
+
keyword_only: Optional[bool] = None,
|
|
72
72
|
content_types: Optional[List[str]] = None,
|
|
73
73
|
) -> None:
|
|
74
74
|
super().__init__(yaml_data)
|
|
@@ -99,6 +99,7 @@ class Parameter(BaseModel): # pylint: disable=too-many-instance-attributes, too
|
|
|
99
99
|
self.body_kwargs: List[Parameter] = []
|
|
100
100
|
self.is_body_kwarg = False
|
|
101
101
|
self.need_import = True
|
|
102
|
+
self.is_kwarg = (self.rest_api_name == "Content-Type" or (self.constant and self.rest_api_name != "Accept"))
|
|
102
103
|
|
|
103
104
|
def __hash__(self) -> int:
|
|
104
105
|
return hash(self.serialized_name)
|
|
@@ -111,6 +112,14 @@ class Parameter(BaseModel): # pylint: disable=too-many-instance-attributes, too
|
|
|
111
112
|
if description:
|
|
112
113
|
description += " "
|
|
113
114
|
description += f"{self.schema.extra_description_information}"
|
|
115
|
+
if isinstance(self.schema, ConstantSchema) and not self.constant:
|
|
116
|
+
if description:
|
|
117
|
+
description += " "
|
|
118
|
+
description += f"Possible values are {self.schema.get_declaration(self.schema.value)} or {None}."
|
|
119
|
+
if self.has_default_value and not any(
|
|
120
|
+
l for l in ["default value is", "default is"] if l in description.lower()
|
|
121
|
+
):
|
|
122
|
+
description += f" Default value is {self.default_value_declaration}."
|
|
114
123
|
if self.constant:
|
|
115
124
|
description += " Note that overriding this default value may result in unsupported behavior."
|
|
116
125
|
return description
|
|
@@ -232,7 +241,12 @@ class Parameter(BaseModel): # pylint: disable=too-many-instance-attributes, too
|
|
|
232
241
|
default_value_declaration = "None"
|
|
233
242
|
else:
|
|
234
243
|
if isinstance(self.schema, ConstantSchema):
|
|
235
|
-
|
|
244
|
+
if (self.required or
|
|
245
|
+
self.is_content_type or
|
|
246
|
+
not self.code_model.options["default_optional_constants_to_none"]):
|
|
247
|
+
default_value = self.schema.get_declaration(self.schema.value)
|
|
248
|
+
else:
|
|
249
|
+
default_value = None
|
|
236
250
|
default_value_declaration = default_value
|
|
237
251
|
else:
|
|
238
252
|
default_value = self.schema.default_value
|
|
@@ -298,22 +312,26 @@ class Parameter(BaseModel): # pylint: disable=too-many-instance-attributes, too
|
|
|
298
312
|
origin_name = f"self._config.{self.serialized_name}"
|
|
299
313
|
return origin_name
|
|
300
314
|
|
|
301
|
-
@property
|
|
302
|
-
def is_kwarg(self) -> bool:
|
|
303
|
-
# this means "am I in **kwargs?"
|
|
304
|
-
return self.rest_api_name == "Content-Type" or (self.constant and self.rest_api_name != "Accept")
|
|
305
|
-
|
|
306
315
|
@property
|
|
307
316
|
def is_keyword_only(self) -> bool:
|
|
308
317
|
# this means in async mode, I am documented like def hello(positional_1, *, me!)
|
|
309
|
-
return self._keyword_only
|
|
318
|
+
return self._keyword_only or False
|
|
319
|
+
|
|
320
|
+
@is_keyword_only.setter
|
|
321
|
+
def is_keyword_only(self, val: bool) -> None:
|
|
322
|
+
self._keyword_only = val
|
|
323
|
+
self.is_kwarg = False
|
|
310
324
|
|
|
311
325
|
@property
|
|
312
326
|
def is_hidden(self) -> bool:
|
|
313
|
-
return self.serialized_name in _HIDDEN_KWARGS or (
|
|
327
|
+
return self.serialized_name in _HIDDEN_KWARGS and self.is_kwarg or (
|
|
314
328
|
self.yaml_data["implementation"] == "Client" and self.constant
|
|
315
329
|
)
|
|
316
330
|
|
|
331
|
+
@property
|
|
332
|
+
def is_content_type(self) -> bool:
|
|
333
|
+
return self.rest_api_name == "Content-Type" and self.location == ParameterLocation.Header
|
|
334
|
+
|
|
317
335
|
@property
|
|
318
336
|
def is_positional(self) -> bool:
|
|
319
337
|
return self.in_method_signature and not (self.is_keyword_only or self.is_kwarg)
|
|
@@ -365,6 +383,8 @@ class ParameterOnlyPathAndBodyPositional(Parameter):
|
|
|
365
383
|
|
|
366
384
|
@property
|
|
367
385
|
def is_keyword_only(self) -> bool:
|
|
386
|
+
if self._keyword_only is not None:
|
|
387
|
+
return self._keyword_only
|
|
368
388
|
return self.in_method_signature and not (
|
|
369
389
|
self.is_hidden or
|
|
370
390
|
self.location == ParameterLocation.Path or
|
|
@@ -373,6 +393,11 @@ class ParameterOnlyPathAndBodyPositional(Parameter):
|
|
|
373
393
|
self.is_kwarg
|
|
374
394
|
)
|
|
375
395
|
|
|
396
|
+
@is_keyword_only.setter
|
|
397
|
+
def is_keyword_only(self, val: bool) -> None:
|
|
398
|
+
self._keyword_only = val
|
|
399
|
+
self.is_kwarg = False
|
|
400
|
+
|
|
376
401
|
def get_parameter(code_model):
|
|
377
402
|
if code_model.options["only_path_and_body_params_positional"]:
|
|
378
403
|
return ParameterOnlyPathAndBodyPositional
|
|
@@ -207,7 +207,9 @@ class ParameterList(MutableSequence): # pylint: disable=too-many-public-methods
|
|
|
207
207
|
lambda parameter: parameter.implementation == self.implementation
|
|
208
208
|
)
|
|
209
209
|
positional = [p for p in parameters_of_this_implementation if p.is_positional]
|
|
210
|
-
keyword_only =
|
|
210
|
+
keyword_only = self._filter_out_multiple_content_type(
|
|
211
|
+
[p for p in parameters_of_this_implementation if p.is_keyword_only]
|
|
212
|
+
)
|
|
211
213
|
kwargs = self._filter_out_multiple_content_type(
|
|
212
214
|
[p for p in parameters_of_this_implementation if p.is_kwarg]
|
|
213
215
|
)
|
|
@@ -315,7 +317,9 @@ class ParameterOnlyPathAndBodyPositionalList(ParameterList):
|
|
|
315
317
|
file_and_data_params.append(data_param)
|
|
316
318
|
method_params = [p for p in method_params if not p.is_multipart and not p.is_data_input]
|
|
317
319
|
positional = [p for p in method_params if p.is_positional]
|
|
318
|
-
keyword_only =
|
|
320
|
+
keyword_only = self._filter_out_multiple_content_type(
|
|
321
|
+
[p for p in method_params if p.is_keyword_only]
|
|
322
|
+
)
|
|
319
323
|
kwargs = self._filter_out_multiple_content_type(
|
|
320
324
|
[p for p in method_params if p.is_kwarg]
|
|
321
325
|
)
|
|
@@ -338,7 +342,9 @@ class GlobalParameterList(ParameterList):
|
|
|
338
342
|
"""
|
|
339
343
|
# Client level should not be on Method, etc.
|
|
340
344
|
positional = [p for p in self.parameters if p.is_positional]
|
|
341
|
-
keyword_only =
|
|
345
|
+
keyword_only = self._filter_out_multiple_content_type(
|
|
346
|
+
[p for p in self.parameters if p.is_keyword_only]
|
|
347
|
+
)
|
|
342
348
|
kwargs = self._filter_out_multiple_content_type(
|
|
343
349
|
[p for p in self.parameters if p.is_kwarg]
|
|
344
350
|
)
|
|
@@ -384,7 +390,7 @@ class GlobalParameterList(ParameterList):
|
|
|
384
390
|
schema=StringSchema(namespace="", yaml_data={"type": "str"}),
|
|
385
391
|
rest_api_name=self.host_variable_name,
|
|
386
392
|
serialized_name=self.host_variable_name,
|
|
387
|
-
description=f"Service URL.
|
|
393
|
+
description=f"Service URL.",
|
|
388
394
|
implementation="Client",
|
|
389
395
|
required=True,
|
|
390
396
|
location=ParameterLocation.Other,
|
|
@@ -62,6 +62,11 @@ class RequestBuilderParameter(ParameterOnlyPathAndBodyPositional):
|
|
|
62
62
|
def is_keyword_only(self) -> bool:
|
|
63
63
|
return not self.location == ParameterLocation.Path and not self.is_kwarg
|
|
64
64
|
|
|
65
|
+
@is_keyword_only.setter
|
|
66
|
+
def is_keyword_only(self, val: bool) -> None:
|
|
67
|
+
self._keyword_only = val
|
|
68
|
+
self.is_kwarg = False
|
|
69
|
+
|
|
65
70
|
@property
|
|
66
71
|
def full_serialized_name(self) -> str:
|
|
67
72
|
return self.serialized_name
|
|
@@ -30,10 +30,11 @@ __all__ = [
|
|
|
30
30
|
]
|
|
31
31
|
|
|
32
32
|
class JinjaSerializer:
|
|
33
|
-
def __init__(self, autorestapi: AutorestAPI) -> None:
|
|
33
|
+
def __init__(self, autorestapi: AutorestAPI, code_model: CodeModel) -> None:
|
|
34
34
|
self._autorestapi = autorestapi
|
|
35
|
+
self.code_model = code_model
|
|
35
36
|
|
|
36
|
-
def serialize(self
|
|
37
|
+
def serialize(self) -> None:
|
|
37
38
|
env = Environment(
|
|
38
39
|
loader=PackageLoader("autorest.codegen", "templates"),
|
|
39
40
|
keep_trailing_newline=True,
|
|
@@ -44,32 +45,34 @@ class JinjaSerializer:
|
|
|
44
45
|
)
|
|
45
46
|
|
|
46
47
|
namespace_path = (
|
|
47
|
-
Path(".")
|
|
48
|
+
Path(".")
|
|
49
|
+
if self.code_model.options["no_namespace_folders"]
|
|
50
|
+
else Path(*(self.code_model.namespace.split(".")))
|
|
48
51
|
)
|
|
49
52
|
|
|
50
53
|
# if there was a patch file before, we keep it
|
|
51
54
|
self._keep_patch_file(namespace_path / Path("_patch.py"), env)
|
|
52
55
|
self._keep_patch_file(namespace_path / Path("aio") / Path("_patch.py"), env)
|
|
53
56
|
|
|
54
|
-
self._serialize_and_write_top_level_folder(
|
|
57
|
+
self._serialize_and_write_top_level_folder(env=env, namespace_path=namespace_path)
|
|
55
58
|
|
|
56
|
-
if code_model.rest.request_builders:
|
|
57
|
-
if code_model.options["builders_visibility"] != "embedded":
|
|
58
|
-
self._serialize_and_write_rest_layer(
|
|
59
|
-
if not code_model.options["no_async"]:
|
|
59
|
+
if self.code_model.rest.request_builders:
|
|
60
|
+
if self.code_model.options["builders_visibility"] != "embedded":
|
|
61
|
+
self._serialize_and_write_rest_layer(env=env, namespace_path=namespace_path)
|
|
62
|
+
if not self.code_model.options["no_async"]:
|
|
60
63
|
self._serialize_and_write_aio_top_level_folder(
|
|
61
|
-
|
|
64
|
+
env=env, namespace_path=namespace_path,
|
|
62
65
|
)
|
|
63
66
|
|
|
64
|
-
if code_model.options["show_operations"] and code_model.operation_groups:
|
|
65
|
-
self._serialize_and_write_operations_folder(
|
|
66
|
-
if code_model.options["multiapi"]:
|
|
67
|
+
if self.code_model.options["show_operations"] and self.code_model.operation_groups:
|
|
68
|
+
self._serialize_and_write_operations_folder(env=env, namespace_path=namespace_path)
|
|
69
|
+
if self.code_model.options["multiapi"]:
|
|
67
70
|
self._serialize_and_write_metadata(
|
|
68
|
-
|
|
71
|
+
env=env, namespace_path=namespace_path
|
|
69
72
|
)
|
|
70
73
|
|
|
71
|
-
if code_model.options["models_mode"] and (code_model.schemas or code_model.enums):
|
|
72
|
-
self._serialize_and_write_models_folder(
|
|
74
|
+
if self.code_model.options["models_mode"] and (self.code_model.schemas or self.code_model.enums):
|
|
75
|
+
self._serialize_and_write_models_folder(env=env, namespace_path=namespace_path)
|
|
73
76
|
|
|
74
77
|
|
|
75
78
|
|
|
@@ -80,49 +83,51 @@ class JinjaSerializer:
|
|
|
80
83
|
self._autorestapi.write_file(path_file, PatchSerializer(env=env).serialize())
|
|
81
84
|
|
|
82
85
|
|
|
83
|
-
def _serialize_and_write_models_folder(self,
|
|
86
|
+
def _serialize_and_write_models_folder(self, env: Environment, namespace_path: Path) -> None:
|
|
84
87
|
# Write the models folder
|
|
85
88
|
models_path = namespace_path / Path("models")
|
|
86
|
-
if code_model.schemas:
|
|
87
|
-
if not code_model.options['python3_only']:
|
|
89
|
+
if self.code_model.schemas:
|
|
90
|
+
if not self.code_model.options['python3_only']:
|
|
88
91
|
self._autorestapi.write_file(
|
|
89
|
-
models_path / Path("_models.py"),
|
|
92
|
+
models_path / Path("_models.py"),
|
|
93
|
+
ModelGenericSerializer(code_model=self.code_model, env=env).serialize()
|
|
90
94
|
)
|
|
91
95
|
self._autorestapi.write_file(
|
|
92
|
-
models_path / Path("_models_py3.py"),
|
|
96
|
+
models_path / Path("_models_py3.py"),
|
|
97
|
+
ModelPython3Serializer(code_model=self.code_model, env=env).serialize()
|
|
93
98
|
)
|
|
94
|
-
if code_model.enums:
|
|
99
|
+
if self.code_model.enums:
|
|
95
100
|
self._autorestapi.write_file(
|
|
96
|
-
models_path / Path(f"_{code_model.module_name}_enums.py"),
|
|
97
|
-
EnumSerializer(code_model=code_model, env=env).serialize(),
|
|
101
|
+
models_path / Path(f"_{self.code_model.module_name}_enums.py"),
|
|
102
|
+
EnumSerializer(code_model=self.code_model, env=env).serialize(),
|
|
98
103
|
)
|
|
99
104
|
self._autorestapi.write_file(
|
|
100
|
-
models_path / Path("__init__.py"), ModelInitSerializer(code_model=code_model, env=env).serialize()
|
|
105
|
+
models_path / Path("__init__.py"), ModelInitSerializer(code_model=self.code_model, env=env).serialize()
|
|
101
106
|
)
|
|
102
107
|
|
|
103
108
|
def _serialize_and_write_rest_layer(
|
|
104
|
-
self,
|
|
109
|
+
self, env: Environment, namespace_path: Path
|
|
105
110
|
) -> None:
|
|
106
|
-
rest_path = namespace_path / Path(code_model.rest_layer_name)
|
|
111
|
+
rest_path = namespace_path / Path(self.code_model.rest_layer_name)
|
|
107
112
|
operation_group_names = {
|
|
108
|
-
rb.operation_group_name for rb in code_model.rest.request_builders
|
|
113
|
+
rb.operation_group_name for rb in self.code_model.rest.request_builders
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
for operation_group_name in operation_group_names:
|
|
112
117
|
request_builders = [
|
|
113
|
-
r for r in code_model.rest.request_builders if r.operation_group_name == operation_group_name
|
|
118
|
+
r for r in self.code_model.rest.request_builders if r.operation_group_name == operation_group_name
|
|
114
119
|
]
|
|
115
120
|
self._serialize_and_write_single_rest_layer(
|
|
116
|
-
|
|
121
|
+
env, rest_path, request_builders
|
|
117
122
|
)
|
|
118
123
|
if not "" in operation_group_names:
|
|
119
124
|
self._autorestapi.write_file(
|
|
120
|
-
rest_path / Path("__init__.py"), code_model.options['license_header']
|
|
125
|
+
rest_path / Path("__init__.py"), self.code_model.options['license_header']
|
|
121
126
|
)
|
|
122
127
|
|
|
123
128
|
|
|
124
129
|
def _serialize_and_write_single_rest_layer(
|
|
125
|
-
self,
|
|
130
|
+
self, env: Environment, rest_path: Path, request_builders: List[RequestBuilder]
|
|
126
131
|
) -> None:
|
|
127
132
|
builder_group_name = request_builders[0].builder_group_name
|
|
128
133
|
output_path = rest_path / Path(builder_group_name) if builder_group_name else rest_path
|
|
@@ -130,7 +135,7 @@ class JinjaSerializer:
|
|
|
130
135
|
self._autorestapi.write_file(
|
|
131
136
|
output_path / Path("_request_builders.py"),
|
|
132
137
|
RestGenericSerializer(
|
|
133
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
138
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
134
139
|
).serialize_request_builders()
|
|
135
140
|
)
|
|
136
141
|
|
|
@@ -138,20 +143,19 @@ class JinjaSerializer:
|
|
|
138
143
|
self._autorestapi.write_file(
|
|
139
144
|
output_path / Path("_request_builders_py3.py"),
|
|
140
145
|
RestPython3Serializer(
|
|
141
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
146
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
142
147
|
).serialize_request_builders()
|
|
143
148
|
)
|
|
144
149
|
|
|
145
150
|
# write rest init file
|
|
146
151
|
self._autorestapi.write_file(
|
|
147
152
|
output_path / Path("__init__.py"), RestSerializer(
|
|
148
|
-
code_model=code_model, env=env, request_builders=request_builders
|
|
153
|
+
code_model=self.code_model, env=env, request_builders=request_builders
|
|
149
154
|
).serialize_init()
|
|
150
155
|
)
|
|
151
156
|
|
|
152
157
|
def _serialize_and_write_operations_file(
|
|
153
158
|
self,
|
|
154
|
-
code_model: CodeModel,
|
|
155
159
|
env: Environment,
|
|
156
160
|
namespace_path: Path,
|
|
157
161
|
operation_group: Optional[OperationGroup] = None
|
|
@@ -159,35 +163,35 @@ class JinjaSerializer:
|
|
|
159
163
|
filename = operation_group.filename if operation_group else "_operations"
|
|
160
164
|
# write first sync file
|
|
161
165
|
operation_group_serializer = OperationGroupsSerializer(
|
|
162
|
-
code_model=code_model,
|
|
166
|
+
code_model=self.code_model,
|
|
163
167
|
env=env,
|
|
164
168
|
async_mode=False,
|
|
165
|
-
is_python3_file=code_model.options['python3_only'],
|
|
169
|
+
is_python3_file=self.code_model.options['python3_only'],
|
|
166
170
|
operation_group=operation_group
|
|
167
171
|
)
|
|
168
172
|
self._autorestapi.write_file(
|
|
169
|
-
namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}.py"),
|
|
173
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}.py"),
|
|
170
174
|
operation_group_serializer.serialize(),
|
|
171
175
|
)
|
|
172
176
|
|
|
173
|
-
if not code_model.options['python3_only'] and code_model.options["add_python3_operation_files"]:
|
|
177
|
+
if not self.code_model.options['python3_only'] and self.code_model.options["add_python3_operation_files"]:
|
|
174
178
|
# write typed second file if not python 3 only
|
|
175
179
|
operation_group_serializer = OperationGroupsSerializer(
|
|
176
|
-
code_model=code_model,
|
|
180
|
+
code_model=self.code_model,
|
|
177
181
|
env=env,
|
|
178
182
|
async_mode=False,
|
|
179
183
|
is_python3_file=True,
|
|
180
184
|
|
|
181
185
|
)
|
|
182
186
|
self._autorestapi.write_file(
|
|
183
|
-
namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}_py3.py"),
|
|
187
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}_py3.py"),
|
|
184
188
|
operation_group_serializer.serialize(),
|
|
185
189
|
)
|
|
186
190
|
|
|
187
|
-
if not code_model.options["no_async"]:
|
|
191
|
+
if not self.code_model.options["no_async"]:
|
|
188
192
|
# write async operation group and operation files
|
|
189
193
|
operation_group_async_serializer = OperationGroupsSerializer(
|
|
190
|
-
code_model=code_model,
|
|
194
|
+
code_model=self.code_model,
|
|
191
195
|
env=env,
|
|
192
196
|
async_mode=True,
|
|
193
197
|
is_python3_file=True,
|
|
@@ -197,47 +201,47 @@ class JinjaSerializer:
|
|
|
197
201
|
(
|
|
198
202
|
namespace_path
|
|
199
203
|
/ Path("aio")
|
|
200
|
-
/ Path(code_model.operations_folder_name)
|
|
204
|
+
/ Path(self.code_model.operations_folder_name)
|
|
201
205
|
/ Path(f"{filename}.py")
|
|
202
206
|
),
|
|
203
207
|
operation_group_async_serializer.serialize(),
|
|
204
208
|
)
|
|
205
209
|
|
|
206
210
|
def _serialize_and_write_operations_folder(
|
|
207
|
-
self,
|
|
211
|
+
self, env: Environment, namespace_path: Path
|
|
208
212
|
) -> None:
|
|
209
213
|
# write sync operations init file
|
|
210
|
-
operations_init_serializer = OperationsInitSerializer(code_model=code_model, env=env, async_mode=False)
|
|
214
|
+
operations_init_serializer = OperationsInitSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
211
215
|
self._autorestapi.write_file(
|
|
212
|
-
namespace_path / Path(code_model.operations_folder_name) / Path("__init__.py"),
|
|
216
|
+
namespace_path / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
213
217
|
operations_init_serializer.serialize(),
|
|
214
218
|
)
|
|
215
219
|
|
|
216
220
|
# write async operations init file
|
|
217
|
-
if not code_model.options["no_async"]:
|
|
218
|
-
operations_async_init_serializer = OperationsInitSerializer(
|
|
221
|
+
if not self.code_model.options["no_async"]:
|
|
222
|
+
operations_async_init_serializer = OperationsInitSerializer(
|
|
223
|
+
code_model=self.code_model, env=env, async_mode=True
|
|
224
|
+
)
|
|
219
225
|
self._autorestapi.write_file(
|
|
220
|
-
namespace_path / Path("aio") / Path(code_model.operations_folder_name) / Path("__init__.py"),
|
|
226
|
+
namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path("__init__.py"),
|
|
221
227
|
operations_async_init_serializer.serialize(),
|
|
222
228
|
)
|
|
223
229
|
|
|
224
|
-
if code_model.options["combine_operation_files"]:
|
|
230
|
+
if self.code_model.options["combine_operation_files"]:
|
|
225
231
|
self._serialize_and_write_operations_file(
|
|
226
|
-
code_model=code_model,
|
|
227
232
|
env=env,
|
|
228
233
|
namespace_path=namespace_path,
|
|
229
234
|
)
|
|
230
235
|
else:
|
|
231
|
-
for operation_group in code_model.operation_groups:
|
|
236
|
+
for operation_group in self.code_model.operation_groups:
|
|
232
237
|
self._serialize_and_write_operations_file(
|
|
233
|
-
code_model=code_model,
|
|
234
238
|
env=env,
|
|
235
239
|
namespace_path=namespace_path,
|
|
236
240
|
operation_group=operation_group,
|
|
237
241
|
)
|
|
238
242
|
|
|
239
243
|
def _serialize_and_write_version_file(
|
|
240
|
-
self,
|
|
244
|
+
self, namespace_path: Path, general_serializer: GeneralSerializer
|
|
241
245
|
):
|
|
242
246
|
def _read_version_file(original_version_file_name: str) -> str:
|
|
243
247
|
return self._autorestapi.read_file(namespace_path / original_version_file_name)
|
|
@@ -247,23 +251,23 @@ class JinjaSerializer:
|
|
|
247
251
|
namespace_path / Path("_version.py"),
|
|
248
252
|
_read_version_file(original_version_file_name)
|
|
249
253
|
)
|
|
250
|
-
keep_version_file = code_model.options['keep_version_file']
|
|
254
|
+
keep_version_file = self.code_model.options['keep_version_file']
|
|
251
255
|
if keep_version_file and _read_version_file("_version.py"):
|
|
252
256
|
_write_version_file(original_version_file_name="_version.py")
|
|
253
257
|
elif keep_version_file and _read_version_file("version.py"):
|
|
254
258
|
_write_version_file(original_version_file_name="version.py")
|
|
255
|
-
elif code_model.options['package_version']:
|
|
259
|
+
elif self.code_model.options['package_version']:
|
|
256
260
|
self._autorestapi.write_file(
|
|
257
261
|
namespace_path / Path("_version.py"),
|
|
258
262
|
general_serializer.serialize_version_file()
|
|
259
263
|
)
|
|
260
264
|
|
|
261
265
|
def _serialize_and_write_top_level_folder(
|
|
262
|
-
self,
|
|
266
|
+
self, env: Environment, namespace_path: Path
|
|
263
267
|
) -> None:
|
|
264
|
-
general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=False)
|
|
268
|
+
general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=False)
|
|
265
269
|
|
|
266
|
-
if code_model.rest.request_builders:
|
|
270
|
+
if self.code_model.rest.request_builders:
|
|
267
271
|
self._autorestapi.write_file(
|
|
268
272
|
namespace_path / Path("__init__.py"), general_serializer.serialize_init_file()
|
|
269
273
|
)
|
|
@@ -280,37 +284,37 @@ class JinjaSerializer:
|
|
|
280
284
|
p = p.parent
|
|
281
285
|
|
|
282
286
|
# Write the service client
|
|
283
|
-
if code_model.rest.request_builders:
|
|
287
|
+
if self.code_model.rest.request_builders:
|
|
284
288
|
self._autorestapi.write_file(
|
|
285
|
-
namespace_path / Path(f"_{code_model.module_name}.py"),
|
|
289
|
+
namespace_path / Path(f"_{self.code_model.module_name}.py"),
|
|
286
290
|
general_serializer.serialize_service_client_file()
|
|
287
291
|
)
|
|
288
292
|
|
|
289
|
-
if code_model.need_vendored_code:
|
|
293
|
+
if self.code_model.need_vendored_code:
|
|
290
294
|
self._autorestapi.write_file(
|
|
291
295
|
namespace_path / Path("_vendor.py"),
|
|
292
296
|
general_serializer.serialize_vendor_file()
|
|
293
297
|
)
|
|
294
298
|
|
|
295
|
-
self._serialize_and_write_version_file(
|
|
299
|
+
self._serialize_and_write_version_file(namespace_path, general_serializer)
|
|
296
300
|
|
|
297
301
|
# write the empty py.typed file
|
|
298
302
|
self._autorestapi.write_file(namespace_path / Path("py.typed"), "# Marker file for PEP 561.")
|
|
299
303
|
|
|
300
304
|
# Write the config file
|
|
301
|
-
if code_model.rest.request_builders:
|
|
305
|
+
if self.code_model.rest.request_builders:
|
|
302
306
|
self._autorestapi.write_file(
|
|
303
307
|
namespace_path / Path("_configuration.py"), general_serializer.serialize_config_file()
|
|
304
308
|
)
|
|
305
309
|
|
|
306
310
|
# Write the setup file
|
|
307
|
-
if code_model.options["basic_setup_py"]:
|
|
311
|
+
if self.code_model.options["basic_setup_py"]:
|
|
308
312
|
self._autorestapi.write_file(Path("setup.py"), general_serializer.serialize_setup_file())
|
|
309
313
|
|
|
310
314
|
def _serialize_and_write_aio_top_level_folder(
|
|
311
|
-
self,
|
|
315
|
+
self, env: Environment, namespace_path: Path
|
|
312
316
|
) -> None:
|
|
313
|
-
aio_general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=True)
|
|
317
|
+
aio_general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=True)
|
|
314
318
|
|
|
315
319
|
aio_path = namespace_path / Path("aio")
|
|
316
320
|
|
|
@@ -319,7 +323,7 @@ class JinjaSerializer:
|
|
|
319
323
|
|
|
320
324
|
# Write the service client
|
|
321
325
|
self._autorestapi.write_file(
|
|
322
|
-
aio_path / Path(f"_{code_model.module_name}.py"),
|
|
326
|
+
aio_path / Path(f"_{self.code_model.module_name}.py"),
|
|
323
327
|
aio_general_serializer.serialize_service_client_file(),
|
|
324
328
|
)
|
|
325
329
|
|
|
@@ -329,6 +333,6 @@ class JinjaSerializer:
|
|
|
329
333
|
)
|
|
330
334
|
|
|
331
335
|
|
|
332
|
-
def _serialize_and_write_metadata(self,
|
|
333
|
-
metadata_serializer = MetadataSerializer(code_model, env)
|
|
336
|
+
def _serialize_and_write_metadata(self, env: Environment, namespace_path: Path) -> None:
|
|
337
|
+
metadata_serializer = MetadataSerializer(self.code_model, env)
|
|
334
338
|
self._autorestapi.write_file(namespace_path / Path("_metadata.json"), metadata_serializer.serialize())
|
|
@@ -27,6 +27,7 @@ from ..models import (
|
|
|
27
27
|
SchemaResponse,
|
|
28
28
|
IOSchema,
|
|
29
29
|
ParameterStyle,
|
|
30
|
+
ParameterLocation
|
|
30
31
|
)
|
|
31
32
|
from . import utils
|
|
32
33
|
|
|
@@ -152,12 +153,21 @@ def _serialize_flattened_body(builder) -> List[str]:
|
|
|
152
153
|
return retval
|
|
153
154
|
|
|
154
155
|
def _content_type_docstring(builder) -> str:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
content_types = [f'"{c}"' for c in builder.parameters.content_types]
|
|
157
|
+
if len(content_types) == 2:
|
|
158
|
+
possible_values_str = " or ".join(content_types)
|
|
159
|
+
else:
|
|
160
|
+
possible_values_str = ", ".join(
|
|
161
|
+
content_types[: len(content_types) - 1]
|
|
162
|
+
) + f", and {content_types[-1]}"
|
|
163
|
+
default_value = next(
|
|
164
|
+
p for p in builder.parameters.method if p.rest_api_name == "Content-Type"
|
|
165
|
+
).default_value_declaration
|
|
166
|
+
return (
|
|
167
|
+
":keyword content_type: Media type of the body sent to the API. " +
|
|
168
|
+
f"Possible values are: {possible_values_str}. " +
|
|
169
|
+
f"Default value is {default_value}."
|
|
159
170
|
)
|
|
160
|
-
return content_type_str
|
|
161
171
|
|
|
162
172
|
class _BuilderSerializerProtocol(ABC):
|
|
163
173
|
@property
|
|
@@ -304,13 +314,14 @@ class _BuilderBaseSerializer(_BuilderSerializerProtocol): # pylint: disable=abs
|
|
|
304
314
|
description_list.append(
|
|
305
315
|
f":{param.docstring_type_keyword} { param.serialized_name }: { param.docstring_type }"
|
|
306
316
|
)
|
|
307
|
-
try:
|
|
308
|
-
request_builder: RequestBuilder = cast(Operation, builder).request_builder
|
|
309
|
-
except AttributeError:
|
|
310
|
-
request_builder = cast(RequestBuilder, builder)
|
|
311
317
|
|
|
312
|
-
if len(
|
|
313
|
-
description_list
|
|
318
|
+
if len(builder.parameters.content_types) > 1:
|
|
319
|
+
description_list = [
|
|
320
|
+
_content_type_docstring(builder) if l.startswith(":keyword content_type:") else l
|
|
321
|
+
for l in description_list
|
|
322
|
+
]
|
|
323
|
+
if not any(l for l in description_list if l.startswith(":keyword content_type:")):
|
|
324
|
+
description_list.append(_content_type_docstring(builder))
|
|
314
325
|
return description_list
|
|
315
326
|
|
|
316
327
|
def param_description_and_response_docstring(self, builder) -> List[str]:
|
|
@@ -788,6 +799,7 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
788
799
|
builder,
|
|
789
800
|
request_builder: RequestBuilder,
|
|
790
801
|
template_url: Optional[str] = None,
|
|
802
|
+
is_next_request: bool = False,
|
|
791
803
|
) -> List[str]:
|
|
792
804
|
retval = []
|
|
793
805
|
if len(builder.body_kwargs_to_pass_to_request_builder) > 1:
|
|
@@ -827,6 +839,16 @@ class _OperationBaseSerializer(_BuilderBaseSerializer): # pylint: disable=abstr
|
|
|
827
839
|
parameter.serialized_name not in builder.body_kwargs_to_pass_to_request_builder
|
|
828
840
|
):
|
|
829
841
|
continue
|
|
842
|
+
if (
|
|
843
|
+
is_next_request and
|
|
844
|
+
not bool(builder.next_request_builder) and
|
|
845
|
+
not self.code_model.options["reformat_next_link"] and
|
|
846
|
+
parameter.location == ParameterLocation.Query
|
|
847
|
+
):
|
|
848
|
+
# if we don't want to reformat query parameters for next link calls
|
|
849
|
+
# in paging operations with a single swagger operation defintion,
|
|
850
|
+
# we skip passing query params when building the next request
|
|
851
|
+
continue
|
|
830
852
|
high_level_name = cast(RequestBuilderParameter, parameter).name_in_high_level_operation
|
|
831
853
|
retval.append(f" {parameter.serialized_name}={high_level_name},")
|
|
832
854
|
if not self.code_model.options["version_tolerant"]:
|
|
@@ -1073,11 +1095,13 @@ class _PagingOperationBaseSerializer(_OperationBaseSerializer): # pylint: disab
|
|
|
1073
1095
|
else:
|
|
1074
1096
|
request_builder = builder.request_builder
|
|
1075
1097
|
template_url = "next_link"
|
|
1098
|
+
|
|
1076
1099
|
request_builder = builder.next_request_builder or builder.request_builder
|
|
1077
1100
|
return self._call_request_builder_helper(
|
|
1078
1101
|
builder,
|
|
1079
1102
|
request_builder,
|
|
1080
1103
|
template_url=template_url,
|
|
1104
|
+
is_next_request=True
|
|
1081
1105
|
)
|
|
1082
1106
|
|
|
1083
1107
|
def _prepare_request_callback(self, builder) -> List[str]:
|
|
@@ -373,7 +373,7 @@ class NameConverter:
|
|
|
373
373
|
# check to see if name is reserved for the type of name we are converting
|
|
374
374
|
pad_string = cast(PadType, pad_string)
|
|
375
375
|
# there are some private variables, such as grouped parameters
|
|
376
|
-
# that are private. We still want to escape them for
|
|
376
|
+
# that are private. We still want to escape them for DPG
|
|
377
377
|
name_prefix = ""
|
|
378
378
|
if name[0] == "_":
|
|
379
379
|
# i am private
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.13.0",
|
|
4
4
|
"description": "The Python extension for generators in AutoRest.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "node run-python3.js prepare.py",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@azure-tools/extension": "~3.2.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@microsoft.azure/autorest.testserver": "^3.
|
|
30
|
+
"@microsoft.azure/autorest.testserver": "^3.3.20"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"autorest/**/*.py",
|
package/run-python3.js
CHANGED
|
@@ -18,12 +18,6 @@ async function runPython3(scriptName, debug = "") {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
runPython3(...process.argv.slice(2)).catch(err => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Python script errors are already written out via stderr so don't
|
|
24
|
-
// write them twice. Write out all other errors to stderr.
|
|
25
|
-
if (!error.startsWith("Error: Command failed")) {
|
|
26
|
-
console.error(error);
|
|
27
|
-
}
|
|
21
|
+
console.error(err.toString());
|
|
28
22
|
process.exit(1);
|
|
29
23
|
});
|
package/venvtools.py
CHANGED
|
@@ -62,13 +62,13 @@ def python_run(venv_context, module, command=None, *, additional_dir=".", error_
|
|
|
62
62
|
venv_context.env_exe,
|
|
63
63
|
"-m", module
|
|
64
64
|
] + (command if command else [])
|
|
65
|
-
print("Executing: {}".format(" ".join(cmd_line))
|
|
65
|
+
print("Executing: {}".format(" ".join(cmd_line)))
|
|
66
66
|
subprocess.run(
|
|
67
67
|
cmd_line,
|
|
68
68
|
cwd=_ROOT_DIR / additional_dir,
|
|
69
69
|
check=True,
|
|
70
70
|
)
|
|
71
71
|
except subprocess.CalledProcessError as err:
|
|
72
|
-
print(err
|
|
72
|
+
print(err)
|
|
73
73
|
if not error_ok:
|
|
74
74
|
sys.exit(1)
|