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

Commit a129d3d

Browse files
authored
Adds 3.1.0 dependentRequired (#212)
* Writes out dependent_required info in two schemas * Adds tests of dependent_required component schemas * Samples regen * Adds DependentRequired schema feature and turns it on in python generator docs
1 parent 8318ab9 commit a129d3d

File tree

34 files changed

+348
-3
lines changed

34 files changed

+348
-3
lines changed

docs/generators/java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
319319
|Const|✗|OAS3
320320
|Contains|✗|OAS3
321321
|Default|✗|OAS2,OAS3
322+
|DependentRequired|✗|OAS3
322323
|Discriminator|✓|OAS2,OAS3
323324
|Enum|✓|OAS2,OAS3
324325
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/jaxrs-jersey.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
302302
|Const|✗|OAS3
303303
|Contains|✗|OAS3
304304
|Default|✗|OAS2,OAS3
305+
|DependentRequired|✗|OAS3
305306
|Discriminator|✓|OAS2,OAS3
306307
|Enum|✓|OAS2,OAS3
307308
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/jmeter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
161161
|Const|✗|OAS3
162162
|Contains|✗|OAS3
163163
|Default|✗|OAS2,OAS3
164+
|DependentRequired|✗|OAS3
164165
|Discriminator|✓|OAS2,OAS3
165166
|Enum|✓|OAS2,OAS3
166167
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/kotlin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
271271
|Const|✗|OAS3
272272
|Contains|✗|OAS3
273273
|Default|✗|OAS2,OAS3
274+
|DependentRequired|✗|OAS3
274275
|Discriminator|✓|OAS2,OAS3
275276
|Enum|✓|OAS2,OAS3
276277
|ExclusiveMinimum|✓|OAS2,OAS3

docs/generators/python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
230230
|Const|✓|OAS3
231231
|Contains|✓|OAS3
232232
|Default|✓|OAS2,OAS3
233+
|DependentRequired|✓|OAS3
233234
|Discriminator|✓|OAS2,OAS3
234235
|Enum|✓|OAS2,OAS3
235236
|ExclusiveMinimum|✓|OAS2,OAS3

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'any_of': 'anyOf',
1919
'const_value_to_name': 'const',
2020
'contains': 'contains',
21+
'dependent_required': 'dependentRequired',
2122
'discriminator': 'discriminator',
2223
# default omitted because it has no validation impact
2324
'enum_value_to_name': 'enum',

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,26 @@ def validate_const(
10611061
return None
10621062

10631063

1064+
def validate_dependent_required(
1065+
arg: typing.Any,
1066+
dependent_required: typing.Mapping[str, typing.Set[str]],
1067+
cls: typing.Type,
1068+
validation_metadata: ValidationMetadata,
1069+
) -> None:
1070+
if not isinstance(arg, immutabledict):
1071+
return None
1072+
for key, keys_that_must_exist in dependent_required.items():
1073+
if key not in arg:
1074+
continue
1075+
missing_keys = keys_that_must_exist - arg.keys()
1076+
if missing_keys:
1077+
raise exceptions.ApiValueError(
1078+
f"Validation failed for dependentRequired because these_keys={missing_keys} are "
1079+
f"missing at path_to_item={validation_metadata.path_to_item} in class {cls}"
1080+
)
1081+
return None
1082+
1083+
10641084
validator_type = typing.Callable[[typing.Any, typing.Any, type, ValidationMetadata], typing.Optional[PathToSchemasType]]
10651085
json_schema_keyword_to_validator: typing.Mapping[str, validator_type] = {
10661086
'types': validate_types,
@@ -1092,4 +1112,5 @@ def validate_const(
10921112
'min_contains': validate_min_contains,
10931113
'max_contains': validate_max_contains,
10941114
'const_value_to_name': validate_const,
1115+
'dependent_required': validate_dependent_required,
10951116
}

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
@@ -5,11 +5,13 @@ README.md
55
docs/apis/tags/default_api.md
66
docs/components/schema/any_type_const_string.md
77
docs/components/schema/any_type_contains_value.md
8+
docs/components/schema/any_type_dependent_required.md
89
docs/components/schema/any_type_max_contains_value.md
910
docs/components/schema/any_type_min_contains_value.md
1011
docs/components/schema/array_contains_value.md
1112
docs/components/schema/array_max_contains_value.md
1213
docs/components/schema/array_min_contains_value.md
14+
docs/components/schema/object_dependent_required.md
1315
docs/components/schema/string_const_string.md
1416
docs/paths/some_path/get.md
1517
docs/paths/some_path/get/responses/response_200/content/application_json/schema.md
@@ -33,11 +35,13 @@ src/json_schema_api/components/__init__.py
3335
src/json_schema_api/components/schema/__init__.py
3436
src/json_schema_api/components/schema/any_type_const_string.py
3537
src/json_schema_api/components/schema/any_type_contains_value.py
38+
src/json_schema_api/components/schema/any_type_dependent_required.py
3639
src/json_schema_api/components/schema/any_type_max_contains_value.py
3740
src/json_schema_api/components/schema/any_type_min_contains_value.py
3841
src/json_schema_api/components/schema/array_contains_value.py
3942
src/json_schema_api/components/schema/array_max_contains_value.py
4043
src/json_schema_api/components/schema/array_min_contains_value.py
44+
src/json_schema_api/components/schema/object_dependent_required.py
4145
src/json_schema_api/components/schema/string_const_string.py
4246
src/json_schema_api/components/schemas/__init__.py
4347
src/json_schema_api/configurations/__init__.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
@@ -175,11 +175,13 @@ Class | Description
175175
----- | ------------
176176
[AnyTypeConstString](docs/components/schema/any_type_const_string.md) |
177177
[AnyTypeContainsValue](docs/components/schema/any_type_contains_value.md) |
178+
[AnyTypeDependentRequired](docs/components/schema/any_type_dependent_required.md) |
178179
[AnyTypeMaxContainsValue](docs/components/schema/any_type_max_contains_value.md) |
179180
[AnyTypeMinContainsValue](docs/components/schema/any_type_min_contains_value.md) |
180181
[ArrayContainsValue](docs/components/schema/array_contains_value.md) |
181182
[ArrayMaxContainsValue](docs/components/schema/array_max_contains_value.md) |
182183
[ArrayMinContainsValue](docs/components/schema/array_min_contains_value.md) |
184+
[ObjectDependentRequired](docs/components/schema/object_dependent_required.md) |
183185
[StringConstString](docs/components/schema/string_const_string.md) |
184186

185187
## Notes for Large OpenAPI documents
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AnyTypeDependentRequired
2+
json_schema_api.components.schema.any_type_dependent_required
3+
```
4+
type: schemas.Schema
5+
```
6+
7+
## validate method
8+
Input Type | Return Type | Notes
9+
------------ | ------------- | -------------
10+
dict, schemas.immutabledict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | schemas.immutabledict, str, float, int, bool, None, tuple, bytes, io.FileIO |
11+
12+
[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)

0 commit comments

Comments
 (0)