-
Notifications
You must be signed in to change notification settings - Fork 81
feat: 新增工作流相关接口 #124
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
feat: 新增工作流相关接口 #124
Conversation
WalkthroughAdds workflow listing and retrieval: new Retrofit Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant WorkflowService
participant WorkflowAPI as Retrofit:WorkflowAPI
participant Server as HTTP
Client->>WorkflowService: list(WorkflowListReq)
WorkflowService->>WorkflowAPI: list(workspace_id, page_num, page_size, workflow_mode, app_id, publish_status, BaseReq)
WorkflowAPI->>Server: GET /v1/workflows?...
Server-->>WorkflowAPI: 200 BaseResponse<WorkflowListResp>
WorkflowAPI-->>WorkflowService: Response<BaseResponse<...>>
WorkflowService-->>Client: BaseResponse<WorkflowListResp>
alt get workflow
Client->>WorkflowService: get(WorkflowGetReq)
WorkflowService->>WorkflowAPI: get(workflow_id, include_input_output, BaseReq)
WorkflowAPI->>Server: GET /v1/workflows/{workflow_id}?include_input_output=...
Server-->>WorkflowAPI: 200 BaseResponse<WorkflowGetResp>
WorkflowAPI-->>WorkflowService: Response<BaseResponse<...>>
WorkflowService-->>Client: BaseResponse<WorkflowGetResp>
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
songping seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this 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
🧹 Nitpick comments (13)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java (1)
18-35
: Consider improving field documentation and validation.The recursive structure with self-referencing fields is well-designed for complex parameter schemas. However, consider these improvements:
- Line 27: The comment mentions "数组元素的子类型" (array element subtype) but should say "对象属性的子类型" (object property subtype) for the
properties
field.- Consider adding validation annotations for type constraints (e.g.,
@NotNull
fortype
field).Apply this diff to fix the comment:
- /** 当参数类型为 object 时,该字段用于定义数组元素的子类型。 */ + /** 当参数类型为 object 时,该字段用于定义对象属性的子类型。 */ @JsonProperty("properties") private Map<String, WorkflowParameter> properties;api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (1)
6-8
: Harden JSON deserialization against unknown fields.
Add ignore-unknown to be forward-compatible with backend additions.import com.coze.openapi.client.workflows.model.WorkflowOutput; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public class WorkflowGetResp {Also applies to: 18-18
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java (3)
16-19
: Rename field to follow Java naming conventions (appId).
Currentapp_id
breaks typical camelCase and generates awkward Lombok accessors/builders./** 工作流关联的应用 ID。若工作流未关联任何应用,则该字段值为 0 */ @JsonProperty("app_id") - private String app_id; + private String appId;Note: Update any builder/setter usages in tests accordingly (e.g.,
.appId("...")
).
3-4
: Align with other models: include NON_NULL and ignore unknowns.
Other DTOs use@JsonInclude(NON_NULL)
; adding both improves payload cleanliness and resilience.-import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; @@ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public class WorkflowDetail {Also applies to: 10-14
25-30
: Consider numeric timestamps for createdAt/updatedAt.
API docs say Unix seconds; representing asLong
avoids parsing at call sites.- @JsonProperty("created_at") - private String createdAt; + @JsonProperty("created_at") + private Long createdAt; @@ - @JsonProperty("updated_at") - private String updatedAt; + @JsonProperty("updated_at") + private Long updatedAt;If you keep String for compatibility, ignore this.
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetReq.java (1)
25-28
: Default includeInputOutput to false instead of forcing NonNull.
Docs say default=false; make it optional with a safe default to simplify callers./** 是否在返回结果中返回输入和输出参数的结构体。 true:返回输入输出参数结构体 false:不返回输入输出参数结构体 默认值为 false。 */ - @NonNull @JsonProperty("include_input_output") - private Boolean includeInputOutput; + private Boolean includeInputOutput = Boolean.FALSE;api/src/main/java/com/coze/openapi/service/service/workflow/WorkflowService.java (2)
49-51
: Guard null and honor default=false when includeInputOutput is omitted.
If callers don’t set it (per request DTO default), passfalse
instead of null.- public BaseResponse<WorkflowGetResp> get(WorkflowGetReq req) { - return Utils.execute(workflowAPI.get(req.getWorkflowId(), req.getIncludeInputOutput(), req)); - } + public BaseResponse<WorkflowGetResp> get(WorkflowGetReq req) { + Boolean include = Boolean.TRUE.equals(req.getIncludeInputOutput()); + return Utils.execute(workflowAPI.get(req.getWorkflowId(), include, req)); + }
37-47
: Optional: validate paging bounds before calling API.
EnforcepageNum >= 1
and1 <= pageSize <= 30
to fail fast client-side.Happy to add small checks returning a typed error if preferred.
api/src/main/java/com/coze/openapi/client/workflows/WorkflowListReq.java (3)
29-31
: Provide a default page size of 10 as documented.
Avoids forcing callers to set it explicitly./** 查询结果分页展示时,此参数用于设置每页返回的数据量。取值范围为 1 ~ 30,默认为 10。 */ @JsonProperty("page_size") - private Integer pageSize; + private Integer pageSize = 10;
25-28
: Consider client-side validation for pageNum.
EnsurepageNum >= 1
; currently only documented.We can add a small validator or precondition in the service layer.
33-44
: Use enums for constrained fields (workflowMode, publishStatus).
Prevents invalid values and aids IDE completion.Example (new types):
public enum WorkflowMode { workflow, chatflow } public enum PublishStatus { all, published_online, unpublished_draft }Then change fields to these enums and keep @JsonProperty; Jackson will serialize as strings.
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowOutput.java (2)
25-26
: Model terminatePlan as an enum.
These are fixed values; enum improves type-safety and docs.- @JsonProperty("terminate_plan") - private String terminatePlan; + public enum TerminatePlan { return_variables, use_answer_content } + @JsonProperty("terminate_plan") + private TerminatePlan terminatePlan;Note: Adjust any test builders accordingly.
5-6
: Consistency: add NON_NULL and ignore unknowns.
Matches other DTOs and keeps payload minimal.-import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; @@ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public class WorkflowOutput {Also applies to: 12-16
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
api/pom.xml
(1 hunks)api/src/main/java/com/coze/openapi/api/WorkflowAPI.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetReq.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/WorkflowListReq.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/WorkflowListResp.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowCreator.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowInput.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowOutput.java
(1 hunks)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java
(1 hunks)api/src/main/java/com/coze/openapi/service/service/CozeAPI.java
(1 hunks)api/src/main/java/com/coze/openapi/service/service/workflow/WorkflowService.java
(2 hunks)api/src/test/java/com/coze/openapi/service/service/workflow/WorkFlowServiceTest.java
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (9)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowInput.java (3)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (1)
Data
(14-30)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowOutput.java (1)
Data
(12-27)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java (1)
Data
(12-36)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java (3)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (1)
Data
(14-30)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowInput.java (1)
Data
(12-21)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowOutput.java (1)
Data
(12-27)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowOutput.java (3)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (1)
Data
(14-30)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowInput.java (1)
Data
(12-21)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java (1)
Data
(12-36)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java (3)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (1)
Data
(14-30)api/src/main/java/com/coze/openapi/client/workflows/WorkflowListResp.java (1)
Data
(14-26)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowCreator.java (1)
Data
(10-22)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowListResp.java (3)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowListReq.java (1)
Data
(13-44)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowCreator.java (1)
Data
(10-22)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java (1)
Data
(10-40)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowListReq.java (3)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetReq.java (1)
Data
(13-29)api/src/main/java/com/coze/openapi/client/workflows/WorkflowListResp.java (1)
Data
(14-26)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java (1)
Data
(10-40)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowCreator.java (1)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java (1)
Data
(10-40)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetReq.java (5)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (1)
Data
(14-30)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java (1)
Data
(10-40)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowInput.java (1)
Data
(12-21)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowOutput.java (1)
Data
(12-27)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java (1)
Data
(12-36)
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (5)
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowCreator.java (1)
Data
(10-22)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowDetail.java (1)
Data
(10-40)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowInput.java (1)
Data
(12-21)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowOutput.java (1)
Data
(12-27)api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java (1)
Data
(12-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test (Java 17 on Windows)
- GitHub Check: test (Java 11 on Windows)
🔇 Additional comments (12)
api/pom.xml (1)
46-46
: LGTM! Version increment is appropriate.The version bump from 0.4.2 to 0.4.3 aligns with the new workflow API functionality being introduced. This follows semantic versioning for a minor feature addition.
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowParameter.java (1)
12-16
: LGTM! Standard Lombok configuration.The class follows standard patterns with appropriate Lombok annotations for generating boilerplate code.
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowCreator.java (1)
10-22
: LGTM! Simple and well-structured model.The WorkflowCreator model is appropriately simple with clear field names and proper JSON mapping. The Lombok annotations are correctly applied.
api/src/main/java/com/coze/openapi/client/workflows/model/WorkflowInput.java (1)
12-21
: LGTM! Clean and focused model.The WorkflowInput model correctly encapsulates the input parameters structure using the WorkflowParameter type. The design is consistent with the API structure.
api/src/main/java/com/coze/openapi/service/service/CozeAPI.java (1)
217-222
: LGTM! Proper integration of new WorkflowAPI.The WorkflowService constructor is correctly updated to include the new WorkflowAPI as the first parameter, maintaining backward compatibility with existing workflow run APIs. The retrofit integration follows the established pattern.
api/src/main/java/com/coze/openapi/api/WorkflowAPI.java (2)
16-24
: LGTM! Well-designed list endpoint.The list endpoint properly uses query parameters for filtering and pagination. The parameter naming follows REST conventions.
26-30
: LGTM! Clean and focused get endpoint.The get endpoint correctly uses path parameters for the workflow ID and a query parameter for the optional input/output inclusion. The design follows REST best practices.
api/src/main/java/com/coze/openapi/client/workflows/WorkflowListResp.java (1)
14-25
: LGTM! Standard pagination response structure.The response model follows standard pagination patterns with
items
for data andhasMore
for pagination state. The use ofWorkflowDetail
as the item type maintains consistency with the data model hierarchy.api/src/test/java/com/coze/openapi/service/service/workflow/WorkFlowServiceTest.java (1)
35-50
: LGTM! Proper test setup with mocks.The test setup correctly mocks all required API dependencies and initializes the WorkflowService with the new constructor signature. The use of MockitoAnnotations.openMocks() follows current best practices.
api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetResp.java (1)
14-29
: LGTM: response DTO is clean and matches API fields.
The structure and Jackson mappings look correct.api/src/main/java/com/coze/openapi/client/workflows/WorkflowGetReq.java (1)
20-24
: Keep NonNull on workflowId.
This matches server requirements and prevents accidental empty calls.api/src/main/java/com/coze/openapi/service/service/workflow/WorkflowService.java (1)
37-47
: LGTM: list wiring mirrors API and passes through filters.
Delegation to Retrofit with Utils.execute looks consistent with existing services.
新增「查询工作流基本信息」、「查询工作流的版本列表」接口