Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema used is mutating inside validation process #24

Closed
Larox opened this issue Nov 25, 2021 · 1 comment
Closed

Schema used is mutating inside validation process #24

Larox opened this issue Nov 25, 2021 · 1 comment

Comments

@Larox
Copy link
Contributor

Larox commented Nov 25, 2021

Hi all! First of all thanks for providing this tool. It has helped my projects a lot.

I find an issue related to the schema used for the validation. There is an _schema.update(...) in https://github.com/p1c2u/openapi-schema-validator/blob/ab7222af0597ebc672f93cc7f7e089897aba1bec/openapi_schema_validator/validators.py#L68-L72 that is mutating the schema adding nullable: False property in all the fields that doesn't have it.

This schema mutation is generating some issues at the time of using the schema in other features like generating default values and in tests that are expecting the schema without changes.

I'll be happy to work on this and submit a PR.

Steps to reproduce

  • Create a schema that doesn't have the nullable property
  • Use validate(...) function with the instance and the schema
  • Now the schema contains the nullable property

Expected Behaviour

  • The schema shouldn't have changed

Code used as an example for showing the issue

from openapi_schema_validator import validate
schema = {
    "type": "object",
    'properties': {
        'email': {
            'type': 'string'
        },
        'enabled': {
            'type': 'boolean',
        }
    },
    'example': {'enabled': False, 'email': "foo@bar.com"}
}

validate({"email": "foo@bar.com"}, schema)
# schema after the validation
{
    'type': 'object',
    'properties': {
        'email': {
            'type': 'string',
+           'nullable': False
        },
        'enabled': {
            'type': 'boolean',
        }
    },
    'example': {
        'enabled': False,
        'email': "foo@bar.com"
    },
+   'nullable': False
}
@p1c2u
Copy link
Collaborator

p1c2u commented Dec 28, 2021

Fix merged hence closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants