Skip to content

[19.0][ADD] endpoint_json2 - #135

Open
AungKoKoLin1997 wants to merge 1 commit into
OCA:19.0from
qrtl:19.0-add-endpoint_json2
Open

[19.0][ADD] endpoint_json2#135
AungKoKoLin1997 wants to merge 1 commit into
OCA:19.0from
qrtl:19.0-add-endpoint_json2

Conversation

@AungKoKoLin1997

Copy link
Copy Markdown

This module adds exec_mode="json2 to the endpoint framework, enabling declarative JSON-2 API endpoint configuration. Select a model, method, and parameters — the module handles dispatch, parameter validation, access control, and result filtering. A code snippet can be used as an alternative to a model method for quick, ad-hoc logic.

@qrtl QT6769

@simahawk

Copy link
Copy Markdown
Contributor

@AungKoKoLin1997 interesting approach. Early feedback: I don't think the mixin is the right place as it can be inherited by all extending models (eg: edi_endpoint). I tend to say endpoint.endpoint is better.

@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-add-endpoint_json2 branch from bd16156 to 26ae1fd Compare May 27, 2026 05:07
@AungKoKoLin1997

Copy link
Copy Markdown
Author

@simahawk Thanks for your feedback. I updated to use endpoint.endpoint instead of the mixin model.

Comment thread endpoint_json2/readme/CONFIGURE.md Outdated
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-add-endpoint_json2 branch from 26ae1fd to d74377a Compare June 2, 2026 09:24

@smorita7749 smorita7749 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional review: LGTM
The flow creating endpoint and getting response is properly working.

@simahawk

simahawk commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@ivantodorovich can you have a look at this?

@yostashiro
yostashiro force-pushed the 19.0-add-endpoint_json2 branch from d74377a to 3b7080c Compare July 26, 2026 14:13

@yostashiro yostashiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review and functional test.

Comment thread endpoint_json2/tests/common.py
Comment thread endpoint_json2/models/endpoint_endpoint.py
yostashiro added a commit to qrtl/ocj-oca that referenced this pull request Aug 9, 2026
…lds (#31)

[QT6769](https://www.quartile.co/web#id=6769&cids=3&menu_id=506&action=1457&model=project.task&view_type=form)

Lets an endpoint whose method is not `read`/`search_read` declare its response fields.

### Problem

`_check_json2_response_fields` validated every response field against the target model's fields, for every endpoint. That is correct when the method is `read` or `search_read`, whose result rows are made of model fields. It is wrong for any other method: the keys are the method's own, and the model has no way to know them.

A method returning a derived value therefore could not name it at all — declaring it raised `ValidationError`, so the only way forward was to leave `json2_response_fields` empty. That turns off filtering and aliasing entirely and leaves the payload implicit in the Python, invisible to anyone reading the endpoint record.

### Change

- Plain names are validated only for the methods in `FIELD_READING_METHODS` (`read`, `search_read`). That is a **policy list, not a taxonomy of the ORM** and is not meant to grow: `read_group` also returns model field values and is deliberately excluded, since its rows carry keys of its own (`__count`, `__domain`) too. A module wanting its own method checked should constrain it where the payload is defined, which can pin the exact keys rather than merely "is a field of the model".
- Dotted specs stay validated whatever the method is: `_json2_resolve_dotted_fields` resolves the base against `Model._fields` before fetching the related rows, so a base that is not a relational field can never resolve.
- The constraint now also depends on `json2_method`, so switching an endpoint back to `search_read` re-runs the check instead of leaving behind keys the model does not have.

Nothing changes at execution time: filtering, aliasing and dotted resolution were already applied to the result of any method, not only `search_read`.

### Notes

- `README.rst` is not regenerated — the `oca-gen-addon-readme` hook is commented out in this repository's `.pre-commit-config.yaml` (line 57), so `readme/CONFIGURE.md` is updated but the generated file is left alone rather than hand-edited.
- The same change is wanted upstream in OCA/web-api#135, which is still open.
- I could not execute the tests locally: `addons_path` is empty in this workspace's `odoo.conf` and a fresh database registered 667 modules with no `endpoint*` among them, so the namespace path did not include the repositories. Relying on CI here.
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-add-endpoint_json2 branch 2 times, most recently from 68f5b7d to bca7295 Compare August 10, 2026 03:07
@AungKoKoLin1997

Copy link
Copy Markdown
Author

I added a few changes.

  • Response Language (json2_lang_id): optionally forces the execution context language, so translated values (including dotted relational fields like uom_id.name) no longer depend on the API user's language setting.
  • Response Timezone (json2_tz): optionally converts datetimes in the response to the given timezone, rendered as local wall time without an offset (incoming datetime parameters are left as-is).
  • Align access / exec-target rules with the documentation: an empty Allowed Groups list rejects every caller, and Method / Code Snippet are truly mutually exclusive — both now backed by constraints so a data file or an import cannot create an endpoint that nobody can call, or one with both exec targets set.
  • Response fields for non-read methods: plain field names are validated only for read / search_read, whose rows are made of model fields. Other methods can now declare their own keys instead of leaving json2_response_fields empty (which disables filtering and aliasing entirely). Dotted specs stay validated for every method.
  • Tests: moved the test endpoints to their own route group so they no longer collide with the demo data route.

@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-add-endpoint_json2 branch from bca7295 to 2c6f947 Compare August 10, 2026 03:46
Assisted-by: Claude Opus 5
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-add-endpoint_json2 branch from 2c6f947 to ec926e3 Compare August 10, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants