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

Updated swagger schema of get workflow by id endpoint #2762

Merged

Conversation

tomer-shvadron
Copy link
Collaborator

@tomer-shvadron tomer-shvadron commented Oct 9, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new properties in the workflow model for enhanced data representation.
    • Added new endpoints for emitting workflow events and handling document OCR processing.
  • Bug Fixes

    • Improved error handling in several workflow management methods.
  • Refactor

    • Removed unnecessary properties from the WorkflowDefinition model and related schemas to streamline workflow definitions.
    • Updated method signatures to reflect the removal of redundant fields, including backend and supportedPlatforms.
  • Documentation

    • Enhanced API documentation with new response types and validation schemas.

Copy link

changeset-bot bot commented Oct 9, 2024

⚠️ No Changeset found

Latest commit: 6bde6a0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

Walkthrough

The changes in this pull request involve significant modifications to the WorkflowDefinition model and related classes within the workflows service. Key alterations include the removal of several properties such as supportedPlatforms and backend from various schemas and DTOs, as well as the introduction of new optional properties in the WorkflowDefinitionModel and WorkflowRuntimeListItemModel. Additionally, new methods have been added to the workflow controllers, enhancing functionality and error handling. Overall, the updates streamline the data model and improve the structure of the service.

Changes

File Path Change Summary
services/workflows-service/prisma/schema.prisma Removed fields: supportedPlatforms, backend, persistStates, submitStates from WorkflowDefinition model.
services/workflows-service/prisma/migrations/20241009122132_removed_unused_schema/migration.sql Dropped columns: backend, supportedPlatforms from WorkflowDefinition table.
services/workflows-service/src/filter/dtos/temp-zod-schemas.ts Removed properties: supportedPlatforms and backend from WorkflowDefinitionWhereInput, WorkflowDefinitionWhereInputSchema, WorkflowDefinitionSelectSchema, and BusinessWhereInputSchema.
services/workflows-service/src/workflow/dtos/workflow-definition-create.ts Removed properties: supportedPlatforms and backend from WorkflowDefinitionCreateDto.
services/workflows-service/src/workflow/workflow-definition.model.ts Removed property: user. Added properties: crossEnvKey, projectId, isPublic, displayName, reviewMachineId, variant, createdBy. Renamed properties: context to contextSchema, config to documentsSchema, extensions to config, backend to extensions.
services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts Added properties: projectId, salesforceObjectName, salesforceRecordId, parentRuntimeDataId, endUserId, businessId, assigneeId, uiDefinitionId, workflowDefinitionVersion, assignedAt, tags. Modified assignee to optional.
services/workflows-service/src/workflow/workflow.controller.external.ts Updated return type of getRunnableWorkflowDataById to Promise<WorkflowRuntimeData>. Simplified method implementation to return workflowRuntimeData.
services/workflows-service/src/workflow/workflow.controller.internal.ts Added methods: emitWorkflowEvent, runDocumentOcr. Updated deleteWorkflowDefinitionById to remove backend from selection criteria. Enhanced error handling in several methods.
services/workflows-service/src/workflow/workflow.service.ts Removed backend and supportedPlatforms from createWorkflowDefinition, cloneWorkflowDefinition, and listWorkflowDefinitions methods.

Possibly related PRs

  • Pdf export feature #2331: The changes in this PR involve the removal of fields related to WorkflowDefinition, which aligns with the main PR's modifications to the WorkflowDefinition model in the Prisma schema.

Suggested reviewers

  • alonp99

🐰 In the meadow, changes bloom,
Fields once crowded, now have room.
Properties gone, new paths we tread,
A clearer view, where dreams are led.
With every hop, we celebrate,
The workflows dance, it’s truly great! 🌼


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.

@tomer-shvadron tomer-shvadron changed the title feat: updated swagger schema of get workflow by id endpoint Updated swagger schema of get workflow by id endpoint Oct 9, 2024
Copy link
Contributor

@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: 12

🧹 Outside diff range and nitpick comments (2)
services/workflows-service/src/workflow/workflow.controller.external.ts (2)

50-56: Rename the Test class to a more descriptive name.

