Skip to content

Schema used is mutating inside validation process #24

@Larox

Description

@Larox

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': "[email protected]"}
}

validate({"email": "[email protected]"}, schema)
# schema after the validation
{
    'type': 'object',
    'properties': {
        'email': {
            'type': 'string',
+           'nullable': False
        },
        'enabled': {
            'type': 'boolean',
        }
    },
    'example': {
        'enabled': False,
        'email': "[email protected]"
    },
+   'nullable': False
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions