@@ -20,6 +20,17 @@ def assert_eq(
20
20
assert generated == expected
21
21
22
22
23
+ def build_field_with_alias (identifier : str ) -> ast .Call :
24
+ return ast .Call (
25
+ func = ast .Name (id = "Field" ),
26
+ args = [],
27
+ keywords = [
28
+ ast .keyword (arg = "default" , value = ast .Constant (value = None )),
29
+ ast .keyword (arg = "alias" , value = ast .Constant (value = identifier )),
30
+ ],
31
+ )
32
+
33
+
23
34
def test_generates_empty_ast_from_empty_definitions () -> None :
24
35
assert build_ast ([]) == []
25
36
@@ -64,12 +75,12 @@ def test_generates_class_for_flat_definition() -> None:
64
75
),
65
76
ast .Expr (value = ast .Constant (value = "test resource property 1" )),
66
77
ast .AnnAssign (
67
- target = ast .Name (id = "_property1 " ),
78
+ target = ast .Name (id = "property1__ext " ),
68
79
annotation = ast .Subscript (
69
80
value = ast .Name (id = "Optional_" ),
70
81
slice = ast .Constant ("Element" ),
71
82
),
72
- value = ast . Constant ( None ),
83
+ value = build_field_with_alias ( "_property1" ),
73
84
simple = 1 ,
74
85
),
75
86
ast .Expr (value = ast .Constant (value = "test resource property 1" )),
@@ -176,13 +187,13 @@ def test_generates_multiple_classes_for_compound_definition() -> None:
176
187
value = ast .Constant (value = "nested test resource property 1" )
177
188
),
178
189
ast .AnnAssign (
179
- target = ast .Name (id = "_property1 " ),
190
+ target = ast .Name (id = "property1__ext " ),
180
191
annotation = ast .Subscript (
181
192
value = ast .Name (id = "Optional_" ),
182
193
slice = ast .Constant ("Element" ),
183
194
),
184
195
simple = 1 ,
185
- value = ast . Constant ( None ),
196
+ value = build_field_with_alias ( "_property1" ),
186
197
),
187
198
ast .Expr (
188
199
value = ast .Constant (value = "nested test resource property 1" )
@@ -329,7 +340,7 @@ def test_generates_annotations_according_to_structure_type(
329
340
),
330
341
ast .Expr (value = ast .Constant (value = "test resource property 1" )),
331
342
ast .AnnAssign (
332
- target = ast .Name (id = "_property1 " ),
343
+ target = ast .Name (id = "property1__ext " ),
333
344
annotation = ast .Subscript (
334
345
value = ast .Name (id = "Optional_" ),
335
346
slice = ast .Subscript (
@@ -343,7 +354,7 @@ def test_generates_annotations_according_to_structure_type(
343
354
slice = ast .Constant ("Element" ),
344
355
),
345
356
simple = 1 ,
346
- value = ast . Constant ( None ),
357
+ value = build_field_with_alias ( "_property1" ),
347
358
),
348
359
ast .Expr (value = ast .Constant (value = "test resource property 1" )),
349
360
],
@@ -418,13 +429,13 @@ def test_unrolls_required_polymorphic_into_class_union() -> None:
418
429
),
419
430
ast .Expr (value = ast .Constant (value = "monotype property definition" )),
420
431
ast .AnnAssign (
421
- target = ast .Name (id = "_monotype " ),
432
+ target = ast .Name (id = "monotype__ext " ),
422
433
annotation = ast .Subscript (
423
434
value = ast .Name (id = "Optional_" ),
424
435
slice = ast .Constant ("Element" ),
425
436
),
426
437
simple = 1 ,
427
- value = ast . Constant ( None ),
438
+ value = build_field_with_alias ( "_monotype" ),
428
439
),
429
440
ast .Expr (value = ast .Constant (value = "monotype property definition" )),
430
441
ast .AnnAssign (
@@ -440,13 +451,13 @@ def test_unrolls_required_polymorphic_into_class_union() -> None:
440
451
value = ast .Constant (value = "polymorphic property definition" )
441
452
),
442
453
ast .AnnAssign (
443
- target = ast .Name (id = "_valueBoolean " ),
454
+ target = ast .Name (id = "valueBoolean__ext " ),
444
455
annotation = ast .Subscript (
445
456
value = ast .Name (id = "Optional_" ),
446
457
slice = ast .Constant ("Element" ),
447
458
),
448
459
simple = 1 ,
449
- value = ast . Constant ( None ),
460
+ value = build_field_with_alias ( "_valueBoolean" ),
450
461
),
451
462
ast .Expr (
452
463
value = ast .Constant (value = "polymorphic property definition" )
0 commit comments