chore: Strict payloads for update action and gen template API#34446
chore: Strict payloads for update action and gen template API#34446
Conversation
WalkthroughThe recent code changes primarily involve updating the payload structure in various APIs, ensuring more consistent and flexible handling of API requests. The updates target methods in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Outside diff range and nitpick comments (3)
app/client/src/api/AppThemingApi.tsx (1)
Line range hint
1-87: Consider refactoring class to use utility functions.The class
AppThemingApionly contains static members, which could be simplified into a set of utility functions. This would reduce the complexity and improve modularity.- class AppThemingApi extends API { + const AppThemingApi = { - static async fetchThemes(applicationId: string) { + async function fetchThemes(applicationId: string) { - ... - } + export { fetchThemes, fetchSelected, updateTheme, changeTheme, deleteTheme };app/client/src/api/ActionAPI.tsx (1)
Line range hint
125-264: Consider refactoring class to use utility functions.Similar to
AppThemingApi,ActionAPIcould benefit from being refactored into a set of utility functions instead of a class with only static methods.- class ActionAPI extends API { + const ActionAPI = { - static async createAction(apiConfig: Partial<Action>) { + async function createAction(apiConfig: Partial<Action>) { - ... - } + export { createAction, fetchActions, updateAction, deleteAction, moveAction };app/client/src/api/PageApi.tsx (1)
Line range hint
170-323: Consider refactoring class to use utility functions.
PageApialso only contains static members and could be simplified into a set of utility functions, enhancing modularity and reducing complexity.- class PageApi extends Api { + const PageApi = { - static async fetchPage(pageRequest: FetchPageRequest) { + async function fetchPage(pageRequest: FetchPageRequest) { - ... - } + export { fetchPage, savePage, createPage, updatePage, deletePage };Tools
Biome
[error] 271-273: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)
Unsafe fix: Omit the else clause.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- app/client/src/api/ActionAPI.tsx (2 hunks)
- app/client/src/api/AppThemingApi.tsx (1 hunks)
- app/client/src/api/PageApi.tsx (1 hunks)
Additional context used
Biome
app/client/src/api/AppThemingApi.tsx
[error] 5-87: Avoid classes that contain only static members. (lint/complexity/noStaticOnlyClass)
Prefer using simple functions instead of classes with only static members.
app/client/src/api/ActionAPI.tsx
[error] 125-264: Avoid classes that contain only static members. (lint/complexity/noStaticOnlyClass)
Prefer using simple functions instead of classes with only static members.
[error] 231-231: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 234-234: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.app/client/src/api/PageApi.tsx
[error] 170-323: Avoid classes that contain only static members. (lint/complexity/noStaticOnlyClass)
Prefer using simple functions instead of classes with only static members.
[error] 189-189: Avoid redundant double-negation. (lint/complexity/noExtraBooleanCast)
It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation
[error] 271-273: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)
Unsafe fix: Omit the else clause.
Additional comments not posted (4)
app/client/src/api/AppThemingApi.tsx (1)
48-54: Refactor to improve payload construction inupdateTheme.The payload construction in
updateThememethod explicitly setsnewtoundefined. This is a good practice to ensure the payload only contains the necessary data. However, consider documenting whynewis set toundefined.app/client/src/api/ActionAPI.tsx (2)
239-251: RefactormoveActionto improve payload construction.The
moveActionmethod follows a similar pattern toupdateActionfor payload construction. This consistency is good, but ensure the fields set toundefinedare documented for clarity.
174-195: Ensure consistency in payload structure forupdateAction.The method
updateActionnow constructs a payload that omits certain fields and sets others toundefined. This aligns with the PR's goal to make payloads stricter. Ensure that all fields set toundefinedare intentionally excluded and document the reason.app/client/src/api/PageApi.tsx (1)
265-272: Improve clarity ingenerateTemplatePagemethod.The payload construction in
generateTemplatePagesetspageIdtoundefinedbefore making the API call. This is likely to ensure thatpageIdis not mistakenly sent as part of the payload. Document this explicitly to avoid confusion.
Currently, if the incoming request body contains fields that aren't recognized by the backend, we just ignore them, and deserialize what we _can_. This has lead to subtle bugs and wasted a lot of developer time in the past, and added little value in return. Most recently, with application creation, now fixed in #33722. Another one, for action creation, client sends this in `eventData` field of the request body:  But the class defined for `eventData` is this:  Clearly isn't working. This PR enabled the `FAIL_ON_UNKNOWN_PROPERTIES` setting only for the deserialization of HTTP request payloads. It shouldn't have impact on other deserializations like those for Git, and those that load resource files. Primarily to limit the scope. This should also bring in some much-needed type strictness to the client as well. So far, server has been lax in accepting just any fields in the incoming request body, so client was able to afford being lax about the object that was sent up. We're enabling this restriction only for CE currently. Will be opening a similar PR on EE and once all tests pass there, we enable for EE as well. Depends on #33728 #33730 #33731 #34366 #34405 #34446 #34473 #34506 Run No. 1 > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9685619413> > Commit: 04e225f > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9685619413&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `` **/test all** <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9690185000> > Commit: 29da8b4 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9690185000&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `` <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added `certificateType` property to datasources for enhanced SSL configuration options. - **Enhancements** - Improved JSON deserialization behavior for better data handling and flexibility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…thorg#34446) Part of appsmithorg#33724. This PR fixes a few more APIs to pass just the fields that the server expects, and nothing more. /test sanity datasource <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9648180689> > Commit: 874f9f1 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9648180689&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity, @tag.Datasource` <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved payload structure for `updateAction` and `moveAction` methods to enhance API request consistency. - Updated `updateApplicationTheme` method to refine the payload before making API calls. - Modified `generateTemplatePage` method to update the request payload, improving API interaction. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Currently, if the incoming request body contains fields that aren't recognized by the backend, we just ignore them, and deserialize what we _can_. This has lead to subtle bugs and wasted a lot of developer time in the past, and added little value in return. Most recently, with application creation, now fixed in appsmithorg#33722. Another one, for action creation, client sends this in `eventData` field of the request body:  But the class defined for `eventData` is this:  Clearly isn't working. This PR enabled the `FAIL_ON_UNKNOWN_PROPERTIES` setting only for the deserialization of HTTP request payloads. It shouldn't have impact on other deserializations like those for Git, and those that load resource files. Primarily to limit the scope. This should also bring in some much-needed type strictness to the client as well. So far, server has been lax in accepting just any fields in the incoming request body, so client was able to afford being lax about the object that was sent up. We're enabling this restriction only for CE currently. Will be opening a similar PR on EE and once all tests pass there, we enable for EE as well. Depends on appsmithorg#33728 appsmithorg#33730 appsmithorg#33731 appsmithorg#34366 appsmithorg#34405 appsmithorg#34446 appsmithorg#34473 appsmithorg#34506 Run No. 1 > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9685619413> > Commit: 04e225f > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9685619413&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `` **/test all** <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9690185000> > Commit: 29da8b4 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9690185000&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `` <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added `certificateType` property to datasources for enhanced SSL configuration options. - **Enhancements** - Improved JSON deserialization behavior for better data handling and flexibility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Part of #33724.
This PR fixes a few more APIs to pass just the fields that the server expects, and nothing more.
/test sanity datasource
Tip
🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9648180689
Commit: 874f9f1
Cypress dashboard.
Tags:
@tag.Sanity, @tag.DatasourceSummary by CodeRabbit
updateActionandmoveActionmethods to enhance API request consistency.updateApplicationThememethod to refine the payload before making API calls.generateTemplatePagemethod to update the request payload, improving API interaction.