fix(docs): make `make docs` reproduce the committed Swagger again (#3751)
Running `make docs` on main no longer reproduces the committed docs/*: every definition loses its package-qualified name (types.* instead of github_com_Tencent_WeKnora_internal_types.*), enums disappear, ErrorCode becomes a plain integer, and docs/swagger_contract_test.go fails (TestModelDeleteUsageContract). Cause: internal/localsandbox is not a dependency of cmd/server (its importers are behind the `desktop` build tag), but swag's directory walk reaches it. Its `const X = core.X` aliases make swag load internal/localsandbox/core again through go/loader, and that second load re-registers every already-deduplicated type under its short name without enum values. Excluding the directory removes the second load. That load was also hiding a second problem: skill_handler.go references errors.AppError in @Failure without importing internal/errors, so with the exclude swag stops with "cannot find type definition: errors.AppError". A blank import lets swag resolve it. Co-authored-by: Victor Maznyuk <victor@maznyuk.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>main
parent
11bfacad97
commit
3206e15e83
11
Makefile
11
Makefile
|
|
@ -246,9 +246,18 @@ migrate-goto:
|
|||
./scripts/migrate.sh goto $(version)
|
||||
|
||||
# Generate API documentation (Swagger)
|
||||
#
|
||||
# internal/localsandbox is excluded because cmd/server does not depend on it
|
||||
# (its importers are behind the `desktop` build tag). Without the exclude,
|
||||
# swag walks into the directory, follows its `const X = core.X` aliases and
|
||||
# loads internal/localsandbox/core a second time through go/loader; that
|
||||
# second load re-registers every model under its short name without enum
|
||||
# values, so definitions lose their package-qualified names and
|
||||
# docs/swagger_contract_test.go fails.
|
||||
docs:
|
||||
@echo "生成 Swagger API 文档..."
|
||||
swag init -g $(MAIN_PATH)/main.go -o ./docs --parseDependency --parseInternal
|
||||
swag init -g $(MAIN_PATH)/main.go -o ./docs --parseDependency --parseInternal \
|
||||
--exclude ./internal/localsandbox
|
||||
@echo "文档已生成到 ./docs 目录"
|
||||
@echo "启动服务后访问 http://localhost:8080/swagger/index.html 查看文档"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ import (
|
|||
|
||||
"github.com/Tencent/WeKnora/internal/application/access"
|
||||
"github.com/Tencent/WeKnora/internal/application/service"
|
||||
// Referenced only by the @Failure annotations (errors.AppError); swag
|
||||
// resolves annotation types through the file's imports.
|
||||
_ "github.com/Tencent/WeKnora/internal/errors"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue