go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

[API TS Generator]Some codes generated by ts code generator of goctl are incorrect

Open hkb1990 opened this issue 4 months ago • 0 comments

Describe the bug Some codes generated by ts code generator of goctl are incorrect

To Reproduce Steps to reproduce the behavior, if applicable:

goctl api ts --api .\test.api --dir .\js

The api file is as follows

syntax = "v1"

info (
	title:   "Test ts generator"
	desc:    "Some codes generated by ts code generator of goctl are incorrect"
	author:  "HKB"
	date:    "2025 年 8 月 22 日"
	version: "v1"
)

// common pagination request
type PaginationReq {
	PageNum  int `form:"pageNum"`
	PageSize int `form:"pageSize"`
}

// base response
type BaseResp {
	Code int64  `json:"code"`
	Msg  string `json:"msg"`
}

// common req
type GetListCommonReq {
	Sth      string `form:"sth"`
	PageNum  int    `form:"pageNum"`
	PageSize int    `form:"pageSize"`
}

// bad req to ts
type GetListBadReq {
	Sth string `form:"sth"`
	PaginationReq
}

// bad req to ts 2
type GetListBad2Req {
	PaginationReq
}

// GetListResp
type GetListResp {
	BaseResp
}

service test-api {
	@doc "common req"
	@handler getListCommon
	get /getListCommon (GetListCommonReq) returns (GetListResp)

	@doc "bad req"
	@handler getListBad
	get /getListBad (GetListBadReq) returns (GetListResp)

	@doc "bad req 2"
	@handler getListBad2
	get /getListBad2 (GetListBad2Req) returns (GetListResp)

	@doc "no req"
	@handler getListNoReq
	get /getListNoReq returns (GetListResp)
}   
  1. The error is

In generated file 'test.ts'

Expected 2-3 arguments, but got 4.  [Ln 12, Col 72]
'"******/testComponents"' has no exported member named 'GetListBad2ReqHeaders'. Did you mean 'GetListBadReqHeaders'?  [Ln 20, Col 81]
Expected 2-3 arguments, but got 1. [Ln 36, Col 16]

Expected behavior The generated code should not have any errors.

Screenshots If applicable, add screenshots to help explain your problem.

Environments (please complete the following information):

  • OS: Windows 11
  • go-zero version 1.9.0
  • goctl version 1.8.5 windows/amd64

More description Add any other context about the problem here.

hkb1990 avatar Aug 22 '25 02:08 hkb1990