Skip to content

[0.16.0 regression] TypeError: Field names must be valid identifiers #430

Closed
@andersk

Description

@andersk

As of commit c2e166e (#422), trying to validate {"0": "a"} against schema {"type": "object"} raises TypeError: Field names must be valid identifiers. This is a valid object, so no error should be raised.

This is likely to come up whenever an object is being used as an associative array rather than as a record with a fixed set of fields.

Test case:

from openapi_core import Spec
from openapi_core.testing import MockRequest
from openapi_core.validation.request import openapi_request_validator

spec = Spec.create(
    {
        "openapi": "3.0.3",
        "info": {"title": "test", "version": "0"},
        "paths": {
            "/url": {
                "post": {
                    "parameters": [
                        {
                            "name": "data",
                            "in": "query",
                            "content": {
                                "application/json": {
                                    "schema": {"type": "object"}
                                }
                            },
                        }
                    ],
                    "responses": {"200": {"description": "Success."}},
                }
            }
        },
    },
)
request = MockRequest(
    "http://localhost:9991/", "post", "/url", args={"data": '{"0": "a"}'}
)
result = openapi_request_validator.validate(spec, request)
print(result)
result.raise_for_errors()

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