Skip to content

feat(n8n): add n8n community node client generator - #25803

Open
Riventh wants to merge 24 commits into
OpenAPITools:masterfrom
Riventh:feat_n8n
Open

Riventh wants to merge 24 commits into
OpenAPITools:masterfrom
Riventh:feat_n8n

Conversation

@Riventh

@Riventh Riventh commented Nov 23, 2026 •

Copy link
Copy Markdown

Description

Adds a new n8n generator that produces an n8n community node package (TypeScript) from an OpenAPI spec, instead of a traditional client SDK.

Closes #25802

What it generates

Given an OpenAPI spec, the generator produces a ready-to-build n8n community node package:

  • One n8n node class grouping the spec's operations into Resource (per OpenAPI tag) / Operation (per operation) dropdowns, matching n8n's usual convention for multi-operation nodes.
  • Request parameters mapped to n8n field types (string/number/boolean/options/collection), including:
    • Enum parameters mapped to n8n options fields.
    • Array parameters mapped to n8n's collection field type.
    • JSON object request bodies flattened into individual node fields (with disambiguation when a flattened field name collides with another parameter), falling back to a generic JSON field for shapes that don't map cleanly (e.g. arrays of complex objects).
  • One generated n8n credential type per security scheme declared in the spec (API key, HTTP basic, HTTP bearer), or OAuth2 auto-wired to n8n's built-in OAuth2 credential when the scheme declares a clientCredentials or authorizationCode flow (falls back to a manual access-token field otherwise).
  • Each operation authenticates with whichever credential matches its own declared security requirement (or the spec's global default), so multi-scheme specs are handled per-operation rather than per-package.
  • A generated README.md documenting the package's resources/operations and credentials.

Testing

  • Unit tests under modules/openapi-generator/src/test/java/org/openapitools/codegen/n8n/N8nClientCodegenTest.java cover the generator's option/model/template behavior.
  • Sample output lives under samples/client/petstore/n8n, generated from bin/configs/n8n-petstore.yaml.
  • The generated sample package was also verified to build and load correctly in a live n8n instance.

PR checklist

  • Read the contribution guidelines.
  • Ran ./mvnw clean package, ./bin/generate-samples.sh ./bin/configs/*.yaml, and ./bin/utils/export_docs_generators.sh, and committed all resulting changes.
  • If your PR is targeting a particular programming language, @mention the technical committee members. (n8n isn't a programming-language target in the usual sense, so skipping this.)

Summary by cubic

Adds a new n8n generator that produces an installable n8n community node package (TypeScript) from an OpenAPI spec instead of a traditional client SDK. Closes #25802.

What it generates

  • A node class grouping operations into Resource and Operation dropdowns from the spec's tags, with path-derived grouping for untagged operations and collision disambiguation.
  • Request parameters mapped to n8n field types: enums become options, arrays become collection fields, and JSON object bodies are flattened into individual fields. Header, cookie, and form parameters are sent correctly.
  • One credential type per declared security scheme, with OAuth2 client-credentials and authorization-code flows wired to n8n's built-in OAuth2 credential. Unmappable schemes are documented instead of hidden.
  • Per-operation credential selection that falls back to the spec's global default and sends unauthenticated requests when no security applies.
  • Package metadata, TypeScript config, and a README documenting resources, operations, and credentials.

Notes

  • Package names must use the n8n-nodes- prefix, and node/credential names are prefixed to avoid cross-package collisions.
  • Exposes dryRun through GlobalSettings so custom file writes respect --dry-run, including across repeated runs.
  • Honors skip-overwrite, custom templates, and supportingFiles selection, and skips blank optional form fields. Adds unit tests (including a compiled-TypeScript check) and a committed petstore sample, with CI building the sample on Node 20 and 22 and installing dependencies with --ignore-scripts to avoid a native build failure from n8n-workflow's transitive isolated-vm dependency.

Written for commit e77fb1c. Summary will update on new commits.

View guided diff

Adds a new "n8n" generator target that turns an OpenAPI spec into an
installable n8n community-node TypeScript package: a node definition
grouping operations into n8n's Resource/Operation UI convention (reusing
the existing per-tag operation grouping), a credential definition derived
from the spec's highest-priority declared security scheme, package.json,
tsconfig.json, and README.

- N8nClientCodegen.java registered via the CodegenConfig SPI, following
  the existing ZapierClientCodegen as a precedent
- mustache templates under resources/n8n/
- unit tests covering SPI discovery, full generation, tag-based
  Resource/Operation grouping, and credential scheme priority/fallback
- bin/configs/n8n-petstore.yaml and committed sample output under
  samples/client/petstore/n8n/, matching every other generator's
  CI-verified sample convention
- docs/generators/n8n.md and regenerated docs/generators.md index
- Group untagged operations by a path-derived Resource instead of a
  single catch-all "Default", and disambiguate colliding sanitized tag
  names so two different tags never silently merge into one Resource.
- Generate one credential class/file per declared security scheme
  instead of only the single highest-priority one, so specs declaring
  more than one scheme (e.g. apiKey + oauth2) get a usable credential
  for each.
- Add test coverage for the HTTP basic and HTTP bearer credential
  branches and the oneOf/anyOf generic-JSON fallback, none of which the
  Petstore sample alone exercises.
- Run a tsc --noEmit check as part of the test suite so generated
  TypeScript validity is enforced automatically instead of only being
  checked by hand.
Each generated operation now authenticates with the credential matching
its own declared security scheme instead of always applying the single
highest-priority one to every request. Petstore's own spec exercises
this directly: addPet/updatePet declare petstore_auth while getPetById/
getInventory declare api_key, and each now resolves to its own
credential within the same generated node.

genericFunctions.mustache's apiRequest helper takes the credential name
as a runtime argument and branches on it, rather than hardcoding the
first generated credential at generation time.
Operations with no security requirement at all (and no spec-wide
default to inherit) were being authenticated with the single
highest-priority generated credential anyway. Petstore's own spec
exercises this: placeOrder, getOrderById, getUserByName, loginUser, and
deleteOrder declare no security and are genuinely public on the live
API, but all five were getting apiKeyCredentials forced onto their
requests regardless.

The underlying framework already distinguishes "no local override,
inherits global" from an explicit security: [] opt-out, leaving
authMethods null in both cases where no security actually applies.
Removed the fallback so the generator trusts that signal instead of
second-guessing it - affected operations now send unauthenticated
requests, matching what the spec actually requires.

Also corrected the generated README's "Known limitations" section,
which still described the per-operation credential selection as a
single always-primary fallback after that behavior was already
replaced, and updated a stale class-level comment claiming the
generator doesn't override the framework's tag-grouping logic when it
now does.
Three doc comments still described the single-highest-priority
fallback that per-operation credential selection already replaced, and
one described a credential fallback that was later removed entirely in
favor of sending unauthenticated requests when no security applies.
Two of these ship directly into generated output (credentials.mustache,
genericFunctions.mustache); the third is an internal Javadoc.

All three now describe the actual mechanism: an operation's own
declared scheme, falling back to the spec's global default only when
the operation declares none of its own, and sending an unauthenticated
request when neither applies.
writeCredentialFile() wrote credential files directly via Files.write,
bypassing the framework's templateProcessor pipeline entirely - the
same pipeline --dry-run intercepts to report changes without making
them. Running generate --dry-run against the n8n target confirmed this:
both generated credential files were written to disk for real despite
dry-run, and neither appeared in the "Dry Run Results" report.

DefaultGenerator had no existing way to expose its dry-run state to a
CodegenConfig that needs to write files outside the standard
SupportingFile mechanism, so it now publishes dryRun through
GlobalSettings, the same thread-local mechanism already used for other
cross-cutting flags in that file. Purely additive - no other generator
currently reads this key, so no other generator's behavior changes.
…lisions

Wire the already-declared nodePrefix option into the generated node's
class name, file name, and INodeTypeDescription.name, plus the
credential class/file names. Previously these were hardcoded (Api,
Api.node.ts, name: 'api') regardless of the source spec, so installing
two generated packages into the same n8n instance caused one to
silently fail registration.
Arrays of strings/numbers/enum values (e.g. findPetsByStatus's status
query parameter) were falling into the same generic-JSON fallback
reserved for genuinely-unmappable shapes like oneOf/anyOf. Map them to
n8n's collection field type instead, with multipleValues support and
per-item enum choices where applicable.
…ization-code flows

A security scheme declaring exactly one of these two flows now extends
n8n's generic oAuth2Api credential (authorization redirects and token
refresh handled by n8n itself), pre-filled with the spec's declared
authorization/token URLs and scopes. Any other flow, or a scheme
declaring more than one flow at once, keeps the manual-paste-a-token
fallback instead of guessing which flow to perform.
…ne exist

A security scheme this generator cannot map at all (e.g. openIdConnect)
used to be indistinguishable, in the generated README, from a spec
that declares no security at all - the "no security scheme" message
rendered either way, actively claiming something false and hiding the
real limitation. Name the unmapped scheme(s) explicitly instead, both
in the Credentials section and a new Known limitations bullet.
The generator's own Failure Contract documents, as a MUST, that a
spec with zero operations still produces a valid, loadable package
rather than throwing - add a regression test for this previously
unverified contract clause.
A parameter's spec-declared OpenAPI default was never used anywhere
in the generated output - fields always fell back to a generic
type-based filler (false/0/''/first enum choice) regardless of what
the spec actually declared. Compute a ready-to-embed default literal
per field instead, matching enum defaults against the declared
choices rather than always picking the first one.
A JSON object request body (e.g. addPet's Pet body) was exposed as a
single opaque JSON field the user had to hand-fill with a raw blob for
the whole object. Flatten its top-level properties into individual
fields instead, reusing the existing field-type/default/required
mapping machinery, and reassemble the body in execute() from the
individual fields instead of merging one opaque parameter.

Free-form objects, maps, arrays, and composed (oneOf/anyOf) bodies
that don't populate a fixed property list are left on the existing
opaque-body/generic-JSON fallback.
An array of complex objects/model references (e.g.
createUsersWithArrayInput's body, an array of User) was mapping to
the collection field type introduced for arrays of primitives, whose
single-scalar-value per-entry sub-field has no way to represent a
full object - the generated node couldn't correctly call that
operation at all. Fall back to the generic JSON field instead, which
can at least accept a real JSON array of full objects.
The json field type's default literal was hardcoded to {} regardless
of whether the underlying value is an object or an array. An array
of complex objects (e.g. createUsersWithArrayInput's User body, or
addPet's tags property) now defaults to [], matching the shape the
API actually expects; genuinely object-shaped json fallbacks (free-
form objects, nested object refs) still default to {}.
…ameters

A flattened body property (e.g. updateUser's User.username) could
share its n8n-internal field name with another parameter already on
the same operation (updateUser's own path parameter, username) - n8n
stores parameter values in a flat map keyed by name, so the generated
node couldn't set the path segment and the body field independently.

Disambiguate the n8n-internal parameter name with a suffix when this
happens, mirroring the existing Resource-tag collision pattern. The
real JSON body key is left untouched so the correct key still reaches
the API.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 23 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

View guided diff | Re-trigger cubic

Comment thread docs/generators/n8n.md Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 18 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

…detection, skip blank optional form fields, and clarify security: [] opt-out wording
@@ -0,0 +1,6 @@
generatorName: n8n
outputDir: samples/client/petstore/n8n

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @wing328 thanks for the feedback. Honestly you are right, thiw would be better. I added a small workflow in this MR.

npm install was failing on Node 20.x due to a node-gyp build error in
isolated-vm, a transitive dependency of n8n-workflow pulled in only for
runtime expression sandboxing. This sample only needs n8n-workflow's
type declarations, so --ignore-scripts avoids the unrelated native build.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Generator: n8n community node client

2 participants