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

Commit a05acd8

Browse files
authored
Adds openapi 3.1.0 if/then/else json schema features + fixes exclusiveMax/Min bug (#234)
* Adds if and then codegenSchema info * Adds string types to if then else samples * Templates updated to render if then in schema classes * Samples regen * Adds then validator * Adds tests * Adds else schema data store * Adds alse info in component schemas * Adds else tests * Adds if then else schea features * Generator docs updated * Adds if then else tests to 310 unit test spec * Turns on tests for if/then/else in 310 client * Fixes some if + else tests * Fixes exclusiveMin/Max ingestion * Enables more exclusive min and max tests * Samples regen
1 parent 4daefd9 commit a05acd8

File tree

366 files changed

+13099
-21
lines changed

Some content is hidden

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

366 files changed

+13099
-21
lines changed

docs/generators/java.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
322322
|DependentRequired|✗|OAS3
323323
|DependentSchemas|✗|OAS3
324324
|Discriminator|✓|OAS2,OAS3
325+
|Else|✗|OAS3
325326
|Enum|✓|OAS2,OAS3
326327
|ExclusiveMinimum|✓|OAS2,OAS3
327328
|ExclusiveMaximum|✓|OAS2,OAS3
328329
|Format|✓|OAS2,OAS3
330+
|If|✗|OAS3
329331
|Items|✓|OAS2,OAS3
330332
|MaxContains|✗|OAS3
331333
|MaxItems|✓|OAS2,OAS3
@@ -347,6 +349,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
347349
|Properties|✓|OAS2,OAS3
348350
|PropertyNames|✗|OAS3
349351
|Required|✓|OAS2,OAS3
352+
|Then|✗|OAS3
350353
|Type|✓|OAS2,OAS3
351354
|UnevaluatedItems|✗|OAS3
352355
|UnevaluatedProperties|✗|OAS3

docs/generators/jaxrs-jersey.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
305305
|DependentRequired|✗|OAS3
306306
|DependentSchemas|✗|OAS3
307307
|Discriminator|✓|OAS2,OAS3
308+
|Else|✗|OAS3
308309
|Enum|✓|OAS2,OAS3
309310
|ExclusiveMinimum|✓|OAS2,OAS3
310311
|ExclusiveMaximum|✓|OAS2,OAS3
311312
|Format|✓|OAS2,OAS3
313+
|If|✗|OAS3
312314
|Items|✓|OAS2,OAS3
313315
|MaxContains|✗|OAS3
314316
|MaxItems|✓|OAS2,OAS3
@@ -330,6 +332,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
330332
|Properties|✓|OAS2,OAS3
331333
|PropertyNames|✗|OAS3
332334
|Required|✓|OAS2,OAS3
335+
|Then|✗|OAS3
333336
|Type|✓|OAS2,OAS3
334337
|UnevaluatedItems|✗|OAS3
335338
|UnevaluatedProperties|✗|OAS3

docs/generators/jmeter.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
164164
|DependentRequired|✗|OAS3
165165
|DependentSchemas|✗|OAS3
166166
|Discriminator|✓|OAS2,OAS3
167+
|Else|✗|OAS3
167168
|Enum|✓|OAS2,OAS3
168169
|ExclusiveMinimum|✓|OAS2,OAS3
169170
|ExclusiveMaximum|✓|OAS2,OAS3
170171
|Format|✓|OAS2,OAS3
172+
|If|✗|OAS3
171173
|Items|✓|OAS2,OAS3
172174
|MaxContains|✗|OAS3
173175
|MaxItems|✓|OAS2,OAS3
@@ -189,6 +191,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
189191
|Properties|✓|OAS2,OAS3
190192
|PropertyNames|✗|OAS3
191193
|Required|✓|OAS2,OAS3
194+
|Then|✗|OAS3
192195
|Type|✓|OAS2,OAS3
193196
|UnevaluatedItems|✗|OAS3
194197
|UnevaluatedProperties|✗|OAS3

docs/generators/kotlin.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
274274
|DependentRequired|✗|OAS3
275275
|DependentSchemas|✗|OAS3
276276
|Discriminator|✓|OAS2,OAS3
277+
|Else|✗|OAS3
277278
|Enum|✓|OAS2,OAS3
278279
|ExclusiveMinimum|✓|OAS2,OAS3
279280
|ExclusiveMaximum|✓|OAS2,OAS3
280281
|Format|✓|OAS2,OAS3
282+
|If|✗|OAS3
281283
|Items|✓|OAS2,OAS3
282284
|MaxContains|✗|OAS3
283285
|MaxItems|✓|OAS2,OAS3
@@ -299,6 +301,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
299301
|Properties|✓|OAS2,OAS3
300302
|PropertyNames|✗|OAS3
301303
|Required|✓|OAS2,OAS3
304+
|Then|✗|OAS3
302305
|Type|✓|OAS2,OAS3
303306
|UnevaluatedItems|✗|OAS3
304307
|UnevaluatedProperties|✗|OAS3

docs/generators/python.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
233233
|DependentRequired|✓|OAS3
234234
|DependentSchemas|✓|OAS3
235235
|Discriminator|✓|OAS2,OAS3
236+
|Else|✓|OAS3
236237
|Enum|✓|OAS2,OAS3
237238
|ExclusiveMinimum|✓|OAS2,OAS3
238239
|ExclusiveMaximum|✓|OAS2,OAS3
239240
|Format|✓|OAS2,OAS3
241+
|If|✓|OAS3
240242
|Items|✓|OAS2,OAS3
241243
|MaxContains|✓|OAS3
242244
|MaxItems|✓|OAS2,OAS3
@@ -258,6 +260,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
258260
|Properties|✓|OAS2,OAS3
259261
|PropertyNames|✓|OAS3
260262
|Required|✓|OAS2,OAS3
263+
|Then|✓|OAS3
261264
|Type|✓|OAS2,OAS3
262265
|UnevaluatedItems|✓|OAS3
263266
|UnevaluatedProperties|✓|OAS3

samples/client/3_0_3_unit_test/python/src/unit_test_api/configurations/schema_configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
'dependent_schemas': 'dependentSchemas',
2323
'discriminator': 'discriminator',
2424
# default omitted because it has no validation impact
25+
'else_': 'else',
2526
'enum_value_to_name': 'enum',
2627
'exclusive_maximum': 'exclusiveMaximum',
2728
'exclusive_minimum': 'exclusiveMinimum',
2829
'format': 'format',
30+
'if_': 'if',
2931
'inclusive_maximum': 'maximum',
3032
'inclusive_minimum': 'minimum',
3133
'items': 'items',
@@ -46,6 +48,7 @@
4648
'properties': 'properties',
4749
'property_names': 'propertyNames',
4850
'required': 'required',
51+
'then': 'then',
4952
'types': 'type',
5053
'unique_items': 'uniqueItems',
5154
'unevaluated_items': 'unevaluatedItems',

samples/client/3_0_3_unit_test/python/src/unit_test_api/schemas/validation.py

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ def _validate(
9999
validation_metadata,
100100
path_to_schemas
101101
)
102+
if_path_to_schemas = None
103+
if 'if_' in vars(cls_schema):
104+
if_path_to_schemas = _get_if_path_to_schemas(
105+
arg,
106+
vars(cls_schema)['if_'],
107+
validation_metadata,
108+
)
102109
validated_pattern_properties: typing.Optional[PathToSchemasType] = None
103110
if 'pattern_properties' in vars(cls_schema):
104111
validated_pattern_properties = _get_validated_pattern_properties(
@@ -123,6 +130,8 @@ def _validate(
123130
used_val = (val, format)
124131
elif keyword in {'pattern_properties', 'additional_properties'}:
125132
used_val = (val, validated_pattern_properties)
133+
elif keyword in {'if_', 'then', 'else_'}:
134+
used_val = (val, if_path_to_schemas)
126135
else:
127136
used_val = val
128137
validator = json_schema_keyword_to_validator[keyword]
@@ -1005,6 +1014,108 @@ def validate_discriminator(
10051014
return discriminated_cls._validate(arg, validation_metadata=updated_vm)
10061015

10071016

1017+
def _get_if_path_to_schemas(
1018+
arg: typing.Any,
1019+
if_cls: typing.Type[SchemaValidator],
1020+
validation_metadata: ValidationMetadata,
1021+
) -> PathToSchemasType:
1022+
if_cls = _get_class(if_cls)
1023+
these_path_to_schemas: PathToSchemasType = {}
1024+
try:
1025+
other_path_to_schemas = if_cls._validate(
1026+
arg, validation_metadata=validation_metadata)
1027+
update(these_path_to_schemas, other_path_to_schemas)
1028+
except exceptions.OpenApiException:
1029+
pass
1030+
return these_path_to_schemas
1031+
1032+
1033+
def validate_if(
1034+
arg: typing.Any,
1035+
if_cls_if_path_to_schemas: typing.Tuple[
1036+
typing.Type[SchemaValidator], typing.Optional[PathToSchemasType]
1037+
],
1038+
cls: typing.Type,
1039+
validation_metadata: ValidationMetadata,
1040+
) -> typing.Optional[PathToSchemasType]:
1041+
if_path_to_schemas = if_cls_if_path_to_schemas[1]
1042+
if if_path_to_schemas is None:
1043+
raise exceptions.OpenApiException('Invalid type for if_path_to_schemas')
1044+
"""
1045+
if is false use case
1046+
if_path_to_schemas == {}
1047+
no need to add any data to path_to_schemas
1048+
1049+
if true, then true -> true for whole schema
1050+
so validate_then will add if_path_to_schemas data to path_to_schemas
1051+
"""
1052+
return None
1053+
1054+
1055+
def validate_then(
1056+
arg: typing.Any,
1057+
then_cls_if_path_to_schemas: typing.Tuple[
1058+
typing.Type[SchemaValidator], typing.Optional[PathToSchemasType]
1059+
],
1060+
cls: typing.Type,
1061+
validation_metadata: ValidationMetadata,
1062+
) -> typing.Optional[PathToSchemasType]:
1063+
if_path_to_schemas = then_cls_if_path_to_schemas[1]
1064+
if if_path_to_schemas is None:
1065+
# use case: there is no if
1066+
return None
1067+
"""
1068+
if is false use case
1069+
if_path_to_schemas == {}
1070+
no need to add any data to path_to_schemas
1071+
"""
1072+
if not if_path_to_schemas:
1073+
return None
1074+
then_cls = _get_class(then_cls_if_path_to_schemas[0])
1075+
these_path_to_schemas: PathToSchemasType = {}
1076+
try:
1077+
other_path_to_schemas = then_cls._validate(
1078+
arg, validation_metadata=validation_metadata)
1079+
update(these_path_to_schemas, if_path_to_schemas)
1080+
update(these_path_to_schemas, other_path_to_schemas)
1081+
return these_path_to_schemas
1082+
except exceptions.OpenApiException as ex:
1083+
# then False case
1084+
raise ex
1085+
1086+
1087+
def validate_else(
1088+
arg: typing.Any,
1089+
else_cls_if_path_to_schemas: typing.Tuple[
1090+
typing.Type[SchemaValidator], typing.Optional[PathToSchemasType]
1091+
],
1092+
cls: typing.Type,
1093+
validation_metadata: ValidationMetadata,
1094+
) -> typing.Optional[PathToSchemasType]:
1095+
if_path_to_schemas = else_cls_if_path_to_schemas[1]
1096+
if if_path_to_schemas is None:
1097+
# use case: there is no if
1098+
return None
1099+
if if_path_to_schemas:
1100+
# skip validation if if_path_to_schemas was true
1101+
return None
1102+
"""
1103+
if is false use case
1104+
if_path_to_schemas == {}
1105+
"""
1106+
else_cls = _get_class(else_cls_if_path_to_schemas[0])
1107+
these_path_to_schemas: PathToSchemasType = {}
1108+
try:
1109+
other_path_to_schemas = else_cls._validate(
1110+
arg, validation_metadata=validation_metadata)
1111+
update(these_path_to_schemas, if_path_to_schemas)
1112+
update(these_path_to_schemas, other_path_to_schemas)
1113+
return these_path_to_schemas
1114+
except exceptions.OpenApiException as ex:
1115+
# else False case
1116+
raise ex
1117+
1118+
10081119
def _get_contains_qty(
10091120
arg: typing.Any,
10101121
contains_cls: typing.Type[SchemaValidator],
@@ -1326,5 +1437,8 @@ def validate_unevaluated_properties(
13261437
'pattern_properties': validate_pattern_properties,
13271438
'prefix_items': validate_prefix_items,
13281439
'unevaluated_items': validate_unevaluated_items,
1329-
'unevaluated_properties': validate_unevaluated_properties
1440+
'unevaluated_properties': validate_unevaluated_properties,
1441+
'if_': validate_if,
1442+
'then': validate_then,
1443+
'else_': validate_else
13301444
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ docs/components/schema/any_type_const_string.md
77
docs/components/schema/any_type_contains_value.md
88
docs/components/schema/any_type_dependent_required.md
99
docs/components/schema/any_type_dependent_schemas.md
10+
docs/components/schema/any_type_if_then_else.md
1011
docs/components/schema/any_type_max_contains_value.md
1112
docs/components/schema/any_type_min_contains_value.md
1213
docs/components/schema/any_type_pattern_properties.md
@@ -27,6 +28,7 @@ docs/components/schema/array_prefix_items.md
2728
docs/components/schema/array_unevaluated_items_false_with_prefix_items.md
2829
docs/components/schema/object_dependent_required.md
2930
docs/components/schema/object_dependent_schemas.md
31+
docs/components/schema/object_if_then_else.md
3032
docs/components/schema/object_pattern_properties.md
3133
docs/components/schema/object_property_names.md
3234
docs/components/schema/object_unevaluated_properties_false_with_properties.md
@@ -55,6 +57,7 @@ src/json_schema_api/components/schema/any_type_const_string.py
5557
src/json_schema_api/components/schema/any_type_contains_value.py
5658
src/json_schema_api/components/schema/any_type_dependent_required.py
5759
src/json_schema_api/components/schema/any_type_dependent_schemas.py
60+
src/json_schema_api/components/schema/any_type_if_then_else.py
5861
src/json_schema_api/components/schema/any_type_max_contains_value.py
5962
src/json_schema_api/components/schema/any_type_min_contains_value.py
6063
src/json_schema_api/components/schema/any_type_pattern_properties.py
@@ -75,6 +78,7 @@ src/json_schema_api/components/schema/array_prefix_items.py
7578
src/json_schema_api/components/schema/array_unevaluated_items_false_with_prefix_items.py
7679
src/json_schema_api/components/schema/object_dependent_required.py
7780
src/json_schema_api/components/schema/object_dependent_schemas.py
81+
src/json_schema_api/components/schema/object_if_then_else.py
7882
src/json_schema_api/components/schema/object_pattern_properties.py
7983
src/json_schema_api/components/schema/object_property_names.py
8084
src/json_schema_api/components/schema/object_unevaluated_properties_false_with_properties.py

samples/client/3_1_0_json_schema/python/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Class | Description
177177
[AnyTypeContainsValue](docs/components/schema/any_type_contains_value.md) |
178178
[AnyTypeDependentRequired](docs/components/schema/any_type_dependent_required.md) |
179179
[AnyTypeDependentSchemas](docs/components/schema/any_type_dependent_schemas.md) |
180+
[AnyTypeIfThenElse](docs/components/schema/any_type_if_then_else.md) |
180181
[AnyTypeMaxContainsValue](docs/components/schema/any_type_max_contains_value.md) |
181182
[AnyTypeMinContainsValue](docs/components/schema/any_type_min_contains_value.md) |
182183
[AnyTypePatternProperties](docs/components/schema/any_type_pattern_properties.md) |
@@ -197,6 +198,7 @@ Class | Description
197198
[ArrayUnevaluatedItemsFalseWithPrefixItems](docs/components/schema/array_unevaluated_items_false_with_prefix_items.md) |
198199
[ObjectDependentRequired](docs/components/schema/object_dependent_required.md) |
199200
[ObjectDependentSchemas](docs/components/schema/object_dependent_schemas.md) |
201+
[ObjectIfThenElse](docs/components/schema/object_if_then_else.md) |
200202
[ObjectPatternProperties](docs/components/schema/object_pattern_properties.md) |
201203
[ObjectPropertyNames](docs/components/schema/object_property_names.md) |
202204
[ObjectUnevaluatedPropertiesFalseWithProperties](docs/components/schema/object_unevaluated_properties_false_with_properties.md) |
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# AnyTypeIfThenElse
2+
json_schema_api.components.schema.any_type_if_then_else
3+
```
4+
type: schemas.Schema
5+
```
6+
7+
## validate method
8+
Input Type | Return Type | Notes
9+
------------ | ------------- | -------------
10+
[AnyTypeIfThenElseDictInput](#anytypeifthenelsedictinput), [AnyTypeIfThenElseDict](#anytypeifthenelsedict), str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | [AnyTypeIfThenElseDict](#anytypeifthenelsedict), str, float, int, bool, None, tuple, bytes, io.FileIO |
11+
12+
## AnyTypeIfThenElseDictInput
13+
```
14+
type: typing.Mapping[str, schemas.INPUT_TYPES_ALL]
15+
```
16+
Key | Type | Description | Notes
17+
------------ | ------------- | ------------- | -------------
18+
**street_address** | str | | [optional]
19+
**country** | typing.Literal["United States of America", "Canada"] | | [optional] must be one of ["United States of America", "Canada"] if omitted the server will use the default value of United States of America
20+
**any_string_name** | dict, schemas.immutabledict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.FileIO | any string name can be used but the value must be the correct type | [optional]
21+
22+
## AnyTypeIfThenElseDict
23+
```
24+
base class: schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]
25+
26+
```
27+
### __new__ method
28+
Keyword Argument | Type | Description | Notes
29+
---------------- | ---- | ----------- | -----
30+
**street_address** | str, schemas.Unset | | [optional]
31+
**country** | typing.Literal["United States of America", "Canada"], schemas.Unset | | [optional] must be one of ["United States of America", "Canada"] if omitted the server will use the default value of United States of America
32+
**kwargs** | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO | any string name can be used but the value must be the correct type | [optional] typed value is accessed with the get_additional_property_ method
33+
34+
### properties
35+
Property | Type | Description | Notes
36+
-------- | ---- | ----------- | -----
37+
**street_address** | str, schemas.Unset | | [optional]
38+
**country** | typing.Literal["United States of America", "Canada"], schemas.Unset | | [optional] must be one of ["United States of America", "Canada"] if omitted the server will use the default value of United States of America
39+
40+
### methods
41+
Method | Input Type | Return Type | Notes
42+
------ | ---------- | ----------- | ------
43+
from_dict_ | [AnyTypeIfThenElseDictInput](#anytypeifthenelsedictinput), [AnyTypeIfThenElseDict](#anytypeifthenelsedict), str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | [AnyTypeIfThenElseDict](#anytypeifthenelsedict), str, float, int, bool, None, tuple, bytes, io.FileIO | a constructor
44+
get_additional_property_ | str | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO, schemas.Unset | provides type safety for additional properties
45+
46+
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)

0 commit comments

Comments
 (0)