Repository navigation
Conversation
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.
There was a problem hiding this comment.
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
… selection; keep dry-run correct across runs; require n8n-nodes- package prefix; disambiguate colliding credential names
…erated credentials
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
thanks for the PR
what about adding a new workflow to test the n8n samples similar to https://github.com/OpenAPITools/openapi-generator/blob/master/.github/workflows/samples-typescript-client.yaml ?
There was a problem hiding this comment.
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.
Description
Adds a new
n8ngenerator 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:
optionsfields.collectionfield type.clientCredentialsorauthorizationCodeflow (falls back to a manual access-token field otherwise).README.mddocumenting the package's resources/operations and credentials.Testing
modules/openapi-generator/src/test/java/org/openapitools/codegen/n8n/N8nClientCodegenTest.javacover the generator's option/model/template behavior.samples/client/petstore/n8n, generated frombin/configs/n8n-petstore.yaml.PR checklist
./mvnw clean package,./bin/generate-samples.sh ./bin/configs/*.yaml, and./bin/utils/export_docs_generators.sh, and committed all resulting changes.Summary by cubic
Adds a new
n8ngenerator that produces an installable n8n community node package (TypeScript) from an OpenAPI spec instead of a traditional client SDK. Closes #25802.What it generates
Notes
n8n-nodes-prefix, and node/credential names are prefixed to avoid cross-package collisions.dryRunthroughGlobalSettingsso custom file writes respect--dry-run, including across repeated runs.--ignore-scriptsto avoid a native build failure fromn8n-workflow's transitiveisolated-vmdependency.Written for commit e77fb1c. Summary will update on new commits.