python-openapi/openapi-core

[Bug]: `RequestUnmarshalResult` has wrong type for `body`

mtvx opened this issue · 0 comments

mtvx commented

Actual Behavior

unmarshal_request returns RequestUnmarshalResult which has body field defined as:

@dataclass
class RequestUnmarshalResult(BaseUnmarshalResult):
    body: str | None = None
    ...

But actually, at least with application/json or alike request body defined in the spec, this gets set to the validated/unmarshalled dict.

Maybe generics could be used there, but it would probably make things just complicated.

Anyway, the reality and the type hint are not matching.

Expected Behavior

It's nice to get that unmarshalled dict instead of str, but the type hint is wrong.

I guess the type hint should be changed to Any, because if the content type was e.g. text/plain then body would really get set to a str (or bytes, rather?).

Steps to Reproduce

Something like:

result = unmarshal_request(...)
print(type(result.body))

OpenAPI Core Version

0.19.3

OpenAPI Core Integration

custom

Affected Area(s)

No response

References

No response

Anything else we need to know?

No response

Would you like to implement a fix?

None