rest-framework icon indicating copy to clipboard operation
rest-framework copied to clipboard

[FIX] 14.0 pydantic: generate schema using field name

Open PierrickBrun opened this issue 3 years ago • 3 comments

ref: https://pydantic-docs.helpmanual.io/usage/schema/

The schema is generated by default using aliases as keys, but it can be generated using model property names instead by calling MainModel.schema/schema_json(by_alias=False).

Before:

generated schema uses aliases (odoo's internal naming) to name fields.

The schema does not correspond to what's effectively returned.

Capture d’écran du 2022-08-10 14-44-14

After:

generated schema uses the field's name, masking odoo's internal naming.

The schema corresponds to what's effectively returned.

Capture d’écran du 2022-08-10 14-44-38

PierrickBrun avatar Aug 10 '22 12:08 PierrickBrun

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

OCA-git-bot avatar Sep 03 '22 02:09 OCA-git-bot

I second the need for this change. Should we also change it for the params?

https://github.com/OCA/rest-framework/blob/6cf2dc90bd0f9a21f0385d3acc51273d8bbfb8f1/base_rest_pydantic/restapi.py#L56-L59

jeremi avatar Sep 04 '22 15:09 jeremi

I second the need for this change. Should we also change it for the params?

https://github.com/OCA/rest-framework/blob/6cf2dc90bd0f9a21f0385d3acc51273d8bbfb8f1/base_rest_pydantic/restapi.py#L56-L59

I don't think so because I don't notice this problem on query parameters

Capture d’écran du 2022-09-07 17-07-45

PierrickBrun avatar Sep 07 '22 15:09 PierrickBrun

/ocabot merge patch

lmignon avatar Dec 20 '22 13:12 lmignon

On my way to merge this fine PR! Prepared branch 14.0-ocabot-merge-pr-277-by-lmignon-bump-patch, awaiting test results.

OCA-git-bot avatar Dec 20 '22 13:12 OCA-git-bot

Congratulations, your PR was merged at 9338361be3fe0cde6d6ab61fd67f6fb1b224902d. Thanks a lot for contributing to OCA. ❤️

OCA-git-bot avatar Dec 20 '22 13:12 OCA-git-bot