The newly added Test class appears to be a DTO for API responses. While the property declarations and decorators are correct, the class name "Test" is not descriptive and doesn't follow naming conventions. Consider renaming it to something more meaningful, such as WorkflowResponseDto or RunnableWorkflowDataDto, which better reflects its purpose and content.


Line range hint 194-224: Update return statement to use the new response structure.

The method body hasn't been updated to reflect the new response structure defined by the Test class. To ensure consistency with the API response type, modify the return statement to construct and return an instance of the Test class.

Apply this change to the return statement:

- return {
-   workflowDefinition,
-   workflowRuntimeData,
- };
+ return new Test({
+   workflowDefinition,
+   workflowRuntimeData,
+ });

Also, ensure that the Test class constructor accepts these properties, or use property assignment if it doesn't have a constructor.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f9b7358 and acf56f3.

📒 Files selected for processing (8)
  • services/workflows-service/prisma/schema.prisma (0 hunks)
  • services/workflows-service/src/filter/dtos/temp-zod-schemas.ts (0 hunks)
  • services/workflows-service/src/workflow/dtos/workflow-definition-create.ts (0 hunks)
  • services/workflows-service/src/workflow/workflow-definition.model.ts (3 hunks)
  • services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts (4 hunks)
  • services/workflows-service/src/workflow/workflow.controller.external.ts (3 hunks)
  • services/workflows-service/src/workflow/workflow.controller.internal.ts (0 hunks)
  • services/workflows-service/src/workflow/workflow.service.ts (0 hunks)
💤 Files with no reviewable changes (5)
  • services/workflows-service/prisma/schema.prisma
  • services/workflows-service/src/filter/dtos/temp-zod-schemas.ts
  • services/workflows-service/src/workflow/dtos/workflow-definition-create.ts
  • services/workflows-service/src/workflow/workflow.controller.internal.ts
  • services/workflows-service/src/workflow/workflow.service.ts
🧰 Additional context used
🔇 Additional comments (10)
services/workflows-service/src/workflow/workflow.controller.external.ts (1)

7-8: LGTM: Import statements updated appropriately.

The changes to the import statements are correct and align with the modifications in the code. The addition of ApiProperty and WorkflowRuntimeListItemModel imports, as well as the type-only import of WorkflowRuntimeData, reflect the updates in the API documentation and response types.

Also applies to: 48-48

services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts (1)

72-72: ⚠️ Potential issue

Missing @Expose() decorator for uiDefinitionId

Similar to assigneeId, the uiDefinitionId property is missing the @Expose() decorator, which is necessary for serialization.

Add the @Expose() decorator:

+@Expose()
 @ApiProperty({ required: false, type: String })
 @IsOptional()
 @IsString()
 uiDefinitionId?: string;

Likely invalid or redundant comment.

services/workflows-service/src/workflow/workflow-definition.model.ts (8)

18-21: New property crossEnvKey added.

The optional string property crossEnvKey has been introduced with appropriate validation and API documentation. Ensure that this property is correctly utilized throughout the application and any necessary documentation is updated.


23-26: New property projectId added.

The optional string property projectId has been added with proper validation and API documentation. Confirm that projectId is properly handled in relevant parts of the application.


31-34: New property displayName added.

An optional string property displayName has been added with appropriate validation and API documentation.


36-39: New property reviewMachineId added.

The optional string property reviewMachineId has been introduced. Ensure it is utilized appropriately within the application.


41-44: New property variant added.

The optional string property variant has been added with proper validation and API documentation.


134-137: New property createdBy added.

An optional string property createdBy has been added with proper validation and API documentation. Ensure that this field is correctly set when creating workflow definitions and handled appropriately in related services.


112-112: Property renamed from backend to extensions.

The property backend has been renamed to extensions. Ensure all references to workflowDefinition.backend are updated to workflowDefinition.extensions throughout the codebase.

Run this command to search for outdated references:

#!/bin/bash
# Description: Find references to workflowDefinition.backend

rg --type typescript 'workflowDefinition\.backend\b'

88-88: Property renamed from context to contextSchema.

The property context has been renamed to contextSchema. Verify that all references to workflowDefinition.context are updated to workflowDefinition.contextSchema throughout the codebase to prevent runtime errors.

