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

Commit 9763ac9

Browse files
committed
Adds generic type T
1 parent 8d65f59 commit 9763ac9

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

  • modules/openapi-json-schema-generator/src/main/resources/python
  • samples/openapi3/client/petstore/python

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,9 @@ json_schema_keyword_to_validator = {
12261226
'discriminator': validate_discriminator
12271227
}
12281228

1229+
T = typing.TypeVar('T')
12291230

1230-
class Schema:
1231+
class Schema(typing.Generic[T]):
12311232
"""
12321233
the base class of all swagger/openapi schemas/models
12331234
"""
@@ -2144,7 +2145,7 @@ def cast_to_allowed_types(
21442145

21452146
class ListSchema(
21462147
ListBase,
2147-
Schema,
2148+
Schema[T],
21482149
TupleMixin
21492150
):
21502151
class Schema_:
@@ -2160,7 +2161,7 @@ class ListSchema(
21602161

21612162
class NoneSchema(
21622163
NoneBase,
2163-
Schema,
2164+
Schema[T],
21642165
NoneMixin
21652166
):
21662167
class Schema_:
@@ -2176,7 +2177,7 @@ class NoneSchema(
21762177

21772178
class NumberSchema(
21782179
NumberBase,
2179-
Schema,
2180+
Schema[T],
21802181
DecimalMixin
21812182
):
21822183
"""
@@ -2259,7 +2260,7 @@ class Float64Schema(
22592260

22602261
class StrSchema(
22612262
StrBase,
2262-
Schema,
2263+
Schema[T],
22632264
StrMixin
22642265
):
22652266
"""
@@ -2324,7 +2325,7 @@ class DecimalSchema(DecimalBase, StrSchema):
23242325

23252326

23262327
class BytesSchema(
2327-
Schema,
2328+
Schema[T],
23282329
BytesMixin
23292330
):
23302331
"""
@@ -2338,7 +2339,7 @@ class BytesSchema(
23382339

23392340

23402341
class FileSchema(
2341-
Schema,
2342+
Schema[T],
23422343
FileMixin
23432344
):
23442345
"""
@@ -2365,7 +2366,7 @@ class FileSchema(
23652366

23662367

23672368
class BinarySchema(
2368-
Schema,
2369+
Schema[T],
23692370
BinaryMixin
23702371
):
23712372
class Schema_:
@@ -2384,7 +2385,7 @@ class BinarySchema(
23842385

23852386
class BoolSchema(
23862387
BoolBase,
2387-
Schema,
2388+
Schema[T],
23882389
BoolMixin
23892390
):
23902391
class Schema_:
@@ -2405,7 +2406,7 @@ class AnyTypeSchema(
24052406
StrBase,
24062407
NumberBase,
24072408
BoolBase,
2408-
Schema,
2409+
Schema[T],
24092410
NoneFrozenDictTupleStrDecimalBoolFileBytesMixin
24102411
):
24112412
# Python representation of a schema defined as true or {}
@@ -2442,7 +2443,7 @@ class NotAnyTypeSchema(AnyTypeSchema):
24422443

24432444
class DictSchema(
24442445
DictBase,
2445-
Schema,
2446+
Schema[T],
24462447
FrozenDictMixin
24472448
):
24482449
class Schema_:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0
1+
unset

samples/openapi3/client/petstore/python/src/petstore_api/schemas.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,8 +1102,9 @@ def validate_discriminator(
11021102
'discriminator': validate_discriminator
11031103
}
11041104

1105+
T = typing.TypeVar('T')
11051106

1106-
class Schema:
1107+
class Schema(typing.Generic[T]):
11071108
"""
11081109
the base class of all swagger/openapi schemas/models
11091110
"""
@@ -2055,7 +2056,7 @@ def cast_to_allowed_types(
20552056

20562057
class ListSchema(
20572058
ListBase,
2058-
Schema,
2059+
Schema[T],
20592060
TupleMixin
20602061
):
20612062
class Schema_:
@@ -2071,7 +2072,7 @@ def __new__(cls, arg_: typing.Union[typing.List[typing.Any], typing.Tuple[typing
20712072

20722073
class NoneSchema(
20732074
NoneBase,
2074-
Schema,
2075+
Schema[T],
20752076
NoneMixin
20762077
):
20772078
class Schema_:
@@ -2087,7 +2088,7 @@ def __new__(cls, arg_: None, **kwargs: schema_configuration.SchemaConfiguration)
20872088

20882089
class NumberSchema(
20892090
NumberBase,
2090-
Schema,
2091+
Schema[T],
20912092
DecimalMixin
20922093
):
20932094
"""
@@ -2170,7 +2171,7 @@ def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_c
21702171

21712172
class StrSchema(
21722173
StrBase,
2173-
Schema,
2174+
Schema[T],
21742175
StrMixin
21752176
):
21762177
"""
@@ -2235,7 +2236,7 @@ def __new__(cls, arg_: str, **kwargs: schema_configuration.SchemaConfiguration):
22352236

22362237

22372238
class BytesSchema(
2238-
Schema,
2239+
Schema[T],
22392240
BytesMixin
22402241
):
22412242
"""
@@ -2249,7 +2250,7 @@ def __new__(cls, arg_: bytes, **kwargs: schema_configuration.SchemaConfiguration
22492250

22502251

22512252
class FileSchema(
2252-
Schema,
2253+
Schema[T],
22532254
FileMixin
22542255
):
22552256
"""
@@ -2276,7 +2277,7 @@ def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader], **kwargs: sch
22762277

22772278

22782279
class BinarySchema(
2279-
Schema,
2280+
Schema[T],
22802281
BinaryMixin
22812282
):
22822283
class Schema_:
@@ -2295,7 +2296,7 @@ def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader, bytes], **kwar
22952296

22962297
class BoolSchema(
22972298
BoolBase,
2298-
Schema,
2299+
Schema[T],
22992300
BoolMixin
23002301
):
23012302
class Schema_:
@@ -2316,7 +2317,7 @@ class AnyTypeSchema(
23162317
StrBase,
23172318
NumberBase,
23182319
BoolBase,
2319-
Schema,
2320+
Schema[T],
23202321
NoneFrozenDictTupleStrDecimalBoolFileBytesMixin
23212322
):
23222323
# Python representation of a schema defined as true or {}
@@ -2353,7 +2354,7 @@ def __new__(
23532354

23542355
class DictSchema(
23552356
DictBase,
2356-
Schema,
2357+
Schema[T],
23572358
FrozenDictMixin
23582359
):
23592360
class Schema_:

0 commit comments

Comments
 (0)