Command line tool to create a new N8N node from openAPI specification
This tool creates a new N8N node from an openAPI specification. It generates the node files, credentials, and documentation.
- convert postman collection to openAPI
- Merge multiple openAPI files into one
- create node files from openAPI specification
- create credentials file from openAPI specification
- Multiple credentials
- Multiple nodes
- HTTP Routing based nodes
- Custom node properties
- Custom node methods
- Custom node hooks
npm install -g @oneflow-vn/n8n-nodegen (TO BE PUBLISHED)n8n-nodegen --helpn8n-nodegen init --openapi <openapi-file> --template oneflow-vn/n8n-nodes-template --output <output-dir>check the nodes.config.js file in the output directory
const path = require('path');
module.exports = {
packageName: 'n8n-nodes-<name>',
credentials: {
yourApi: {
displayName: 'Your API',
name: 'firecrawlApi',
className: 'FirecrawlApi',
scheme: 'apiKey',
}
},
nodes: {
yourNode: {
displayName: 'Your Node',
name: 'YourNode',
description: 'Your Node Description',
openapi: path.resolve(__dirname, 'openapi.yml'),
icon: 'fa:fire',
baseUrl: 'https://your-api.com',
credentials: [{
displayName: 'Your API',
name: 'yourApi',
required: true,
}],
},
},
// overwrite the generated files
overwrites: {
operations: [],
},
};pnpm run codegenWe offer two ways to overwrite the generated files:
- Overwrite the generated files by providing the
overwritesobject in thenodes.config.jsfile. This will overwrite the generated operations when running thecodegencommand. - Hook into the node's properties and methods in runtime by replacing th
hooksfiles in the generated node directory.
Overwrites operations
// node.config.js
// overwrite the generated files
overwrites: {
operations: [
// unset all operations that have the 'Content-Type' header
{
has: 'routing.request.headers.Content-Type',
set: false,
},
// match all operations that have the 'type' string and set default value to ''
{
match: {
type: 'string',
},
set: {
type: 'string',
default: '',
},
},
// unset all operations that have the 'Authorization' header
{
has: 'routing.request.headers.Authorization',
set: false,
},
],
},Overwrites by extensions
In the root project directory, create a extensions directory, the structure should be like the generated node directory. The extensions directory will contain the files that you want to overwrite.
- root
- extensions
- YourNode
- resources
- your-resource
- hooks.tsBasically, when running the codegen command, the tool will copy the files from the extensions directory to the generated node directory.
example hooks.ts
import { INodeProperties, INodeType } from 'n8n-workflow';
export default function runHook(
properties: INodeProperties[],
): {
properties: INodeProperties[];
methods: INodeType['methods'];
} {
return {
// do anything with the properties
properties,
// all methods that you want to add to the node
methods: {
listSearch: {
searchDocsApps
}
},
};
}Please make sure to read the Contributing Guide before making a pull request.
Please make sure to read the Code of Conduct before making a pull request.
This project is licensed under the MIT License.