Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional requiredParam for UIParameter decoder compatibility #7265

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

mateuszkp96
Copy link
Contributor

@mateuszkp96 mateuszkp96 commented Nov 29, 2024

Describe your changes

Checklist before merge

  • Related issue ID is placed at the beginning of PR title in [brackets] (can be GH issue or Nu Jira issue)
  • Code is cleaned from temporary changes and commented out lines
  • Parts of the code that are not easy to understand are documented in the code
  • Changes are covered by automated tests
  • Showcase in dev-application.conf added to demonstrate the feature
  • Documentation added or updated
  • Added entry in Changelog.md describing the change from the perspective of a public distribution user
  • Added MigrationGuide.md entry in the appropriate subcategory if introducing a breaking change
  • Verify that PR will be squashed during merge

Summary by CodeRabbit

  • New Features

    • Enhanced JSON encoding/decoding for the UIParameter class, allowing the requiredParam field to be optional.
    • Improved handling of parameter optionality in the DefinitionsService class.
    • Introduced new API endpoints and updated existing ones in the Nussknacker Designer API, enhancing functionality and usability.
  • Bug Fixes

    • Ensured backward compatibility for older versions regarding the requiredParam field.
  • Documentation

    • Expanded OpenAPI specification with detailed examples and improved error handling for various endpoints.

Copy link

coderabbitai bot commented Nov 29, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to the UIParameter case class in the pl.touk.nussknacker.restmodel.definition package and the DefinitionsService class. The requiredParam field's type in UIParameter has been changed from Boolean to Option[Boolean], allowing it to be optional and ensuring backward compatibility for decoding responses from older versions. The comments related to this field have been updated to reflect its new optional nature.

In the DefinitionsService class, the createUIParameter method has been updated to accommodate the new Option[Boolean] type for requiredParam. The prepareUIDefinitions method has also seen a minor update, including a new import statement for configuration handling, but its overall logic remains largely unchanged. The control flow and error handling within the methods continue to function as intended, preserving the existing structure while enhancing the handling of optional parameters.

No significant changes to method signatures or the overall structure of the classes are present beyond those mentioned.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DefinitionsService
    participant UIParameter

    Client->>DefinitionsService: Request to create UIParameter
    DefinitionsService->>UIParameter: Create UIParameter with Option[Boolean]
    UIParameter-->>DefinitionsService: Return UIParameter instance
    DefinitionsService-->>Client: Return created UIParameter
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f665227 and 7dff8f2.

📒 Files selected for processing (1)
  • docs-internal/api/nu-designer-openapi.yaml (1 hunks)
🔇 Additional comments (1)
docs-internal/api/nu-designer-openapi.yaml (1)

7038-7040: LGTM! Good backward compatibility consideration.

Making requiredParam nullable is a good change that ensures backward compatibility when decoding responses from older versions that may not include this field.


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
designer/restmodel/src/main/scala/pl/touk/nussknacker/restmodel/definition/package.scala (3)

Line range hint 38-56: Consider enhancing documentation about external project dependency

The comment "This attribute is used only by external project" for requiredParam could be more descriptive. Consider documenting:

  • Which external project depends on this
  • Why it's needed
  • Any plans for future removal or migration

This would help future maintainers understand the importance and lifecycle of this field.


73-75: Enhance version compatibility documentation

The comment about version 1.18 compatibility could be more specific. Consider:

  • Adding the release date of version 1.18
  • Specifying when this fallback might be removed (e.g., "can be removed after version X.Y")
  • Adding a JIRA/GitHub issue reference for tracking the future removal

61-89: Consider using applicative syntax for a more concise decoder

While the current implementation is correct, it could be more concise using Circe's applicative syntax. This would make the code more maintainable and reduce the likelihood of field mapping errors.

Here's a suggested refactoring:

  implicit val uiParameterDecoder: Decoder[UIParameter] = {
-   Decoder.instance { c =>
-     for {
-       name                <- c.downField("name").as[String]
-       typ                 <- c.downField("typ").as[TypingResult]
-       editor              <- c.downField("editor").as[ParameterEditor]
-       defaultValue        <- c.downField("defaultValue").as[Expression]
-       additionalVariables <- c.downField("additionalVariables").as[Map[String, TypingResult]]
-       variablesToHide     <- c.downField("variablesToHide").as[Set[String]]
-       branchParam         <- c.downField("branchParam").as[Boolean]
-       hintText            <- c.downField("hintText").as[Option[String]]
-       label               <- c.downField("label").as[String]
-       requiredParam       <- c.downField("requiredParam").as[Option[Boolean]].map(_.getOrElse(true))
-     } yield UIParameter(
-       name = name,
-       typ = typ,
-       editor = editor,
-       defaultValue = defaultValue,
-       additionalVariables = additionalVariables,
-       variablesToHide = variablesToHide,
-       branchParam = branchParam,
-       hintText = hintText,
-       label = label,
-       requiredParam = requiredParam
-     )
-   }
+   import io.circe.syntax._
+   Decoder.instance { c =>
+     (
+       c.downField("name").as[String],
+       c.downField("typ").as[TypingResult],
+       c.downField("editor").as[ParameterEditor],
+       c.downField("defaultValue").as[Expression],
+       c.downField("additionalVariables").as[Map[String, TypingResult]],
+       c.downField("variablesToHide").as[Set[String]],
+       c.downField("branchParam").as[Boolean],
+       c.downField("hintText").as[Option[String]],
+       c.downField("label").as[String],
+       c.downField("requiredParam").as[Option[Boolean]].map(_.getOrElse(true))
+     ).mapN(UIParameter.apply)
+   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9d4f381 and d2a7b1f.

📒 Files selected for processing (1)
  • designer/restmodel/src/main/scala/pl/touk/nussknacker/restmodel/definition/package.scala (3 hunks)
🔇 Additional comments (2)
designer/restmodel/src/main/scala/pl/touk/nussknacker/restmodel/definition/package.scala (2)

4-4: LGTM: Import changes align with the new JSON handling approach

The import changes correctly reflect the transition from automatic codec derivation to manual decoder implementation while maintaining the configured encoder.


57-91: LGTM: Well-implemented JSON handling with backward compatibility

The implementation successfully:

  • Provides a fallback for missing requiredParam
  • Maintains backward compatibility with version 1.18
  • Uses appropriate JSON encoding/decoding patterns
  • Includes clear documentation

The code is well-structured and follows Scala best practices.

@mateuszkp96 mateuszkp96 changed the title Fallback for missing requiredParam in UIParameter decoder Optional requiredParam for UIParameter decoder compatibility Nov 29, 2024
@mateuszkp96 mateuszkp96 merged commit 648ab35 into release/1.18 Nov 29, 2024
13 checks passed
@mateuszkp96 mateuszkp96 deleted the bugfix/ui-parameter-decoder-fix branch November 29, 2024 11:13
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants