openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

Body from `RequestValidationResult` not a dict anymore

Open diogobaeder opened this issue 6 years ago • 3 comments

Hi guys,

I upgraded openapi-core on my project to 0.6.0, and now when I get an instance of RequestValidationResult and try to access the request body, it's a Model instance now, and I can't get it easily transformed to a plain dictionary to be used elsewhere - for example with dacite.from_dict, which I'm also using together with openapi-core.

I could get the plain dict body from the Flask request instead, but it would be nice if I could keep using the result.body instead, as this leads to a better design - it makes it clear that the body was validated.

Any suggestions on how I should proceed? Can the library receive an implementation change so that it's easier to get the dict representation of the model? Or should I go on and use Flask's request object instead?

Thanks, Diogo

diogobaeder avatar Sep 06 '18 18:09 diogobaeder

@diogobaeder Hi. I plan to add model factory as configuration option for now you can use result.body. __dict__ which returns all model parameters in dict.

p1c2u avatar Sep 06 '18 19:09 p1c2u

Hey @p1c2u , thanks for the quick response :-)

That doesn't work for me, unfortunately... I tried it earlier today and it doesn't quite work because of nested models (__dict__ doesn't cast the items). For now I'm using request.json from Flask, as a clean workaround.

Cheers!

diogobaeder avatar Sep 06 '18 20:09 diogobaeder

@p1c2u would RequestValidationResult be the model factory one can override?

domenkozar avatar Sep 14 '18 13:09 domenkozar