Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit e4e067b

Browse files
committed
Adds unset types on all except for array and object models
1 parent 489f4fb commit e4e067b

30 files changed

Lines changed: 71 additions & 55 deletions

File tree

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_output_type_base.hbs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
{{#each types}}
33
{{#eq this "boolean"}}
44
{{#and ../enumInfo ../enumInfo.typeToValues.boolean}}
5+
{{#if optional}}
6+
typing.Union[typing_extensions.Literal[{{#each ../enumInfo.typeToValues.boolean}}{{#if value}}True{{else}}False{{/if}}{{#unless @last}}, {{/unless}}{{/each}}], schemas.Unset]{{endChar}}
7+
{{else}}
58
typing_extensions.Literal[{{#each ../enumInfo.typeToValues.boolean}}{{#if value}}True{{else}}False{{/if}}{{#unless @last}}, {{/unless}}{{/each}}]{{endChar}}
9+
{{/if}}
610
{{else}}
711
{{#if optional}}typing.Union[bool, schemas.Unset]{{else}}bool{{/if}}{{endChar}}
812
{{/and}}
@@ -15,18 +19,26 @@ typing_extensions.Literal[{{#each ../enumInfo.typeToValues.boolean}}{{#if value}
1519
typing.Union[bytes, schemas.FileIO]{{endChar}}
1620
{{else}}
1721
{{#and ../enumInfo ../enumInfo.typeToValues.string}}
22+
{{#if optional}}
23+
typing.Union[typing_extensions.Literal[{{#each ../enumInfo.typeToValues.string}}"{{{value}}}"{{#unless @last}}, {{/unless}}{{/each}}], schemas.Unset]{{endChar}}
24+
{{else}}
1825
typing_extensions.Literal[{{#each ../enumInfo.typeToValues.string}}"{{{value}}}"{{#unless @last}}, {{/unless}}{{/each}}]{{endChar}}
26+
{{/if}}
1927
{{else}}
2028
{{#if optional}}typing.Union[str, schemas.Unset]{{else}}str{{/if}}{{endChar}}
2129
{{/and}}
2230
{{/eq}}
2331
{{else}}
2432
{{#eq this "number"}}
25-
typing.Union[int, float]{{endChar}}
33+
typing.Union[int, float{{#if optional}}, schemas.Unset{{/if}}]{{endChar}}
2634
{{else}}
2735
{{#eq this "integer"}}
2836
{{#and ../enumInfo ../enumInfo.typeToValues.integer}}
37+
{{#if optional}}
38+
typing.Union[typing_extensions.Literal[{{#each ../enumInfo.typeToValues.integer}}{{value}}{{#unless @last}}, {{/unless}}{{/each}}], schemas.Unset]{{endChar}}
39+
{{else}}
2940
typing_extensions.Literal[{{#each ../enumInfo.typeToValues.integer}}{{value}}{{#unless @last}}, {{/unless}}{{/each}}]{{endChar}}
41+
{{/if}}
3042
{{else}}
3143
{{#if optional}}typing.Union[int, schemas.Unset]{{else}}int{{/if}}{{endChar}}
3244
{{/and}}
@@ -61,5 +73,9 @@ schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]{{endChar}}
6173
{{/eq}}
6274
{{/each}}
6375
{{else}}
76+
{{#if optional}}
77+
typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]{{endChar}}
78+
{{else}}
6479
schemas.OUTPUT_BASE_TYPES{{endChar}}
80+
{{/if}}
6581
{{/if}}

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def get_map_of_map_property(self) -> MapOfMapPropertyDict:
388388
)
389389

390390
@property
391-
def get_anytype1(self) -> schemas.OUTPUT_BASE_TYPES:
391+
def get_anytype1(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
392392
val = self.get("anytype_1", schemas.unset)
393393
if val is schemas.unset:
394394
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_and_format.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class AnyTypeAndFormatDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]
123123
})
124124

125125
@property
126-
def get_uuid(self) -> schemas.OUTPUT_BASE_TYPES:
126+
def get_uuid(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
127127
val = self.get("uuid", schemas.unset)
128128
if val is schemas.unset:
129129
return val
@@ -133,7 +133,7 @@ def get_uuid(self) -> schemas.OUTPUT_BASE_TYPES:
133133
)
134134

135135
@property
136-
def get_date(self) -> schemas.OUTPUT_BASE_TYPES:
136+
def get_date(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
137137
val = self.get("date", schemas.unset)
138138
if val is schemas.unset:
139139
return val
@@ -143,7 +143,7 @@ def get_date(self) -> schemas.OUTPUT_BASE_TYPES:
143143
)
144144

145145
@property
146-
def get_date_time(self) -> schemas.OUTPUT_BASE_TYPES:
146+
def get_date_time(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
147147
val = self.get("date-time", schemas.unset)
148148
if val is schemas.unset:
149149
return val
@@ -153,7 +153,7 @@ def get_date_time(self) -> schemas.OUTPUT_BASE_TYPES:
153153
)
154154

155155
@property
156-
def get_number(self) -> schemas.OUTPUT_BASE_TYPES:
156+
def get_number(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
157157
val = self.get("number", schemas.unset)
158158
if val is schemas.unset:
159159
return val
@@ -163,7 +163,7 @@ def get_number(self) -> schemas.OUTPUT_BASE_TYPES:
163163
)
164164

165165
@property
166-
def get_binary(self) -> schemas.OUTPUT_BASE_TYPES:
166+
def get_binary(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
167167
val = self.get("binary", schemas.unset)
168168
if val is schemas.unset:
169169
return val
@@ -173,7 +173,7 @@ def get_binary(self) -> schemas.OUTPUT_BASE_TYPES:
173173
)
174174

175175
@property
176-
def get_int32(self) -> schemas.OUTPUT_BASE_TYPES:
176+
def get_int32(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
177177
val = self.get("int32", schemas.unset)
178178
if val is schemas.unset:
179179
return val
@@ -183,7 +183,7 @@ def get_int32(self) -> schemas.OUTPUT_BASE_TYPES:
183183
)
184184

185185
@property
186-
def get_int64(self) -> schemas.OUTPUT_BASE_TYPES:
186+
def get_int64(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
187187
val = self.get("int64", schemas.unset)
188188
if val is schemas.unset:
189189
return val
@@ -193,7 +193,7 @@ def get_int64(self) -> schemas.OUTPUT_BASE_TYPES:
193193
)
194194

195195
@property
196-
def get_double(self) -> schemas.OUTPUT_BASE_TYPES:
196+
def get_double(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
197197
val = self.get("double", schemas.unset)
198198
if val is schemas.unset:
199199
return val
@@ -203,7 +203,7 @@ def get_double(self) -> schemas.OUTPUT_BASE_TYPES:
203203
)
204204

205205
@property
206-
def get__float(self) -> schemas.OUTPUT_BASE_TYPES:
206+
def get__float(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
207207
val = self.get("float", schemas.unset)
208208
if val is schemas.unset:
209209
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/complex_quadrilateral.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _1Dict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]):
8080
})
8181

8282
@property
83-
def get_quadrilateral_type(self) -> typing_extensions.Literal["ComplexQuadrilateral"]:
83+
def get_quadrilateral_type(self) -> typing.Union[typing_extensions.Literal["ComplexQuadrilateral"], schemas.Unset]:
8484
val = self.get("quadrilateralType", schemas.unset)
8585
if val is schemas.unset:
8686
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/drawing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class DrawingDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]):
119119
})
120120

121121
@property
122-
def get_main_shape(self) -> schemas.OUTPUT_BASE_TYPES:
122+
def get_main_shape(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
123123
val = self.get("mainShape", schemas.unset)
124124
if val is schemas.unset:
125125
return val
@@ -129,7 +129,7 @@ def get_main_shape(self) -> schemas.OUTPUT_BASE_TYPES:
129129
)
130130

131131
@property
132-
def get_shape_or_null(self) -> schemas.OUTPUT_BASE_TYPES:
132+
def get_shape_or_null(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
133133
val = self.get("shapeOrNull", schemas.unset)
134134
if val is schemas.unset:
135135
return val
@@ -139,7 +139,7 @@ def get_shape_or_null(self) -> schemas.OUTPUT_BASE_TYPES:
139139
)
140140

141141
@property
142-
def get_nullable_shape(self) -> schemas.OUTPUT_BASE_TYPES:
142+
def get_nullable_shape(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
143143
val = self.get("nullableShape", schemas.unset)
144144
if val is schemas.unset:
145145
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_arrays.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class EnumArraysDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]):
214214
})
215215

216216
@property
217-
def get_just_symbol(self) -> typing_extensions.Literal[">=", "$"]:
217+
def get_just_symbol(self) -> typing.Union[typing_extensions.Literal[">=", "$"], schemas.Unset]:
218218
val = self.get("just_symbol", schemas.unset)
219219
if val is schemas.unset:
220220
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def get_enum_string_required(self) -> typing_extensions.Literal["UPPER", "lower"
329329
)
330330

331331
@property
332-
def get_enum_string(self) -> typing_extensions.Literal["UPPER", "lower", ""]:
332+
def get_enum_string(self) -> typing.Union[typing_extensions.Literal["UPPER", "lower", ""], schemas.Unset]:
333333
val = self.get("enum_string", schemas.unset)
334334
if val is schemas.unset:
335335
return val
@@ -339,7 +339,7 @@ def get_enum_string(self) -> typing_extensions.Literal["UPPER", "lower", ""]:
339339
)
340340

341341
@property
342-
def get_enum_integer(self) -> typing_extensions.Literal[1, -1]:
342+
def get_enum_integer(self) -> typing.Union[typing_extensions.Literal[1, -1], schemas.Unset]:
343343
val = self.get("enum_integer", schemas.unset)
344344
if val is schemas.unset:
345345
return val
@@ -349,7 +349,7 @@ def get_enum_integer(self) -> typing_extensions.Literal[1, -1]:
349349
)
350350

351351
@property
352-
def get_enum_number(self) -> typing.Union[int, float]:
352+
def get_enum_number(self) -> typing.Union[int, float, schemas.Unset]:
353353
val = self.get("enum_number", schemas.unset)
354354
if val is schemas.unset:
355355
return val
@@ -361,7 +361,7 @@ def get_enum_number(self) -> typing.Union[int, float]:
361361
@property
362362
def get_string_enum(self) -> typing.Union[
363363
typing.Union[None, schemas.Unset],
364-
typing_extensions.Literal["placed", "approved", "delivered", "single quoted", "multiple\nlines", "double quote \n with newline"],
364+
typing.Union[typing_extensions.Literal["placed", "approved", "delivered", "single quoted", "multiple\nlines", "double quote \n with newline"], schemas.Unset],
365365
]:
366366
val = self.get("stringEnum", schemas.unset)
367367
if val is schemas.unset:
@@ -375,7 +375,7 @@ def get_string_enum(self) -> typing.Union[
375375
)
376376

377377
@property
378-
def get_integer_enum(self) -> typing_extensions.Literal[0, 1, 2]:
378+
def get_integer_enum(self) -> typing.Union[typing_extensions.Literal[0, 1, 2], schemas.Unset]:
379379
val = self.get("IntegerEnum", schemas.unset)
380380
if val is schemas.unset:
381381
return val
@@ -385,7 +385,7 @@ def get_integer_enum(self) -> typing_extensions.Literal[0, 1, 2]:
385385
)
386386

387387
@property
388-
def get_string_enum_with_default_value(self) -> typing_extensions.Literal["placed", "approved", "delivered"]:
388+
def get_string_enum_with_default_value(self) -> typing.Union[typing_extensions.Literal["placed", "approved", "delivered"], schemas.Unset]:
389389
val = self.get("StringEnumWithDefaultValue", schemas.unset)
390390
if val is schemas.unset:
391391
return val
@@ -395,7 +395,7 @@ def get_string_enum_with_default_value(self) -> typing_extensions.Literal["place
395395
)
396396

397397
@property
398-
def get_integer_enum_with_default_value(self) -> typing_extensions.Literal[0, 1, 2]:
398+
def get_integer_enum_with_default_value(self) -> typing.Union[typing_extensions.Literal[0, 1, 2], schemas.Unset]:
399399
val = self.get("IntegerEnumWithDefaultValue", schemas.unset)
400400
if val is schemas.unset:
401401
return val
@@ -405,7 +405,7 @@ def get_integer_enum_with_default_value(self) -> typing_extensions.Literal[0, 1,
405405
)
406406

407407
@property
408-
def get_integer_enum_one_value(self) -> typing_extensions.Literal[0]:
408+
def get_integer_enum_one_value(self) -> typing.Union[typing_extensions.Literal[0], schemas.Unset]:
409409
val = self.get("IntegerEnumOneValue", schemas.unset)
410410
if val is schemas.unset:
411411
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/equilateral_triangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _1Dict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]):
8080
})
8181

8282
@property
83-
def get_triangle_type(self) -> typing_extensions.Literal["EquilateralTriangle"]:
83+
def get_triangle_type(self) -> typing.Union[typing_extensions.Literal["EquilateralTriangle"], schemas.Unset]:
8484
val = self.get("triangleType", schemas.unset)
8585
if val is schemas.unset:
8686
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/format_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def get_int64(self) -> typing.Union[int, schemas.Unset]:
317317
)
318318

319319
@property
320-
def get__float(self) -> typing.Union[int, float]:
320+
def get__float(self) -> typing.Union[int, float, schemas.Unset]:
321321
val = self.get("float", schemas.unset)
322322
if val is schemas.unset:
323323
return val
@@ -327,7 +327,7 @@ def get__float(self) -> typing.Union[int, float]:
327327
)
328328

329329
@property
330-
def get_float32(self) -> typing.Union[int, float]:
330+
def get_float32(self) -> typing.Union[int, float, schemas.Unset]:
331331
val = self.get("float32", schemas.unset)
332332
if val is schemas.unset:
333333
return val
@@ -337,7 +337,7 @@ def get_float32(self) -> typing.Union[int, float]:
337337
)
338338

339339
@property
340-
def get_double(self) -> typing.Union[int, float]:
340+
def get_double(self) -> typing.Union[int, float, schemas.Unset]:
341341
val = self.get("double", schemas.unset)
342342
if val is schemas.unset:
343343
return val
@@ -347,7 +347,7 @@ def get_double(self) -> typing.Union[int, float]:
347347
)
348348

349349
@property
350-
def get_float64(self) -> typing.Union[int, float]:
350+
def get_float64(self) -> typing.Union[int, float, schemas.Unset]:
351351
val = self.get("float64", schemas.unset)
352352
if val is schemas.unset:
353353
return val

samples/openapi3/client/petstore/python/src/petstore_api/components/schema/isosceles_triangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _1Dict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]):
8080
})
8181

8282
@property
83-
def get_triangle_type(self) -> typing_extensions.Literal["IsoscelesTriangle"]:
83+
def get_triangle_type(self) -> typing.Union[typing_extensions.Literal["IsoscelesTriangle"], schemas.Unset]:
8484
val = self.get("triangleType", schemas.unset)
8585
if val is schemas.unset:
8686
return val

0 commit comments

Comments
 (0)