strapi / documentation

Strapi Documentation
https://docs.strapi.io
Other
1.03k stars 1.13k forks source link

fix(controllers): :memo: list correct paths to custom sanitization methods #2277

Closed DomDew closed 5 days ago

DomDew commented 3 weeks ago

What does it do?

Lists the sanitization and validation methods from the contentApi as methods of the global strapi namespace.

Why is it needed?

With the update to v5 the validate and sanitize methods exported from the @strapi/utils package no longer expose the validation and sanitization methods through the contentApi. Instead, they would now have to be accessed through the createAPISanitizers or createAPIValidators methods, which would need to take a getModel callback as a mandatory argument. This would make custom validation code a tiny bit more cluttered.

In keeping consistent with the existing pattern as described by the current documentation, they could however still be accessed from the contentApi key from global strapi namespace.

Either way, the documentation needs to be corrected in either describing custom validation using the createAPISanitizers or by accessing the contentApi from the global namespace.

Let me know what is more in line with you design philosophy and I'll gladly update the docs ✌️.

Thanks for the great project 🀝

Related issue(s)/PR(s)

Let us know if this is related to any issue/pull request

strapi-cla commented 3 weeks ago

CLA assistant check
All committers have signed the CLA.

vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
documentation βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Oct 29, 2024 3:50pm
pwizla commented 3 weeks ago

Thank you so much for your contribution and effort, @DomDew!

I'll add a developer from the Strapi core team as a reviewer (cc @innerdvations). At the moment I'm not 100% sure whether we want to expose these methods in the public documentation or not. Apart from that, from a pure technical writing point of view, your PR looks great! πŸ‘Œ

DomDew commented 1 week ago

Hey hey @pwizla,

just to follow up:

The approach with accessing the validate and sanitize functions through the strapi.contentApi function is listed as the official migration approach in the breaking changes guide for v4 to v5.

Meaning the PR would update the docs to what is described in the migration guide - I overlooked that prior.