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

Commit 3e03cf3

Browse files
authored
Adds XSchemaDict constructor using named arguments (#197)
* Adds from_dict_ method * Adds immutabledict back in * Adds types for required and optional properties * Uses new io_type template for required and optional properties * Adds newlines to boolean input types * Adds newlines to binary and none * Adds newline for literal values * Adds newline for optional str * Adds newlines for number and integer inputs * Adds remaining io newlines * Adds input types to anyType input * Adds map with no props types * Adds object input types * Adds tuple types when there is not arrayOutputJsonPathPiece * Adds array input types * Adds arg casting when addProps is false * Adds casting to object model input in new method * Adds new types for kwargs * Makes arg_ dict type permissive * Adds _arg dict type in new * Replaces _helper_property_value_type with _helper_schema_io_type in object_input_type * Replaces many _helper_property_value_type usages * Uses schema_io for optional property definition * Updates required properties typeddict to use schema_io template * Adjusts definition of array model type to use schema_io template * Removes unused templates * Fixes array model self reference detection * Fixes mypy errors by making default literals into literals * Adjusts comment line for empty map output class * Fixes mypy errors by moving new before properties * Requires that required arguments are named and not positional * Adds date/datetime/uuid inputs when those formats are specified * Removes reference to deleted input schema template * Adds io. types for binary input * Samples regen * Changes node4 image
1 parent 8ee9f12 commit 3e03cf3

File tree

339 files changed

+6915
-2034
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

339 files changed

+6915
-2034
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ jobs:
185185
nodeNo: "3"
186186
node4:
187187
docker:
188-
- image: fkrull/multi-python
188+
- image: python:3.8
189189
working_directory: ~/OpenAPITools/openapi-json-schema-generator
190190
shell: /bin/bash --login
191191
environment:

samples/client/3_0_3_unit_test/python/.openapi-generator/FILES

+1
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,7 @@ src/unit_test_api/py.typed
20842084
src/unit_test_api/rest.py
20852085
src/unit_test_api/schemas/__init__.py
20862086
src/unit_test_api/schemas/format.py
2087+
src/unit_test_api/schemas/original_immutabledict.py
20872088
src/unit_test_api/schemas/schema.py
20882089
src/unit_test_api/schemas/schemas.py
20892090
src/unit_test_api/schemas/validation.py

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_allows_a_schema_which_should_validate.py

+39-33
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,41 @@ class AdditionalpropertiesAllowsASchemaWhichShouldValidateDict(schemas.immutable
3030
"foo",
3131
"bar",
3232
})
33+
@staticmethod
34+
def from_dict_(
35+
arg: AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput,
36+
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
37+
) -> AdditionalpropertiesAllowsASchemaWhichShouldValidateDict:
38+
return AdditionalpropertiesAllowsASchemaWhichShouldValidate.validate(arg, configuration=configuration)
39+
40+
def __new__(
41+
cls,
42+
*,
43+
foo: typing.Union[
44+
schemas.INPUT_TYPES_ALL,
45+
schemas.OUTPUT_BASE_TYPES,
46+
schemas.Unset
47+
] = schemas.unset,
48+
bar: typing.Union[
49+
schemas.INPUT_TYPES_ALL,
50+
schemas.OUTPUT_BASE_TYPES,
51+
schemas.Unset
52+
] = schemas.unset,
53+
configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None,
54+
**kwargs: bool,
55+
):
56+
arg_: typing.Dict[str, typing.Any] = {}
57+
for key, val in (
58+
("foo", foo),
59+
("bar", bar),
60+
):
61+
if isinstance(val, schemas.Unset):
62+
continue
63+
arg_[key] = val
64+
arg_.update(kwargs)
65+
used_arg_ = typing.cast(AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput, arg_)
66+
return AdditionalpropertiesAllowsASchemaWhichShouldValidate.validate(used_arg_, configuration=configuration_)
67+
3368

