public-api

公共 API(public-api)技能。用于添加、迁移或更新带有 @PublicApiController 的 n8n 公共 API v1 端点,包括公共 DTO、API 密钥与 RBAC 范围、游标分页、与 OpenAPI 和覆盖率集成,以及相关测试。适用于在 packages/cli/src/public-api/v1/ 目录下工作,或在通过 /api/v1 暴露现有服务时使用。

仓库最近推送
GitHub Stars
212,639
Forks
61,711
Issues / PRs
308

预览截图

来自skillπ 实验室的展示

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "public-api":https://skillpi.com/zh/skills/deepskill-b002e4e8eeca21066c2830d21665e29975cc439d09f934de92fa23d7525c542a。安装前核对上游来源和版本:https://github.com/n8n-io/n8n。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

公共 API(public-api)技能。用于添加、迁移或更新带有 @PublicApiController 的 n8n 公共 API v1 端点,包括公共 DTO、API 密钥与 RBAC 范围、游标分页、与 OpenAPI 和覆盖率集成,以及相关测试。适用于在 packages/cli/src/public-api/v1/ 目录下工作,或在通过 /api/v1 暴露现有服务时使用。

0 下载

介绍来源: third_party · n8n-io · 1.0.0 参考来源

SkillPi 解读

能完成的任务
来源文档未说明。
适合谁
来源文档未说明。
输入和输出
来源文档未说明。
软件、账号及付费要求
来源文档未说明。
限制与区别
来源文档未说明。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: n8n:public-api
description: >-
  Adds, migrates, or updates n8n Public API v1 endpoints with @PublicApiController
  — public DTOs, API-key and RBAC scopes, cursor pagination, OpenAPI + coverage
  wiring, and tests. Use when working under packages/cli/src/public-api/v1/ or
  when exposing an existing service through /api/v1.

Public API v1

Public API v1 lives in packages/cli/src/public-api/v1/, mounted at /api/v1 with API-key auth and public error formatting via PublicApiControllerRegistry (packages/cli/src/public-api/public-api-controller.registry.ts).

Two rule tiers: invariants (never break) and team defaults (follow unless an existing public contract forces otherwise). When this skill and the code disagree on a detail, the code wins — so open the files below. That is a reason to check the code, not license to drop a team default.

Non-negotiable rules

  • New endpoints are @PublicApiController classes under v1/controllers/, one *.public.controller.ts per feature. A controller is a class — never export = (the legacy tuple style; require-public-api-controller flags it).
  • Public API and internal REST are separate HTTP surfaces. A public controller never calls an internal controller/endpoint; both reuse the same service.
  • Controllers and handlers delegate to a service — never import a repository or Container.get(…Repository) (no-repository-in-public-api-handler).
  • Input/output go through DTOs from @n8n/api-types; every JSON route declares @ApiResponse(Dto).
  • Register each controller via a side-effect import in v1/controllers/index.ts (public-api-controllers.test.ts fails otherwise).
  • Don't add business logic to legacy express-openapi-validator (EOV) handlers.
  • Migrating a legacy endpoint must not change its public contract.

These are n8n-local-rules ESLint rules (see packages/cli/eslint.config.mjs) and can't be silenced inline (no-public-api-guardrail-disable). The off allowlist there covers pre-existing legacy files only — it's shrink-only, don't add to it.

Team defaults

  • List endpoints: cursor-based pagination (internal API uses both cursor- and page-based — don't copy an internal endpoint's model).
  • Updates: full-object PUT, not PATCH. A successful GET body should be acceptable as a PUT body for the same resource (round-trip), aside from server-managed/immutable fields.
  • Strict input DTOs; output DTOs are an allowlist of public fields.
  • Never return real secrets/tokens in responses or error details — mask with the resource's sentinel/placeholder (or omit). Echoing that sentinel on PUT means keep; any other value replaces. Detail: Updates and write-only secrets.
  • "Test connection/config" endpoints validate the request body (test-before-save).

Architecture

Public and internal are sibling routes over one shared, HTTP-agnostic service; neither calls the other.

GET /rest/tags    → TagsController         ┐  JWT auth, internal shape
                                            ├─→ TagService
GET /api/v1/tags  → TagsPublicController   ┘  API-key auth, public DTO

Reuse the service behavior. Reuse a DTO only when public and internal contracts are intentionally identical; otherwise make a public-specific DTO that doesn't depend on a UI-oriented internal shape.

Before editing

