Skip to content

[Bug]: extra_format_unmarshallers get lost when instantiating V31RequestUnmarshaller #821

Closed

Description

@claeyswo

Actual Behavior

I'm trying to instantiate a V31RequestUnmarshaller with extra_format_unmarshallers. Sometime during the initialization process however they get overwritten with None. No problem for the V31ResponseUnmarshaller

Expected Behavior

That the extra_format_unmarshallers dict is equal to the one I provide.

Steps to Reproduce

from jsonschema_path import SchemaPath

from openapi_core.unmarshalling.request import V31RequestUnmarshaller
from openapi_core.unmarshalling.response import V31ResponseUnmarshaller

spec_dict = {
    "openapi": "3.1.0",
    "info": {"version": "1.0.0", "title": "Foo"},
    "paths": {
        "/hello": {
            "post": {
                "requestBody": {
                    "required": True,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": ["id"],
                                "properties": {
                                    "id": {"type": "string", "format": "parse-id"}
                                },
                            }
                        }
                    },
                },
                "responses": {
                    "200": {"description": "Say hello"},
                    "400": {"description": "Bad Request"},
                },
            }
        }
    },
}

spec = SchemaPath.from_dict(spec_dict)

v31_request_unmarshaller = V31RequestUnmarshaller(
    spec, extra_format_unmarshallers={"parse-id": lambda x: x}
)
v31_response_unmarshaller = V31ResponseUnmarshaller(
    spec, extra_format_unmarshallers={"parse-id": lambda x: x}
)
print(v31_request_unmarshaller.extra_format_unmarshallers)
print(v31_response_unmarshaller.extra_format_unmarshallers)

Output:

None
{'parse-id': <function <lambda> at 0x79a6dc363e20>}

OpenAPI Core Version

0.19.0

OpenAPI Core Integration

pyramid_openapi3

Affected Area(s)

No response

References

No response

Anything else we need to know?

No response

Would you like to implement a fix?

None

Activity

  1. p1c2u commented on Mar 28, 2024

    @p1c2u
    Collaborator

    Hi @claeyswo thanks for the report.

    This one looks similar to #802. The fix is in the latest master.

  2. claeyswo commented on Mar 29, 2024

    @claeyswo
    Author

    That seems to be the problem. Any thoughts on when this will be released?

  3. YitingTinaRen commented on Apr 2, 2024

    @YitingTinaRen

    Hello,

    I encountered the same issue with V30RequestUnmarshaller integrated in django framework. I only need to unmarshal the request data, so I did not test the response unmarshaller.

    Allow me to reuse the statement of @claeyswo, modified with my situation.

    Actual Behavior
    I'm trying to instantiate a V30RequestUnmarshaller with extra_format_unmarshallers. Sometime during the initialization process however they get overwritten with None.

    Expected Behavior
    That the extra_format_unmarshallers dict is equal to the one I provide.

    Steps to Reproduce

    from openapi_core.unmarshalling.request import V30RequestUnmarshaller
    from openapi_core import OpenAPI, Config
    from datetime import datetime
    
    def unmarshal_iso_datetime(value):
        return datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
    extra_format_unmarshallers = {
        'iso_datetime': unmarshal_iso_datetime,
    }
    config = Config(extra_format_unmarshallers=extra_format_unmarshallers)
    OPENAPI = OpenAPI.from_file_path('index.yaml', config=config)
    v30_request_unmarshaller = V30RequestUnmarshaller(
        OPENAPI, extra_format_unmarshallers=extra_format_unmarshallers
    )
    print(v30_request_unmarshaller.extra_format_unmarshallers)
    

    The above code snippet returns None.

    where the index.yaml is the following:

    openapi: 3.0.1
    servers:
      - url: http://0.0.0.0:8004/
        description: Local Debug Server
    info:
      version: 2.0.0
      title: test
    paths:
      /test/:
        post:
          tags:
            - test
          summary: test
          description: test
          operationId: test
          requestBody:
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    create_date:
                      type: string
                      format: iso_datetime
                      example: '2023-02-09 09:00:00'
                  required:
                    - create_date
          responses:
            '200':
              description: Success
              content:
                application/json: {}
    

    OpenAPI Core Version
    0.19.0

    OpenAPI Core Integration
    django

  4. p1c2u commented on Apr 10, 2024

    @p1c2u
    Collaborator

    Fixed with #802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugIndicates an issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions