Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|DependentRequired|✗|OAS3
|DependentSchemas|✗|OAS3
|Discriminator|✓|OAS2,OAS3
|Else|✗|OAS3
|Enum|✓|OAS2,OAS3
|ExclusiveMinimum|✓|OAS2,OAS3
|ExclusiveMaximum|✓|OAS2,OAS3
|Format|✓|OAS2,OAS3
|If|✗|OAS3
|Items|✓|OAS2,OAS3
|MaxContains|✗|OAS3
|MaxItems|✓|OAS2,OAS3
Expand All @@ -347,6 +349,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Properties|✓|OAS2,OAS3
|PropertyNames|✗|OAS3
|Required|✓|OAS2,OAS3
|Then|✗|OAS3
|Type|✓|OAS2,OAS3
|UnevaluatedItems|✗|OAS3
|UnevaluatedProperties|✗|OAS3
Expand Down
3 changes: 3 additions & 0 deletions docs/generators/jaxrs-jersey.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|DependentRequired|✗|OAS3
|DependentSchemas|✗|OAS3
|Discriminator|✓|OAS2,OAS3
|Else|✗|OAS3
|Enum|✓|OAS2,OAS3
|ExclusiveMinimum|✓|OAS2,OAS3
|ExclusiveMaximum|✓|OAS2,OAS3
|Format|✓|OAS2,OAS3
|If|✗|OAS3
|Items|✓|OAS2,OAS3
|MaxContains|✗|OAS3
|MaxItems|✓|OAS2,OAS3
Expand All @@ -330,6 +332,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Properties|✓|OAS2,OAS3
|PropertyNames|✗|OAS3
|Required|✓|OAS2,OAS3
|Then|✗|OAS3
|Type|✓|OAS2,OAS3
|UnevaluatedItems|✗|OAS3
|UnevaluatedProperties|✗|OAS3
Expand Down
3 changes: 3 additions & 0 deletions docs/generators/jmeter.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|DependentRequired|✗|OAS3
|DependentSchemas|✗|OAS3
|Discriminator|✓|OAS2,OAS3
|Else|✗|OAS3
|Enum|✓|OAS2,OAS3
|ExclusiveMinimum|✓|OAS2,OAS3
|ExclusiveMaximum|✓|OAS2,OAS3
|Format|✓|OAS2,OAS3
|If|✗|OAS3
|Items|✓|OAS2,OAS3
|MaxContains|✗|OAS3
|MaxItems|✓|OAS2,OAS3
Expand All @@ -189,6 +191,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Properties|✓|OAS2,OAS3
|PropertyNames|✗|OAS3
|Required|✓|OAS2,OAS3
|Then|✗|OAS3
|Type|✓|OAS2,OAS3
|UnevaluatedItems|✗|OAS3
|UnevaluatedProperties|✗|OAS3
Expand Down
3 changes: 3 additions & 0 deletions docs/generators/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|DependentRequired|✗|OAS3
|DependentSchemas|✗|OAS3
|Discriminator|✓|OAS2,OAS3
|Else|✗|OAS3
|Enum|✓|OAS2,OAS3
|ExclusiveMinimum|✓|OAS2,OAS3
|ExclusiveMaximum|✓|OAS2,OAS3
|Format|✓|OAS2,OAS3
|If|✗|OAS3
|Items|✓|OAS2,OAS3
|MaxContains|✗|OAS3
|MaxItems|✓|OAS2,OAS3
Expand All @@ -299,6 +301,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Properties|✓|OAS2,OAS3
|PropertyNames|✗|OAS3
|Required|✓|OAS2,OAS3
|Then|✗|OAS3
|Type|✓|OAS2,OAS3
|UnevaluatedItems|✗|OAS3
|UnevaluatedProperties|✗|OAS3
Expand Down
3 changes: 3 additions & 0 deletions docs/generators/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|DependentRequired|✓|OAS3
|DependentSchemas|✓|OAS3
|Discriminator|✓|OAS2,OAS3
|Else|✓|OAS3
|Enum|✓|OAS2,OAS3
|ExclusiveMinimum|✓|OAS2,OAS3
|ExclusiveMaximum|✓|OAS2,OAS3
|Format|✓|OAS2,OAS3
|If|✓|OAS3
|Items|✓|OAS2,OAS3
|MaxContains|✓|OAS3
|MaxItems|✓|OAS2,OAS3
Expand All @@ -258,6 +260,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Properties|✓|OAS2,OAS3
|PropertyNames|✓|OAS3
|Required|✓|OAS2,OAS3
|Then|✓|OAS3
|Type|✓|OAS2,OAS3
|UnevaluatedItems|✓|OAS3
|UnevaluatedProperties|✓|OAS3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
'dependent_schemas': 'dependentSchemas',
'discriminator': 'discriminator',
# default omitted because it has no validation impact
'else_': 'else',
'enum_value_to_name': 'enum',
'exclusive_maximum': 'exclusiveMaximum',
'exclusive_minimum': 'exclusiveMinimum',
'format': 'format',
'if_': 'if',
'inclusive_maximum': 'maximum',
'inclusive_minimum': 'minimum',
'items': 'items',
Expand All @@ -46,6 +48,7 @@
'properties': 'properties',
'property_names': 'propertyNames',
'required': 'required',
'then': 'then',
'types': 'type',
'unique_items': 'uniqueItems',
'unevaluated_items': 'unevaluatedItems',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ def _validate(
validation_metadata,
path_to_schemas
)
if_path_to_schemas = None
if 'if_' in vars(cls_schema):
if_path_to_schemas = _get_if_path_to_schemas(
arg,
vars(cls_schema)['if_'],
validation_metadata,
)
validated_pattern_properties: typing.Optional[PathToSchemasType] = None
if 'pattern_properties' in vars(cls_schema):
validated_pattern_properties = _get_validated_pattern_properties(
Expand All @@ -123,6 +130,8 @@ def _validate(
used_val = (val, format)
elif keyword in {'pattern_properties', 'additional_properties'}:
used_val = (val, validated_pattern_properties)
elif keyword in {'if_', 'then', 'else_'}:
used_val = (val, if_path_to_schemas)
else:
used_val = val
validator = json_schema_keyword_to_validator[keyword]
Expand Down Expand Up @@ -1005,6 +1014,108 @@ def validate_discriminator(
return discriminated_cls._validate(arg, validation_metadata=updated_vm)


def _get_if_path_to_schemas(
arg: typing.Any,
if_cls: typing.Type[SchemaValidator],
validation_metadata: ValidationMetadata,
) -> PathToSchemasType:
if_cls = _get_class(if_cls)
these_path_to_schemas: PathToSchemasType = {}
try:
other_path_to_schemas = if_cls._validate(
arg, validation_metadata=validation_metadata)
update(these_path_to_schemas, other_path_to_schemas)
except exceptions.OpenApiException:
pass
return these_path_to_schemas


def validate_if(
arg: typing.Any,
if_cls_if_path_to_schemas: typing.Tuple[
typing.Type[SchemaValidator], typing.Optional[PathToSchemasType]
],
cls: typing.Type,
validation_metadata: ValidationMetadata,
) -> typing.Optional[PathToSchemasType]:
if_path_to_schemas = if_cls_if_path_to_schemas[1]
if if_path_to_schemas is None:
raise exceptions.OpenApiException('Invalid type for if_path_to_schemas')
"""
if is false use case
if_path_to_schemas == {}
no need to add any data to path_to_schemas

if true, then true -> true for whole schema
so validate_then will add if_path_to_schemas data to path_to_schemas
"""
return None


def validate_then(
arg: typing.Any,
then_cls_if_path_to_schemas: typing.Tuple[
typing.Type[SchemaValidator], typing.Optional[PathToSchemasType]
],
cls: typing.Type,
validation_metadata: ValidationMetadata,
) -> typing.Optional[PathToSchemasType]:
if_path_to_schemas = then_cls_if_path_to_schemas[1]
if if_path_to_schemas is None:
# use case: there is no if
return None
"""
if is false use case
if_path_to_schemas == {}
no need to add any data to path_to_schemas
"""
if not if_path_to_schemas:
return None
then_cls = _get_class(then_cls_if_path_to_schemas[0])
these_path_to_schemas: PathToSchemasType = {}
try:
other_path_to_schemas = then_cls._validate(
arg, validation_metadata=validation_metadata)
update(these_path_to_schemas, if_path_to_schemas)
update(these_path_to_schemas, other_path_to_schemas)
return these_path_to_schemas
except exceptions.OpenApiException as ex:
# then False case
raise ex


def validate_else(
arg: typing.Any,
else_cls_if_path_to_schemas: typing.Tuple[
typing.Type[SchemaValidator], typing.Optional[PathToSchemasType]
],
cls: typing.Type,
validation_metadata: ValidationMetadata,
) -> typing.Optional[PathToSchemasType]:
if_path_to_schemas = else_cls_if_path_to_schemas[1]
if if_path_to_schemas is None:
# use case: there is no if
return None
if if_path_to_schemas:
# skip validation if if_path_to_schemas was true
return None
"""
if is false use case
if_path_to_schemas == {}
"""
else_cls = _get_class(else_cls_if_path_to_schemas[0])
these_path_to_schemas: PathToSchemasType = {}
try:
other_path_to_schemas = else_cls._validate(
arg, validation_metadata=validation_metadata)
update(these_path_to_schemas, if_path_to_schemas)
update(these_path_to_schemas, other_path_to_schemas)
return these_path_to_schemas
except exceptions.OpenApiException as ex:
# else False case
raise ex


def _get_contains_qty(
arg: typing.Any,
contains_cls: typing.Type[SchemaValidator],
Expand Down Expand Up @@ -1326,5 +1437,8 @@ def validate_unevaluated_properties(
'pattern_properties': validate_pattern_properties,
'prefix_items': validate_prefix_items,
'unevaluated_items': validate_unevaluated_items,
'unevaluated_properties': validate_unevaluated_properties
'unevaluated_properties': validate_unevaluated_properties,
'if_': validate_if,
'then': validate_then,
'else_': validate_else
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ docs/components/schema/any_type_const_string.md
docs/components/schema/any_type_contains_value.md
docs/components/schema/any_type_dependent_required.md
docs/components/schema/any_type_dependent_schemas.md
docs/components/schema/any_type_if_then_else.md
docs/components/schema/any_type_max_contains_value.md
docs/components/schema/any_type_min_contains_value.md
docs/components/schema/any_type_pattern_properties.md
Expand All @@ -27,6 +28,7 @@ docs/components/schema/array_prefix_items.md
docs/components/schema/array_unevaluated_items_false_with_prefix_items.md
docs/components/schema/object_dependent_required.md
docs/components/schema/object_dependent_schemas.md
docs/components/schema/object_if_then_else.md
docs/components/schema/object_pattern_properties.md
docs/components/schema/object_property_names.md
docs/components/schema/object_unevaluated_properties_false_with_properties.md
Expand Down Expand Up @@ -55,6 +57,7 @@ src/json_schema_api/components/schema/any_type_const_string.py
src/json_schema_api/components/schema/any_type_contains_value.py
src/json_schema_api/components/schema/any_type_dependent_required.py
src/json_schema_api/components/schema/any_type_dependent_schemas.py
src/json_schema_api/components/schema/any_type_if_then_else.py
src/json_schema_api/components/schema/any_type_max_contains_value.py
src/json_schema_api/components/schema/any_type_min_contains_value.py
src/json_schema_api/components/schema/any_type_pattern_properties.py
Expand All @@ -75,6 +78,7 @@ src/json_schema_api/components/schema/array_prefix_items.py
src/json_schema_api/components/schema/array_unevaluated_items_false_with_prefix_items.py
src/json_schema_api/components/schema/object_dependent_required.py
src/json_schema_api/components/schema/object_dependent_schemas.py
src/json_schema_api/components/schema/object_if_then_else.py
src/json_schema_api/components/schema/object_pattern_properties.py
src/json_schema_api/components/schema/object_property_names.py
src/json_schema_api/components/schema/object_unevaluated_properties_false_with_properties.py
Expand Down
2 changes: 2 additions & 0 deletions samples/client/3_1_0_json_schema/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Class | Description
[AnyTypeContainsValue](docs/components/schema/any_type_contains_value.md) |
[AnyTypeDependentRequired](docs/components/schema/any_type_dependent_required.md) |
[AnyTypeDependentSchemas](docs/components/schema/any_type_dependent_schemas.md) |
[AnyTypeIfThenElse](docs/components/schema/any_type_if_then_else.md) |
[AnyTypeMaxContainsValue](docs/components/schema/any_type_max_contains_value.md) |
[AnyTypeMinContainsValue](docs/components/schema/any_type_min_contains_value.md) |
[AnyTypePatternProperties](docs/components/schema/any_type_pattern_properties.md) |
Expand All @@ -197,6 +198,7 @@ Class | Description
[ArrayUnevaluatedItemsFalseWithPrefixItems](docs/components/schema/array_unevaluated_items_false_with_prefix_items.md) |
[ObjectDependentRequired](docs/components/schema/object_dependent_required.md) |
[ObjectDependentSchemas](docs/components/schema/object_dependent_schemas.md) |
[ObjectIfThenElse](docs/components/schema/object_if_then_else.md) |
[ObjectPatternProperties](docs/components/schema/object_pattern_properties.md) |
[ObjectPropertyNames](docs/components/schema/object_property_names.md) |
[ObjectUnevaluatedPropertiesFalseWithProperties](docs/components/schema/object_unevaluated_properties_false_with_properties.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# AnyTypeIfThenElse
json_schema_api.components.schema.any_type_if_then_else
```
type: schemas.Schema
```

## validate method
Input Type | Return Type | Notes
------------ | ------------- | -------------
[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 |

## AnyTypeIfThenElseDictInput
```
type: typing.Mapping[str, schemas.INPUT_TYPES_ALL]
```
Key | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**street_address** | str | | [optional]
**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
**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]

## AnyTypeIfThenElseDict
```
base class: schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]

```
### __new__ method
Keyword Argument | Type | Description | Notes
---------------- | ---- | ----------- | -----
**street_address** | str, schemas.Unset | | [optional]
**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
**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

### properties
Property | Type | Description | Notes
-------- | ---- | ----------- | -----
**street_address** | str, schemas.Unset | | [optional]
**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

### methods
Method | Input Type | Return Type | Notes
------ | ---------- | ----------- | ------
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
get_additional_property_ | str | schemas.immutabledict, tuple, float, int, str, bool, None, bytes, schemas.FileIO, schemas.Unset | provides type safety for additional properties

[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)
Loading