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

Adds 3.1.0 contains feature #205

Merged
merged 9 commits into from
Aug 19, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ elif [ "$JOB_ID" = "testPythonClientSamples" ]; then
(cd samples/client/3_0_3_unit_test/python && make test)
(cd samples/client/openapi_features/nonCompliantUseDiscriminatorIfCompositionFails/python && make test)
(cd samples/client/openapi_features/security/python && make test)
(cd samples/client/3_1_0_json_schema/python && make test)

else
echo "Running job $JOB_ID"
Expand Down
5 changes: 5 additions & 0 deletions bin/generate_samples_configs/python_3_1_0_json_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
generatorName: python
outputDir: samples/client/3_1_0_json_schema/python
inputSpec: src/test/resources/3_1/json_schema.yaml
additionalProperties:
packageName: json_schema_api
1 change: 1 addition & 0 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|AdditionalProperties|✗|OAS2,OAS3
|AllOf|✗|OAS2,OAS3
|AnyOf|✗|OAS3
|Contains|✗|OAS3
|Default|✗|OAS2,OAS3
|Discriminator|✓|OAS2,OAS3
|Enum|✓|OAS2,OAS3
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jaxrs-jersey.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|AdditionalProperties|✗|OAS2,OAS3
|AllOf|✗|OAS2,OAS3
|AnyOf|✗|OAS3
|Contains|✗|OAS3
|Default|✗|OAS2,OAS3
|Discriminator|✓|OAS2,OAS3
|Enum|✓|OAS2,OAS3
Expand Down
1 change: 1 addition & 0 deletions docs/generators/jmeter.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|AdditionalProperties|✗|OAS2,OAS3
|AllOf|✗|OAS2,OAS3
|AnyOf|✗|OAS3
|Contains|✗|OAS3
|Default|✗|OAS2,OAS3
|Discriminator|✓|OAS2,OAS3
|Enum|✓|OAS2,OAS3
Expand Down
1 change: 1 addition & 0 deletions docs/generators/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|AdditionalProperties|✗|OAS2,OAS3
|AllOf|✗|OAS2,OAS3
|AnyOf|✗|OAS3
|Contains|✗|OAS3
|Default|✗|OAS2,OAS3
|Discriminator|✓|OAS2,OAS3
|Enum|✓|OAS2,OAS3
Expand Down
1 change: 1 addition & 0 deletions docs/generators/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|AdditionalProperties|✓|OAS2,OAS3
|AllOf|✓|OAS2,OAS3
|AnyOf|✓|OAS3
|Contains|✓|OAS3
|Default|✓|OAS2,OAS3
|Discriminator|✓|OAS2,OAS3
|Enum|✓|OAS2,OAS3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
"""Constructor
"""
# Authentication Settings
self.security_scheme_info = {}
self.security_scheme_info: typing.Dict[str, typing.Any] = {}
self.security_index_info = {'security': 0}
# Server Info
self.server_info: ServerInfo = server_info or {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'additional_properties': 'additionalProperties',
'all_of': 'allOf',
'any_of': 'anyOf',
'contains': 'contains',
'discriminator': 'discriminator',
# default omitted because it has no validation impact
'enum_value_to_name': 'enum',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,41 @@ def validate_discriminator(
return discriminated_cls._validate(arg, validation_metadata=updated_vm)


def validate_contains(
arg: typing.Any,
contains_cls: typing.Type[SchemaValidator],
cls: typing.Type,
validation_metadata: ValidationMetadata,
) -> typing.Optional[PathToSchemasType]:
if not isinstance(arg, tuple):
return None
contains_cls = _get_class(contains_cls)
path_to_schemas: PathToSchemasType = {}
array_contains_item = False
for i, value in enumerate(arg):
item_validation_metadata = ValidationMetadata(
path_to_item=validation_metadata.path_to_item+(i,),
configuration=validation_metadata.configuration,
validated_path_to_schemas=validation_metadata.validated_path_to_schemas
)
if item_validation_metadata.validation_ran_earlier(contains_cls):
add_deeper_validated_schemas(item_validation_metadata, path_to_schemas)
return path_to_schemas
try:
other_path_to_schemas = contains_cls._validate(
value, validation_metadata=item_validation_metadata)
update(path_to_schemas, other_path_to_schemas)
return path_to_schemas
except exceptions.OpenApiException:
pass
if not array_contains_item:
raise exceptions.ApiValueError(
"Validation failed for contains keyword in class={} at path_to_item={}. No "
"items validated to the contains schema.".format(cls, validation_metadata.path_to_item)
)
return path_to_schemas


validator_type = typing.Callable[[typing.Any, typing.Any, type, ValidationMetadata], typing.Optional[PathToSchemasType]]
json_schema_keyword_to_validator: typing.Mapping[str, validator_type] = {
'types': validate_types,
Expand All @@ -982,5 +1017,6 @@ def validate_discriminator(
'any_of': validate_any_of,
'all_of': validate_all_of,
'not_': validate_not,
'discriminator': validate_discriminator
'discriminator': validate_discriminator,
'contains': validate_contains
}
67 changes: 67 additions & 0 deletions samples/client/3_1_0_json_schema/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
dev-requirements.txt.log

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.venv/
.python-version
.pytest_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
15 changes: 15 additions & 0 deletions samples/client/3_1_0_json_schema/python/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ref: https://docs.gitlab.com/ee/ci/README.html

stages:
- test

.tests:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=json_schema_api

test-3.8:
extends: .tests
image: python:3.8-alpine
23 changes: 23 additions & 0 deletions samples/client/3_1_0_json_schema/python/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapi-json-schema-tools/openapi-json-schema-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
70 changes: 70 additions & 0 deletions samples/client/3_1_0_json_schema/python/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.gitignore
.gitlab-ci.yml
.travis.yml
README.md
docs/apis/tags/default_api.md
docs/components/schema/any_type_contains_value.md
docs/components/schema/array_contains_value.md
docs/paths/some_path/get.md
docs/paths/some_path/get/responses/response_200/content/application_json/schema.md
docs/servers/server_0.md
git_push.sh
migration_2_0_0.md
migration_3_0_0.md
migration_other_python_generators.md
pyproject.toml
src/json_schema_api/__init__.py
src/json_schema_api/api_client.py
src/json_schema_api/api_response.py
src/json_schema_api/apis/__init__.py
src/json_schema_api/apis/path_to_api.py
src/json_schema_api/apis/paths/__init__.py
src/json_schema_api/apis/paths/some_path.py
src/json_schema_api/apis/tag_to_api.py
src/json_schema_api/apis/tags/__init__.py
src/json_schema_api/apis/tags/default_api.py
src/json_schema_api/components/__init__.py
src/json_schema_api/components/schema/__init__.py
src/json_schema_api/components/schema/any_type_contains_value.py
src/json_schema_api/components/schema/array_contains_value.py
src/json_schema_api/components/schemas/__init__.py
src/json_schema_api/configurations/__init__.py
src/json_schema_api/configurations/api_configuration.py
src/json_schema_api/configurations/schema_configuration.py
src/json_schema_api/exceptions.py
src/json_schema_api/paths/__init__.py
src/json_schema_api/paths/some_path/__init__.py
src/json_schema_api/paths/some_path/get/__init__.py
src/json_schema_api/paths/some_path/get/operation.py
src/json_schema_api/paths/some_path/get/responses/__init__.py
src/json_schema_api/paths/some_path/get/responses/response_200/__init__.py
src/json_schema_api/paths/some_path/get/responses/response_200/content/__init__.py
src/json_schema_api/paths/some_path/get/responses/response_200/content/application_json/__init__.py
src/json_schema_api/paths/some_path/get/responses/response_200/content/application_json/schema.py
src/json_schema_api/py.typed
src/json_schema_api/rest.py
src/json_schema_api/schemas/__init__.py
src/json_schema_api/schemas/format.py
src/json_schema_api/schemas/original_immutabledict.py
src/json_schema_api/schemas/schema.py
src/json_schema_api/schemas/schemas.py
src/json_schema_api/schemas/validation.py
src/json_schema_api/security_schemes.py
src/json_schema_api/server.py
src/json_schema_api/servers/__init__.py
src/json_schema_api/servers/server_0.py
src/json_schema_api/shared_imports/__init__.py
src/json_schema_api/shared_imports/header_imports.py
src/json_schema_api/shared_imports/operation_imports.py
src/json_schema_api/shared_imports/response_imports.py
src/json_schema_api/shared_imports/schema_imports.py
src/json_schema_api/shared_imports/security_scheme_imports.py
src/json_schema_api/shared_imports/server_imports.py
test-requirements.txt
test/__init__.py
test/components/__init__.py
test/components/schema/__init__.py
test/test_paths/__init__.py
test/test_paths/test_some_path/__init__.py
test/test_paths/test_some_path/test_get.py
tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unset
11 changes: 11 additions & 0 deletions samples/client/3_1_0_json_schema/python/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "3.8"
- "3.9"
# command to install dependencies
install:
- "pip install -r requirements.txt"
- "pip install -r test-requirements.txt"
# command to run tests
script: pytest --cov=json_schema_api
13 changes: 13 additions & 0 deletions samples/client/3_1_0_json_schema/python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SETUP_OUT=*.egg-info
VENV=venv

clean:
rm -rf $(SETUP_OUT)
rm -rf $(VENV)
rm -rf .tox
rm -rf .coverage
find . -name "*.py[oc]" -delete
find . -name "__pycache__" -delete

test: clean
bash ./test_python.sh
Loading