Run the following script to identify any remaining references to the old property name:

✅ Verification successful

Verification Successful: All references to workflowDefinition.context have been updated to workflowDefinition.contextSchema throughout the codebase, preventing potential runtime errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find references to workflowDefinition.context

rg --type typescript 'workflowDefinition\.context\b'

Length of output: 89


Script:

#!/bin/bash
# Description: Find references to workflowDefinition.context in .ts and .tsx files

rg --glob '*.ts' --glob '*.tsx' 'workflowDefinition\.context\b'

Length of output: 65

@tomer-shvadron tomer-shvadron enabled auto-merge (squash) October 9, 2024 13:18
Copy link
Contributor

@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: 3

🧹 Outside diff range and nitpick comments (1)
services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts (1)

Line range hint 88-91: Use @IsEnum() for enum validation on status property

The status property is of type WorkflowRuntimeDataStatus, which is an enum. Using @IsString() validates it as a string, but @IsEnum() provides stronger validation for enum types and ensures that only valid enum values are assigned.

Apply this diff to improve the validation:

 @Expose()
 @ApiProperty()
-@IsString()
+@IsEnum(WorkflowRuntimeDataStatus)
 status!: WorkflowRuntimeDataStatus;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 017dc5a and 1f354ae.

📒 Files selected for processing (2)
  • services/workflows-service/src/workflow/workflow-definition.model.ts (3 hunks)
  • services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts (4 hunks)
🧰 Additional context used
🔇 Additional comments (1)
services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts (1)

108-111: ⚠️ Potential issue

Specify a concrete type for context property

The context property is typed as JSON, which is not a valid TypeScript type and may lead to issues during type checking. Consider using a more accurate type like Record<string, any> or defining a specific interface to improve type safety.

Apply this diff to update the property type:

 @Expose()
 @ApiProperty()
 @IsJSON()
-context!: JSON;
+context!: Record<string, any>;

Likely invalid or redundant comment.

Copy link
Contributor

@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 (1)
services/workflows-service/src/workflow/workflow-definition.model.ts (1)

115-115: Note the inconsistency in validation decorators for extensions.

The extensions property (formerly backend) continues to use @IsNotEmptyObject(), while similar properties (contextSchema, documentsSchema, and config) now use @IsObject().

Consider standardizing the validation approach across all these properties for consistency, unless there's a specific reason for this difference.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1f354ae and 2e5c54b.

📒 Files selected for processing (1)
  • services/workflows-service/src/workflow/workflow-definition.model.ts (3 hunks)
🧰 Additional context used
🔇 Additional comments (7)
services/workflows-service/src/workflow/workflow-definition.model.ts (7)

5-5: LGTM: Import statement added for new property.

The addition of IsBoolean import is consistent with the new isPublic property in the class.


19-22: LGTM: New property crossEnvKey added with correct decorators.

The crossEnvKey property is correctly defined as an optional string with appropriate decorators. The @ApiProperty decorator includes required: false and type: String, which is consistent with the suggested best practices.


24-27: LGTM: New property projectId added with correct decorators.

The projectId property is correctly defined as an optional string with appropriate decorators, following the same pattern as crossEnvKey.


29-32: LGTM: New property isPublic added with correct decorators.

The isPublic property is correctly defined as an optional boolean with appropriate decorators. The @ApiProperty decorator includes required: false and type: Boolean, which is consistent with the suggested best practices.


34-47: LGTM: New properties added with correct decorators.

The displayName, reviewMachineId, and variant properties are correctly defined as optional strings with appropriate decorators, following the same pattern as crossEnvKey and projectId.


137-140: LGTM: New property createdBy added with correct decorators.

The createdBy property is correctly defined as an optional string with appropriate decorators, following the same pattern as other new string properties in this class.


91-91: Clarify the use of @IsObject() vs @IsNotEmptyObject().

The properties contextSchema, documentsSchema, and config now use @IsObject() instead of @IsNotEmptyObject(). This change allows for empty objects, which may or may not be intentional. However, the extensions property still uses @IsNotEmptyObject().