Open these — they are the source of truth, not this skill:

  • v1/controllers/ — copy structure from tags.public.controller.ts (list + cursor) or workflows.public.controller.ts (@Param + @ProjectScope), and index.ts for the barrel.
  • Decorators in packages/@n8n/decorators/src/controller/: public-api-controller.ts, api-key-scope.ts, api-response.ts, api-error-response.ts, api-summary.ts, api-description.ts, api-tags.ts, route.ts, scoped.ts, args.ts, licensed.ts.
  • The OpenAPI generator (reads the decorators above, no hand-written YAML needed for a controller route): v1/openapi-gen/generate.ts, v1/openapi-gen/decorator-routes.ts.
  • Pagination helpers: v1/shared/services/pagination.service.ts (decodeCursor, encodeNextCursor).
  • DTOs: packages/@n8n/api-types/src/dto/.
  • Gating tests: v1/__tests__/public-api-controllers.test.ts, v1/__tests__/scope-parity.test.ts, v1/openapi-gen/__tests__/generated-spec-drift.test.ts.
  • The internal controller for this resource and its neighboring functional tests.

Declaring a controller

A controller is a class marked @PublicApiController('/base') that injects the shared service via its constructor and delegates to it. Copy the shape from an existing controller in v1/controllers/ with the same operation type and auth model; reuse only what applies. Decorators, all from @n8n/decorators:

