[codegen][python-experimental] Add configuration knob to disable JSON schema validation (#6227)

* Add knob to disable JSON schema structural validation

* Add knob to disable JSON schema structural validation

* Fix formatting issues

* execute sample scripts

* execute sample scripts

* fix multipleOf validation issue

* Add validation log for multipleOf. Add customizable validation checks. add unit tests for JSON schema validation

* Add validation log for multipleOf. Add customizable validation checks. add unit tests for JSON schema validation

* Add validation log for multipleOf. Add customizable validation checks. add unit tests for JSON schema validation

* Add validation log for multipleOf. Add customizable validation checks. add unit tests for JSON schema validation. Fix for python 2

* address review comments
This commit is contained in:
Sebastien Rosset
2020-05-17 09:11:01 -07:00
committed by GitHub
parent 04ff319502
commit b4954b0d80
30 changed files with 548 additions and 60 deletions

View File

@@ -20,8 +20,15 @@ import urllib3
import six
from six.moves import http_client as httplib
from petstore_api.exceptions import ApiValueError
JSON_SCHEMA_VALIDATION_KEYWORDS = {
'multipleOf', 'maximum', 'exclusiveMaximum',
'minimum', 'exclusiveMinimum', 'maxLength',
'minLength', 'pattern', 'maxItems', 'minItems'
}
class Configuration(object):
"""NOTE: This class is auto generated by OpenAPI Generator
@@ -49,6 +56,19 @@ class Configuration(object):
then all undeclared properties received by the server are injected into the
additional properties map. In that case, there are undeclared properties, and
nothing to discard.
:param disabled_client_side_validations (string): Comma-separated list of
JSON schema validation keywords to disable JSON schema structural validation
rules. The following keywords may be specified: multipleOf, maximum,
exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern,
maxItems, minItems.
By default, the validation is performed for data generated locally by the client
and data received from the server, independent of any validation performed by
the server side. If the input data does not satisfy the JSON schema validation
rules specified in the OpenAPI document, an exception is raised.
If disabled_client_side_validations is set, structural validation is
disabled. This can be useful to troubleshoot data validation problem, such as
when the OpenAPI document validation rules do not match the actual API data
received by the server.
:Example:
@@ -94,6 +114,7 @@ conf = petstore_api.Configuration(
api_key=None, api_key_prefix=None,
username=None, password=None,
discard_unknown_keys=False,
disabled_client_side_validations="",
):
"""Constructor
"""
@@ -124,6 +145,7 @@ conf = petstore_api.Configuration(
"""Password for HTTP basic authentication
"""
self.discard_unknown_keys = discard_unknown_keys
self.disabled_client_side_validations = disabled_client_side_validations
self.access_token = None
"""access token for OAuth/Bearer
"""
@@ -205,6 +227,13 @@ conf = petstore_api.Configuration(
def __setattr__(self, name, value):
object.__setattr__(self, name, value)
if name == 'disabled_client_side_validations':
s = set(filter(None, value.split(',')))
for v in s:
if v not in JSON_SCHEMA_VALIDATION_KEYWORDS:
raise ApiValueError(
"Invalid keyword: '{0}''".format(v))
self._disabled_client_side_validations = s
@classmethod
def set_default(cls, default):