Could you please clarify if this inconsistency is intentional? If not, consider standardizing the validation approach across all these properties.

To check the usage of these properties in the codebase, you can run:

This will help determine if empty objects are being used or if they should be disallowed.

Also applies to: 99-99, 105-107

Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (1)
services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts (1)

Line range hint 1-152: Consider reviewing and expanding test coverage

The changes in this file have reduced the overall test coverage of the workflow controller. One test case has been removed entirely, and another has been simplified. This reduction in test coverage could potentially lead to undetected bugs or regressions in the future.

Consider reviewing the current test suite and potentially expanding it to ensure comprehensive coverage of the workflow controller's functionality. This might include:

  1. Reinstating the removed test case for GET /workflows if the functionality still exists.
  2. Adding more assertions to the existing test cases to cover all aspects of the response.
  3. Adding new test cases for any new or modified functionality in the workflow controller.

To help identify areas that might need additional testing, you can run the following script:

#!/bin/bash
# Description: Analyze workflow controller for potential untested areas

# Test: List all public methods in the workflow controller
echo "Public methods in workflow controller:"
ast-grep --lang typescript --pattern $'class WorkflowControllerExternal {
  $$$
  @$_($$$)
  $_($_) {
    $$$
  }
  $$$
}'

# Test: List all test cases in the current file
echo "Current test cases:"
rg --type ts "test\(.*\)" services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts

# Test: Check for TODO comments related to testing
echo "TODO comments related to testing:"
rg --type ts "TODO.*test" services/workflows-service/src/workflow

This script will help identify public methods in the controller that might not have corresponding test cases, as well as any TODO comments related to testing that might need to be addressed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2e5c54b and 6bde6a0.

📒 Files selected for processing (1)
  • services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts (2)

Line range hint 86-109: Clarify the removal of the GET /workflows test case

A test case for the GET /workflows endpoint has been commented out. This removes coverage for the list operation of workflows, which could lead to potential regressions going undetected.

Can you please clarify why this test case was removed? If the functionality is still supported, consider keeping the test or replacing it with an updated version.

To verify the current state of workflow listing functionality, you can run the following script:

#!/bin/bash
# Description: Check for workflow listing endpoint and its tests

# Test: Search for workflow listing endpoint in controller
echo "Searching for workflow listing endpoint in controller:"
rg --type ts "GET /workflows" -g "*controller*.ts"

# Test: Search for tests related to workflow listing
echo "Searching for tests related to workflow listing:"
rg --type ts "test.*GET /workflows" -g "*test.ts"

This script will help identify if the workflow listing functionality is still present in the controller and if there are any remaining tests for it.


146-146: Verify the simplified test assertion for GET /workflows/:id

The test assertion for the GET /workflows/:id endpoint has been simplified to only check for the state object in the response. While this aligns with the current mock implementation, it may not fully test the endpoint's response.

Please confirm if this simplification is intentional. Consider whether testing only the state object is sufficient, or if additional assertions should be added to ensure the complete response structure is correct.

To verify the current implementation of the getWorkflowRuntimeDataById method, you can run the following script:

#!/bin/bash
# Description: Check the implementation of getWorkflowRuntimeDataById

# Test: Search for getWorkflowRuntimeDataById method implementation
echo "Searching for getWorkflowRuntimeDataById implementation:"
ast-grep --lang typescript --pattern $'class $_ {
  $$$
  async getWorkflowRuntimeDataById($_) {
    $$$
  }
  $$$
}'

This script will help identify the current implementation of the getWorkflowRuntimeDataById method, which can be used to determine if the test assertion adequately covers the method's return value.

@tomer-shvadron tomer-shvadron merged commit dbecc50 into dev Oct 9, 2024
10 checks passed
@tomer-shvadron tomer-shvadron deleted the chore/tomer/update-get-workflow-by-id-swagger-schema branch October 9, 2024 14:22
mhagi00 added a commit to mhagi00/ballerine that referenced this pull request Oct 9, 2024
Updated swagger schema of get workflow by id endpoint (ballerine-io#2762)
@Omri-Levy Omri-Levy mentioned this pull request Nov 4, 2024
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