Decorator Use
@PublicApiController('/base') Class marker; mounts routes at /api/v1/base.
@Get/@Post/@Put/@Patch/@Delete('/path') Route method.
@ApiKeyScope('res:action') API-key grant check.
@ProjectScope/@GlobalScope('res:action') User RBAC check.
@ApiResponse(status) / @ApiResponse(status, Dto) Success status + (optional) output DTO; registry .parse()s + strips the return value. Exactly one per route — a second @ApiResponse throws. 204 can't carry a DTO — throws.
@ApiErrorResponse(status) Declares an additional documented non-2xx status (e.g. 404, 409). Stack multiple for more than one. 400/401/403 are added automatically (body/query present, always, and @ApiKeyScope present, respectively) — don't declare those yourself.
@ApiSummary(text) / @ApiDescription(text) / @ApiTags([...]) OpenAPI summary/description/tags. @ApiTags sorts alphabetically regardless of the order you pass. All optional but expected on every real route.
@Query / @Body / @Param('name') Bind + validate via a Z.class DTO / path param.
@Licensed('feat') Gates the route on a single BooleanLicenseFeature; PublicApiControllerRegistry runs its own license middleware (after auth/@ApiKeyScope/@ProjectScope

Authorization (easy to get wrong)

  • @ApiKeyScope (what the API key is granted) and @ProjectScope/@GlobalScope (what the user may do) are independent. Use both when the model needs both.
  • @ProjectScope reads req.params as-is and does not remap id — name the path param what the resolver expects (workflowId, credentialId, projectId, dataTableId, …). A generic id often fails.
  • @ApiKeyScope takes a string, { anyOf: [...] }, or { allOf: [...] } — never a bare array. The scope must exist in the permissions registry (API_KEY_RESOURCES in @n8n/permissions); scope-parity.test.ts fails on an orphan scope.

DTOs

  • Build the public response shape explicitly; don't return an ORM entity and lean on @ApiResponse stripping to hide fields.
  • Treat the output DTO as an allowlist. Re-check nested relations, ownership fields, tokens, and encrypted values.
  • Make input DTOs strict so unknown/partial fields aren't silently accepted.
  • Secrets: never return a real secret; use the resource's sentinel/placeholder (or omit). See Updates and write-only secrets.

List endpoints (cursor pagination)

Copy the cursor flow from tags.public.controller.ts. Use publicApiPaginationSchema plus decodeCursor / encodeNextCursor from the shared pagination service; the cursor is opaque; return { data, nextCursor } (never a bare array) with nextCursor: null on the last page; an invalid cursor is a 400. Preserve an existing endpoint's pagination as-is. Detail: List endpoints and cursor pagination.

Wiring checklist

  1. v1/controllers/<feature>.public.controller.ts + side-effect import in v1/controllers/index.ts.
  2. Public DTO in @n8n/api-types + export from the barrel (src/dto/).
  3. @ApiKeyScope value exists in the permissions registry.
  4. Don't hand-write the OpenAPI path or x-required-scope for a controller route — the generator (v1/openapi-gen/generate.ts) builds it from your decorators (@ApiSummary/@ApiDescription/@ApiTags/@ApiKeyScope/ @ApiResponse/@ApiErrorResponse). Run the full pnpm build and commit the regenerated handlers/<feature>/spec/paths/*.generated.yml fragment(s) and openapi.decorator-routes.generated.yml — generated-spec-drift.test.ts fails CI if they're stale. pnpm run build:data alone is not enough after touching a controller: it runs the generator against the already-compiled dist/, so a new/changed controller silently doesn't show up unless tsc ran first.
  5. Add the route to packages/nodes-base/nodes/N8n/n8n-api-coverage.json.
  6. Tests.

Testing

Always cover: happy path, input-validation failure, missing API-key scope, RBAC denial. Prefer covering the business path in packages/cli/test/integration/public-api/ (real HTTP + DB); mocked-service unit tests don't replace that. Add the cases that apply (cursor pages, not-found/conflict, no sensitive fields, credential keep/replace, migration contract) — see Testing matrix. Match the nearest existing tests.

More detail (reference.md)

版本历史

  1. [email protected] GitHub ↗
    原版更新说明

    ## [1.123.100](https://github.com/n8n-io/n8n/compare/[email protected]@1.123.100) (2026-11-20) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/n8n-io/n8n/pull/44590?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/n8n-io/n8n/44590?returnTo=https%3A%2F%2Fgithub.com%2Fn8n-io%2Fn8n%2Fpull%2F44590&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->

  2. stable GitHub ↗
    原版更新说明

    ## [2.48.7](https://github.com/n8n-io/n8n/compare/[email protected]@2.48.7) (2026-11-20) ### Bug Fixes * **core:** End memory guard hold when hold-limit stop frees no memory ([#44463](https://github.com/n8n-io/n8n/issues/44463)) ([22643e1](https://github.com/n8n-io/n8n/commit/22643e170e5ae7ddc86bb61b7d1d5d9e1aab1486)) * **core:** Store plain input data in the error output of scripting nodes ([#44530](https://github.com/n8n-io/n8n/issues/44530)) ([c26c923](https://github.com/n8n-io/n8n/commit/c26c923b248d33e80aad51a7abc80aa07eb6c595)) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/n8n-io/n8n/pull/44594?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/n8n-io/n8n/44594?returnTo=https%3A%2F%2Fgithub.com%2Fn8n-io%2Fn8n%2Fpull%2F44594&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->

  3. [email protected] GitHub ↗
    原版更新说明

    ## [2.48.7](https://github.com/n8n-io/n8n/compare/[email protected]@2.48.7) (2026-11-20) ### Bug Fixes * **core:** End memory guard hold when hold-limit stop frees no memory ([#44463](https://github.com/n8n-io/n8n/issues/44463)) ([22643e1](https://github.com/n8n-io/n8n/commit/22643e170e5ae7ddc86bb61b7d1d5d9e1aab1486)) * **core:** Store plain input data in the error output of scripting nodes ([#44530](https://github.com/n8n-io/n8n/issues/44530)) ([c26c923](https://github.com/n8n-io/n8n/commit/c26c923b248d33e80aad51a7abc80aa07eb6c595)) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/n8n-io/n8n/pull/44594?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/n8n-io/n8n/44594?returnTo=https%3A%2F%2Fgithub.com%2Fn8n-io%2Fn8n%2Fpull%2F44594&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->

  4. [email protected] GitHub ↗
    原版更新说明

    ## [1.123.99](https://github.com/n8n-io/n8n/compare/[email protected]@1.123.99) (2026-11-19) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/n8n-io/n8n/pull/44433?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/n8n-io/n8n/44433?returnTo=https%3A%2F%2Fgithub.com%2Fn8n-io%2Fn8n%2Fpull%2F44433&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->

  5. [email protected] GitHub ↗
    原版更新说明

    ## [2.48.6](https://github.com/n8n-io/n8n/compare/[email protected]@2.48.6) (2026-11-19) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/n8n-io/n8n/pull/44436?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/n8n-io/n8n/44436?returnTo=https%3A%2F%2Fgithub.com%2Fn8n-io%2Fn8n%2Fpull%2F44436&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->

此处仅展示最近 5 个版本。 在原站查看完整版本历史 ↗

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供了 n8n 公共 API v1 端点的完整开发规范,覆盖控制器、DTO、授权、分页、OpenAPI 集成和测试
触发精准95/100

亮点

  • 触发词精准完整,覆盖多种变体,边界清晰,明确指出了适用场景和使用路径
结构规范90/100

亮点

  • Phase/步骤清晰,有出口条件,含端到端示例,frontmatter完整,单文件≤500行
执行可靠88/100

亮点

  • 工具来源明确,参数正确,覆盖主要异常,不可逆操作有确认机制
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

来源文档未说明。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。