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

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

Closed
claeyswo opened this issue Mar 28, 2024 · 4 comments
Labels
kind/bug Indicates an issue

Comments

@claeyswo
Copy link

claeyswo commented Mar 28, 2024

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

@p1c2u
Copy link
Collaborator

p1c2u commented Mar 28, 2024

Hi @claeyswo thanks for the report.

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

@claeyswo
Copy link
Author

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

@YitingTinaRen
Copy link

YitingTinaRen commented Apr 2, 2024

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

@p1c2u
Copy link
Collaborator

p1c2u commented Apr 10, 2024

Fixed with #802

@p1c2u p1c2u closed this as completed Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Indicates an issue
Projects
None yet
Development

No branches or pull requests

3 participants