Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

improve logging in shortcuts.py and turn to pytest in test_shortcut.py#219

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
even-even wants to merge2 commits intopython-openapi:master
base:master
Choose a base branch
Loading
fromeven-even:improve_shotcuts_and_add_test
Open
Show file tree
Hide file tree
Changes fromall 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
2 changes: 1 addition & 1 deletiondocs/index.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@ Installation

.. md-tab-set::

.. md-tab-item:: Pip + PyPI (recommented)
.. md-tab-item:: Pip + PyPI (recommended)

.. code-block:: console

Expand Down
5 changes: 1 addition & 4 deletionsopenapi_schema_validator/_keywords.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
from copy import deepcopy
from typing import Any
from typing import Dict
from typing import Hashable
from typing import ItemsView
from typing import Iterator
from typing import List
from typing import Mapping
Expand DownExpand Up@@ -112,7 +109,7 @@ def type(
# * nullable: true is only meaningful in combination with a type
# assertion specified in the same Schema Object.
# * nullable: true operates within a single Schema Object
if "nullable" in schema and schema["nullable"]== True:
if "nullable" in schema and schema["nullable"]is True:
return
yield ValidationError("None for not nullable")

Expand Down
13 changes: 13 additions & 0 deletionsopenapi_schema_validator/shortcuts.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,19 @@ def validate(
*args: Any,
**kwargs: Any
) -> None:
"""
Validate an instance against a given schema using the specified validator class

Args:
instance: The instance to validate.
schema: The schema to validate against
cls: The validator class to use (defaults to OAS31Validator)
*args: Additional positional arguments to pass to the validator
**kwargs: Additional keyword arguments to pass to the validator

Raises:
jsonschema.exceptions.ValidationError: If the instance is invalid according to the schema
"""
cls.check_schema(schema)
validator = cls(schema, *args, **kwargs)
error = best_match(validator.evolve(schema=schema).iter_errors(instance))
Expand Down
4 changes: 0 additions & 4 deletionsopenapi_schema_validator/validators.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
import warnings
from typing import Any
from typing import Type

from jsonschema import _keywords
from jsonschema import _legacy_keywords
from jsonschema.validators import Draft202012Validator
Expand Down
42 changes: 27 additions & 15 deletionstests/unit/test_shortcut.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
from unittest import TestCase

import pytest
from openapi_schema_validator import validate


class ValidateTest(TestCase):
def test_validate_does_not_mutate_schema_adding_nullable_key(self):
schema = {
"type": "object",
"properties": {
"email": {"type": "string"},
"enabled": {
"type": "boolean",
},
@pytest.fixture(scope="function")
def schema():
return {
"type": "object",
"properties": {
"email": {"type": "string"},
"enabled": {
"type": "boolean",
},
"example": {"enabled": False, "email": "foo@bar.com"},
}
},
"example": {"enabled": False, "email": "foo@bar.com"},
}


def test_validate_does_not_add_nullable_to_schema(schema):
"""
Verify that calling validate does not add the 'nullable' key to the schema
"""
validate({"email": "foo@bar.com"}, schema)
assert "nullable" not in schema["properties"]["email"].keys()

validate({"email": "foo@bar.com"}, schema)

self.assertTrue("nullable" not in schema["properties"]["email"].keys())
def test_validate_does_not_mutate_schema(schema):
"""
Verify that calling validate does not mutate the schema
"""
original_schema = schema.copy()
validate({"email": "foo@bar.com"}, schema)
assert schema == original_schema

[8]ページ先頭

©2009-2025 Movatter.jp