Golang 上下文测试
- 作者仓库星标 0
- 作者仓库 skills-registry
golang-echo-oapi
When To Use
- Use this skill for changes to
github.com/adlandh/echo-oapi-middleware/v2or code that consumes this library. - Apply it when touching
SwaggerYaml,SwaggerYamlWithConfig,SwaggerUI,SwaggerUIWithConfig, their tests, or README examples.
Library Shape
- Package name is
echooapimiddleware; it is a single-package Go module with no generated code or subpackages. - It targets Go 1.25 and Echo v5 (
github.com/labstack/echo/v5). Echo handlers usefunc(c *echo.Context) error. - Public API accepts
*openapi3.Tfromgithub.com/getkin/kin-openapi/openapi3; do not add runtime parsing as part of the middleware path unless explicitly requested.
Behavior To Preserve
- Serialize the OpenAPI spec once when middleware is created, not on every request.
SwaggerYamldefaults to/swagger.yamland serves onlyGETandHEAD; all other methods and paths pass through to the next handler.SwaggerUIdefaults to/swagger, also serves/swagger/and/swagger/index.html, and wires the YAML endpoint.HEADresponses for YAML and UI must setContent-Lengthand write no body.nilspecs are valid and produce successful empty YAML responses.KeepServersdefaults to false: omit top-levelserversfrom emitted YAML without mutating the caller's*openapi3.T.- Generated Swagger UI HTML references unpkg
swagger-ui-dist@5assets.
Verification Commands
- Fast local check:
go test ./.... - CI-equivalent tests:
go test -race -coverprofile=coverage.txt -covermode=atomic ./.... - Focused tests:
go test -run TestSwaggerYaml_RequestRouting .orgo test -run TestSwaggerUI_DefaultPaths .. - Benchmark YAML serving path:
go test -bench BenchmarkSwaggerYamlGET -benchmem .. - CI lint downloads the shared config before running:
curl -sS https://raw.githubusercontent.com/adlandh/golangci-lint-config/refs/heads/main/.golangci.yml -o .golangci.yml, thengolangci-lint run.
Implementation Notes
- Keep the middleware chain passthrough behavior explicit; tests depend on non-matching requests reaching downstream Echo routes.
- Prefer small direct functions over new abstractions; this library is intentionally tiny.
- If changing config defaults or route matching, update both README examples and tests in the same change.
Integrating Into A Project
- Do not try to embed or parse
swagger.yaml/openapi.yamlat runtime. This library accepts*openapi3.Tfromgithub.com/getkin/kin-openapi/openapi3, not a raw YAML file. - Before reaching for
//go:embedoros.ReadFile, check the generated code — most OpenAPI code generators (e.g.oapi-codegen) produce aGetSpecfunction that returns the parsed*openapi3.Tdirectly. Pass that toSwaggerYAMLorSwaggerUI.
<!-- tomevault:4.0:skill_md:2026-05-23 -->Source: adlandh/echo-oapi-middleware — distributed by TomeVault.
- 流狐分类
- 工程开发
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 即装即用
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 检测到的网络行为
- 允许外网请求
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 Use this skill for changes to github.com/adlandh/echo-oapi-middleware/v2 or code that consumes this library. Apply it when touching SwaggerYaml, SwaggerYamlWithConfig, SwaggerUI, SwaggerUIWithConfig, their tests, or README examples.
Package name is echooapimiddleware; it is a single-package Go module with no generated code or subpackages. It targets Go 1.25 and Echo v5 (github.com/labstack/echo/v5). Echo handlers use func(c echo.Context) error. Public API accepts openapi3.T from…
Serialize the OpenAPI spec once when middleware is created, not on every request. SwaggerYaml defaults to /swagger.yaml and serves only GET and HEAD; all other methods and paths pass through to the next handler. SwaggerUI defaults to /swagger, also serves…
Fast local check: go test ./.... CI-equivalent tests: go test -race -coverprofile=coverage.txt -covermode=atomic ./.... Focused tests: go test -run TestSwaggerYamlRequestRouting . or go test -run TestSwaggerUIDefaultPaths ..
Keep the middleware chain passthrough behavior explicit; tests depend on non-matching requests reaching downstream Echo routes. Prefer small direct functions over new abstractions; this library is intentionally tiny. If changing config defaults or route…
Do not try to embed or parse swagger.yaml / openapi.yaml at runtime. This library accepts openapi3.T from github.com/getkin/kin-openapi/openapi3, not a raw YAML file. Before reaching for //go:embed or os.ReadFile, check the generated code — most OpenAPI code…
# golang-echo-oapi
## When To Use
- Use this skill for changes to `github.com/adlandh/echo-oapi-middleware/v2` or code that consumes this library.
- Apply it when touching `SwaggerYaml`, `SwaggerYamlWithConfig`, `SwaggerUI`, `SwaggerUIWithConfig`, their tests, or README examples.
## Library Shape
- Package name is `echooapimiddleware`; it is a single-package Go module with no generated code or subpackages.
- It targets Go 1.25 and Echo v5 (`github.com/labstack/echo/v5`). Echo handlers use `func(c *echo.Context) error`.
- Public API accepts `*openapi3.T` from `github.com/getkin/kin-openapi/openapi3`; do not add runtime parsing as part of the middleware path unless explicitly requested.
## Behavior To Preserve
- Serialize the OpenAPI spec once when middleware is created, not on every request.
- `SwaggerYaml` defaults to `/swagger.yaml` and serves only `GET` and `HEAD`; all other methods and paths pass through to the next handler.
- `SwaggerUI` defaults to `/swagger`, also serves `/swagger/` and `/swagger/index.html`, and wires the YAML endpoint.
- `HEAD` responses for YAML and UI must set `Content-Length` and write no body.
- `nil` specs are valid and produce successful empty YAML responses.
- `KeepServers` defaults to false: omit top-level `servers` from emitted YAML without mutating the caller's `*openapi3.T`.
- Generated Swagger UI HTML references unpkg `swagger-ui-dist@5` assets.
## Verification Commands
- Fast local check: `go test ./...`.
- CI-equivalent tests: `go test -race -coverprofile=coverage.txt -covermode=atomic ./...`.
- Focused tests: `go test -run TestSwaggerYaml_RequestRouting .` or `go test -run TestSwaggerUI_DefaultPaths .`.
- Benchmark YAML serving path: `go test -bench BenchmarkSwaggerYamlGET -benchmem .`.
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> When To Use → Library Shape → Behavior To Preserve → Verification Commands → Implementation Notes → Integrating Into A Project
要点 -> Do not try to embed or parse swagger.yaml / openapi.yaml at runtime.
文件/命令 -> github.com/adlandh/echo-oapi-middleware/v2 · SwaggerYaml · SwaggerYamlWithConfig · SwaggerUI · SwaggerUIWithConfig · echooapimiddleware · github.com/labstack/echo/v5 · func(c echo.Context) error
内容 SHA-256 -> 771aa9fc9a9b
原文结构
适用与边界
原文中的明确线索
github.com/adlandh/echo-oapi-middleware/v2、SwaggerYaml、SwaggerYamlWithConfig、SwaggerUI、SwaggerUIWithConfig、echooapimiddleware、github.com/labstack/echo/v5、func(c echo.Context) error