3469
@property
3570
def foo(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
@@ -60,45 +95,16 @@ def get_additional_property_(self, name: str) -> typing.Union[bool, schemas.Unse
6095
bool,
6196
val
6297
)
63-
64-
def __new__(cls, arg: AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput, configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None):
65-
return AdditionalpropertiesAllowsASchemaWhichShouldValidate.validate(arg, configuration=configuration)
6698
AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput = typing.Mapping[
6799
str,
68100
typing.Union[
69101
typing.Union[
70-
dict,
71-
schemas.immutabledict,
72-
str,
73-
datetime.date,
74-
datetime.datetime,
75-
uuid.UUID,
76-
int,
77-
float,
78-
bool,
79-
None,
80-
list,
81-
tuple,
82-
bytes,
83-
io.FileIO,
84-
io.BufferedReader
102+
schemas.INPUT_TYPES_ALL,
103+
schemas.OUTPUT_BASE_TYPES
85104
],
86105
typing.Union[
87-
dict,
88-
schemas.immutabledict,
89-
str,
90-
datetime.date,
91-
datetime.datetime,
92-
uuid.UUID,
93-
int,
94-
float,
95-
bool,
96-
None,
97-
list,
98-
tuple,
99-
bytes,
100-
io.FileIO,
101-
io.BufferedReader
106+
schemas.INPUT_TYPES_ALL,
107+
schemas.OUTPUT_BASE_TYPES
102108
],
103109
bool,
104110
]

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_are_allowed_by_default.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,41 @@ class AdditionalpropertiesAreAllowedByDefaultDict(schemas.immutabledict[str, sch
2929
"foo",
3030
"bar",
3131
})
32+
@staticmethod
33+
def from_dict_(
34+
arg: AdditionalpropertiesAreAllowedByDefaultDictInput,
35+
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
36+
) -> AdditionalpropertiesAreAllowedByDefaultDict:
37+
return AdditionalpropertiesAreAllowedByDefault.validate(arg, configuration=configuration)
38+
39+
def __new__(
40+
cls,
41+
*,
42+
foo: typing.Union[
43+
schemas.INPUT_TYPES_ALL,
44+
schemas.OUTPUT_BASE_TYPES,
45+
schemas.Unset
46+
] = schemas.unset,
47+
bar: typing.Union[
48+
schemas.INPUT_TYPES_ALL,
49+
schemas.OUTPUT_BASE_TYPES,
50+
schemas.Unset
51+
] = schemas.unset,
52+
configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None,
53+
**kwargs: schemas.INPUT_TYPES_ALL,
54+
):
55+
arg_: typing.Dict[str, typing.Any] = {}
56+
for key, val in (
57+
("foo", foo),
58+
("bar", bar),
59+
):
60+
if isinstance(val, schemas.Unset):
61+
continue
62+
arg_[key] = val
63+
arg_.update(kwargs)
64+
used_arg_ = typing.cast(AdditionalpropertiesAreAllowedByDefaultDictInput, arg_)
65+
return AdditionalpropertiesAreAllowedByDefault.validate(used_arg_, configuration=configuration_)
66+
3267

3368
@property
3469
def foo(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
@@ -53,9 +88,6 @@ def bar(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
5388
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
5489
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
5590
return self.get(name, schemas.unset)
56-
57-
def __new__(cls, arg: AdditionalpropertiesAreAllowedByDefaultDictInput, configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None):
58-
return AdditionalpropertiesAreAllowedByDefault.validate(arg, configuration=configuration)
5991
AdditionalpropertiesAreAllowedByDefaultDictInput = typing.Mapping[str, schemas.INPUT_TYPES_ALL]
6092

6193

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_can_exist_by_itself.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ class AdditionalpropertiesCanExistByItselfDict(schemas.immutabledict[str, bool])
1919
})
2020
__optional_keys__: typing.FrozenSet[str] = frozenset({
2121
})
22+
def __new__(
23+
cls,
24+
configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None,
25+
**kwargs: bool,
26+
):
27+
used_kwargs = typing.cast(AdditionalpropertiesCanExistByItselfDictInput, kwargs)
28+
return AdditionalpropertiesCanExistByItself.validate(used_kwargs, configuration=configuration_)
29+
30+
@staticmethod
31+
def from_dict_(
32+
arg: AdditionalpropertiesCanExistByItselfDictInput,
33+
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
34+
) -> AdditionalpropertiesCanExistByItselfDict:
35+
return AdditionalpropertiesCanExistByItself.validate(arg, configuration=configuration)
36+
2237

2338
def get_additional_property_(self, name: str) -> typing.Union[bool, schemas.Unset]:
2439
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
@@ -29,9 +44,6 @@ def get_additional_property_(self, name: str) -> typing.Union[bool, schemas.Unse
2944
bool,
3045
val
3146
)
32-
33-
def __new__(cls, arg: AdditionalpropertiesCanExistByItselfDictInput, configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None):
34-
return AdditionalpropertiesCanExistByItself.validate(arg, configuration=configuration)
3547
AdditionalpropertiesCanExistByItselfDictInput = typing.Mapping[
3648
str,
3749
bool,

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_should_not_look_in_applicators.py

+44-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ class _0Dict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]):
2727
__optional_keys__: typing.FrozenSet[str] = frozenset({
2828
"foo",
2929
})
30+
@staticmethod
31+
def from_dict_(
32+
arg: _0DictInput,
33+
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
34+
) -> _0Dict:
35+
return _0.validate(arg, configuration=configuration)
36+
37+
def __new__(
38+
cls,
39+
*,
40+
foo: typing.Union[
41+
schemas.INPUT_TYPES_ALL,
42+
schemas.OUTPUT_BASE_TYPES,
43+
schemas.Unset
44+
] = schemas.unset,
45+
configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None,
46+
**kwargs: schemas.INPUT_TYPES_ALL,
47+
):
48+
arg_: typing.Dict[str, typing.Any] = {}
49+
for key, val in (
50+
("foo", foo),
51+
):
52+
if isinstance(val, schemas.Unset):
53+
continue
54+
arg_[key] = val
55+
arg_.update(kwargs)
56+
used_arg_ = typing.cast(_0DictInput, arg_)
57+
return _0.validate(used_arg_, configuration=configuration_)
58+
3059

3160
@property
3261
def foo(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
@@ -41,9 +70,6 @@ def foo(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
4170
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
4271
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
4372
return self.get(name, schemas.unset)
44-
45-
def __new__(cls, arg: _0DictInput, configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None):
46-
return _0.validate(arg, configuration=configuration)
4773
_0DictInput = typing.Mapping[str, schemas.INPUT_TYPES_ALL]
4874

4975

@@ -73,6 +99,21 @@ class AdditionalpropertiesShouldNotLookInApplicatorsDict(schemas.immutabledict[s
7399
})
74100
__optional_keys__: typing.FrozenSet[str] = frozenset({
75101
})
102+
def __new__(
103+
cls,
104+
configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None,
105+
**kwargs: bool,
106+
):
107+
used_kwargs = typing.cast(AdditionalpropertiesShouldNotLookInApplicatorsDictInput, kwargs)
108+
return AdditionalpropertiesShouldNotLookInApplicators.validate(used_kwargs, configuration=configuration_)
109+
110+
@staticmethod
111+
def from_dict_(
112+
arg: AdditionalpropertiesShouldNotLookInApplicatorsDictInput,
113+
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
114+
) -> AdditionalpropertiesShouldNotLookInApplicatorsDict:
115+
return AdditionalpropertiesShouldNotLookInApplicators.validate(arg, configuration=configuration)
116+
76117

77118
def get_additional_property_(self, name: str) -> typing.Union[bool, schemas.Unset]:
78119
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
@@ -83,9 +124,6 @@ def get_additional_property_(self, name: str) -> typing.Union[bool, schemas.Unse
83124
bool,
84125
val
85126
)
86-
87-
def __new__(cls, arg: AdditionalpropertiesShouldNotLookInApplicatorsDictInput, configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None):
88-
return AdditionalpropertiesShouldNotLookInApplicators.validate(arg, configuration=configuration)
89127
AdditionalpropertiesShouldNotLookInApplicatorsDictInput = typing.Mapping[
90128
str,
91129
bool,

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof.py

+42-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ class _0Dict(schemas.immutabledict[str, int]):
2626
})
2727
__optional_keys__: typing.FrozenSet[str] = frozenset({
2828
})
29+
@staticmethod
30+
def from_dict_(
31+
arg: _0DictInput,
32+
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
33+
) -> _0Dict:
34+
return _0.validate(arg, configuration=configuration)
35+
36+
def __new__(
37+
cls,
38+
*,
39+
bar: int,
40+
configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None,
41+
**kwargs: schemas.INPUT_TYPES_ALL,
42+
):
43+
arg_: typing.Dict[str, typing.Any] = {
44+
"bar": bar,
45+
}
46+
arg_.update(kwargs)
47+
used_arg_ = typing.cast(_0DictInput, arg_)
48+
return _0.validate(used_arg_, configuration=configuration_)
49+
2950

3051
@property
3152
def bar(self) -> int:
@@ -37,9 +58,6 @@ def bar(self) -> int:
3758
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
3859
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
3960
return self.get(name, schemas.unset)
40-
41-
def __new__(cls, arg: _0DictInput, configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None):
42-
return _0.validate(arg, configuration=configuration)
4361
_0DictInput = typing.Mapping[str, schemas.INPUT_TYPES_ALL]
4462

4563

@@ -77,6 +95,27 @@ class _1Dict(schemas.immutabledict[str, str]):
7795
})
7896
__optional_keys__: typing.FrozenSet[str] = frozenset({
7997
})
98+
@staticmethod
99+
def from_dict_(
100+
arg: _1DictInput,
101+
configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None
102+
) -> _1Dict:
103+
return _1.validate(arg, configuration=configuration)
104+
105+
def __new__(
106+
cls,
107+
*,
108+
foo: str,
109+
configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None,
110+
**kwargs: schemas.INPUT_TYPES_ALL,
111+
):
112+
arg_: typing.Dict[str, typing.Any] = {
113+
"foo": foo,
114+
}
115+
arg_.update(kwargs)
116+
used_arg_ = typing.cast(_1DictInput, arg_)
117+
return _1.validate(used_arg_, configuration=configuration_)
118+
80119

81120
@property
82121
def foo(self) -> str:
@@ -88,9 +127,6 @@ def foo(self) -> str:
88127
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
89128
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
90129
return self.get(name, schemas.unset)
91-
92-
def __new__(cls, arg: _1DictInput, configuration: typing.Optional[schema_configuration.SchemaConfiguration] = None):
93-
return _1.validate(arg, configuration=configuration)
94130
_1DictInput = typing.Mapping[str, schemas.INPUT_TYPES_ALL]
95131

96132

0 commit comments

Comments
 (0)