[Bug]: extra_format_unmarshallers get lost when instantiating V31RequestUnmarshaller
claeyswo opened this issue · comments
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
That seems to be the problem. Any thoughts on when this will be released?
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