Repository navigation
fix(cmd/gf): find the api import by path when gen ctrl parses controllers - #4957
nk-batman21 wants to merge 1 commit into
Conversation
…lers In merge mode, getApiItemsInDst took the first import whose last path segment equals the api version as the api package of a controller file. An unaliased import such as "github.com/xuri/excelize/v2" placed above the api import of a v2 controller was picked instead, so the existing methods no longer matched the api definitions. A newly added api was then not generated, and with -c the second run failed with "1:1: expected 'package', found 'EOF'". The api import is now chosen by the import paths that getApiItemsInSrc already collects. When no import path matches, the first segment match is kept as before, so controllers of an api version removed from src resolve the same way. Fixes gogf#4954
|
The import selection change looks right for the unaliased case in #4954. Merge is still blocked by CI on this head.
Both assertions are about how many jobs ran before shutdown, so this looks like a timing flake rather than a problem in the genctrl change. That failure also left |
gf gen ctrl -mpicks the api package of an existing controller file by taking the first import whose last path segment equals the api version. An unaliased import like"github.com/xuri/excelize/v2"above the api import in a v2 controller wins, so the existing methods no longer match the api definitions. A newly added api is then skipped without any error, and with-cthe second run fails with1:1: expected 'package', found 'EOF'. #4940 fixed the aliased form, this is the unaliased one.As the issue suggests,
getApiItemsInDstnow receives the api items from src and prefers the import whose path is one of their import paths. When no path matches, the first segment match is kept as before, so controllers of an api version that was removed from src resolve the same way as on master.Test_Gen_Ctrl_UseMerge_Issue4954follows the #4289 test with the unaliased import from the issue steps, with and withoutClear. On master it fails withEXPECT 0 == 1(noDictTypeAdd) and with the EOF error whenClearis set.Ran:
go test -count=1 -run Test_Gen_Ctrl ./internal/cmd/incmd/gf, all 7 passChecked: the issue steps with a built
gf, a v2 api andexcelize/v2, for-mand-m -cChecked:
golangci-lint run -c .golangci.ymlreports no new issues ingenctrlFixes #4954