@devlikeapro/n8n-openapi-node

中文文档
0.1.4发布于 2025/02/24MITTypeScriptESM + CJS构建来源已验证近 30 天下载 35.9万

Turn OpenAPI specs into n8n node

原始使用文档
文档目录14 节
  1. Installation
  2. Usage
  3. Resource
  4. Operation
  5. Query Parameters
  6. Request Body
  7. Headers
  8. Resource
  9. Operation
  10. Fields
  11. I have only OpenAPI v2 spec, what can I do?
  12. I have openapi.yaml spec, what can I do?
  13. How to set up credentials from OpenAPI v3 spec?
  14. Why it doesn't work with my OpenAPI spec?

@devlikeapro/n8n-openapi-node

openapi logo n8n logo

Turn Your OpenAPI (Swagger) spec into a n8n node!

npm version


Quick Start

If you have OpenAPI specification - you can easily in few minutes create your community node for n8n!

It'll still require to create and publish n8n-nodes-<yourproject> npm package, but you can use this package to generate most of the code.

👉 We recommend using one of repo for the n8n-nodes-<yourproject> package:

Find more real-world examples in Use Cases section.

example

Installation

Add @devlikeapro/n8n-openapi-node as dependency

npm install @devlikeapro/n8n-openapi-node
# OR
pnpm add @devlikeapro/n8n-openapi-node
# OR
yarn add @devlikeapro/n8n-openapi-node

Usage

  1. Add your openapi.json to src/{NodeName} folder (use OpenAPI v3 and json, see FAQ if you don't have it)

  2. Get your Node.properties from OpenAPI v3 spec:

import {INodeType, INodeTypeDescription, NodeConnectionType} from 'n8n-workflow';
import {N8NPropertiesBuilder, N8NPropertiesBuilderConfig} from '@devlikeapro/n8n-openapi-node';
import * as doc from './openapi.json'; // <=== Your OpenAPI v3 spec

const config: N8NPropertiesBuilderConfig = {}
const parser = new N8NPropertiesBuilder(doc, config);
const properties = parser.build()

export class Petstore implements INodeType {
  description: INodeTypeDescription = {
    displayName: 'Petstore',
    name: 'petstore',
    icon: 'file:petstore.svg',
    group: ['transform'],
    version: 1,
    subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
    description: 'Interact with Petstore API',
    defaults: {
      name: 'Petstore',
    },
    inputs: [NodeConnectionType.Main],
    outputs: [NodeConnectionType.Main],
    credentials: [
      {
        name: 'petstoreApi',
        required: false,
      },
    ],
    requestDefaults: {
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      baseURL: '={{$credentials.url}}',
    },
    properties: properties, // <==== HERE
  };
}

How it works

N8NPropertiesBuilder extracts few entities from OpenAPI v3 to your n8n community node:

  1. Resource - a list of Tags from OpenAPI spec
  2. Operation - a list of Operations from OpenAPI spec (aka Actions in n8n)
  3. Query Parameters - a list of operation.parameters from OpenAPI spec
  4. Request Body - a list of operation.requestBody.content from OpenAPI spec (only for application/json)
  5. Headers - a list of operation.parameters from OpenAPI spec

Resource

By default, it get Tags from OpenAPI spec and converts them to Resource in n8n.

Operation

By default, it gets Operations from OpenAPI spec and converts them to Actions in n8n.

Query Parameters

It gets operation.parameters from OpenAPI spec and converts them to Query Parameters in n8n.

Request Body

It doesn't create the full structure of the request body, only the first level of properties. So if you have request body as

{
  "name": "string",
  "config": {
    "id": 0,
    "name": "string"
  }
}

it creates 2 fields in n8n:

  • name - with default value string
  • config - with default value {"id": 0, "name": "string"}

Headers

It gets operation.parameters from OpenAPI spec and converts them to Headers in n8n.

Customization

Resource

You can override the way how to extract Resource from OpenAPI Tag defining your custom IResourceParser:

import {IResourceParser} from '@devlikeapro/n8n-openapi-node';

export class CustomResourceParser {
  CUSTOM_DESCRIPTION = {
    "cats": "Cats are cute",
  }

  name(tag: OpenAPIV3.TagObject): string {
    // Your custom logic here
    if (tag['X-Visible-Name']) {
      return tag['X-Visible-Name'];
    }
    return lodash.startCase(tag.name);
  }

  value(tag: Pick<OpenAPIV3.TagObject, "name">): string {
    // Remove all non-alphanumeric characters
    const name = tag.name.replace(/[^a-zA-Z0-9_-]/g, '')
    return lodash.startCase(name)
  }

  description(tag: OpenAPIV3.TagObject): string {
    // Your custom logic here
    return this.CUSTOM_DESCRIPTION[tag.name] || tag.description || '';
  }
}

Alternatively, you can use DefaultResourceParser and override only the methods you need. The default implementation you can find in src/ResourceParser.ts

import {OpenAPIV3} from 'openapi-types';
import * as lodash from 'lodash';
import {DefaultResourceParser} from '@devlikeapro/n8n-openapi-node';

export class CustomResourceParser extends DefaultResourceParser {
  value(tag: OpenAPIV3.TagObject): string {
    return lodash.startCase(tag.name.replace(/[^a-zA-Z0-9_-]/g, ''));
  }
}

Then you use it in N8NPropertiesBuilder in config.resource:

import {N8NPropertiesBuilder, N8NPropertiesBuilderConfig} from '@devlikeapro/n8n-openapi-node';
import * as doc from './openapi.json';

import {CustomResourceParser} from './CustomResourceParser';

const config: N8NPropertiesBuilderConfig = {
  resource: new CustomResourceParser()
}
const parser = new N8NPropertiesBuilder(doc, config);
const properties = parser.build()

Find real example in @devlikeapro/n8n-nodes-waha repository.

Operation

You can override the way how to extract Operation from OpenAPI Operation defining your custom IOperationParser:

import {IOperationParser} from '@devlikeapro/n8n-openapi-node';

export class CustomOperationParser implements IOperationParser {
  shouldSkip(operation: OpenAPIV3.OperationObject, context: OperationContext): boolean {
    // By default it skips operation.deprecated
    // But we can include all operations
    return false
  }

  name(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
    if (operation['X-Visible-Name']) {
      return operation['X-Visible-Name'];
    }
    return lodash.startCase(operation.operationId)
  }

  value(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
    return lodash.startCase(operation.operationId)
  }

  action(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
    // How operation is displayed in n8n when you select your node (right form)
    return operation.summary || this.name(operation, context)
  }

  description(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
    return operation.description || operation.summary || '';
  }
}

Alternatively, you can use DefaultOperationParser and override only the methods you need. The default implementation you can find in src/OperationParser.ts

import {DefaultOperationParser} from '@devlikeapro/n8n-openapi-node';

export class CustomOperationParser extends DefaultOperationParser {
  name(operation: OpenAPIV3.OperationObject, context: OperationContext): string {
    // NestJS add operationId in format CatController_findOne
    let operationId: string = operation.operationId!!.split('_').slice(1).join('_');
    if (!operationId) {
      operationId = operation.operationId as string;
    }
    return lodash.startCase(operationId);
  }
}

Then you use it in N8NPropertiesBuilder in config.operation:

import {N8NPropertiesBuilder, N8NPropertiesBuilderConfig} from '@devlikeapro/n8n-openapi-node';
import * as doc from './openapi.json';
import {CustomOperationParser} from './CustomOperationParser';

const config: N8NPropertiesBuilderConfig = {
  operation: new CustomOperationParser()
}
const parser = new N8NPropertiesBuilder(doc, config);
const properties = parser.build()

Find real example in @devlikeapro/n8n-nodes-waha repository.

Fields

You can override some values for fields at the end, when full properties are ready.

Here's example how you can override session field value (which has 'default' string default value) to more n8n suitable =${$json.session}}:

import {Override} from '@devlikeapro/n8n-openapi-node';

export const customDefaults: Override[] = [
  {
    // Find field by fields matching
    find: {
      name: 'session',
      required: true,
      type: 'string',
    },
    // Replace 'default' field value
    replace: {
      default: '={{ $json.session }}',
    },
  },
];

Then you use it in N8NPropertiesBuilder:


import {N8NPropertiesBuilder, N8NPropertiesBuilderConfig} from '@devlikeapro/n8n-openapi-node';
import * as doc from './openapi.json';
import {customDefaults} from './customDefaults';

const parser = new N8NPropertiesBuilder(doc);
const properties = parser.build(customDefaults);

Find real example in @devlikeapro/n8n-nodes-waha repository.

Use Cases

Here's n8n community nodes generated from OpenAPI specifications you can use for reference:

FAQ

I have only OpenAPI v2 spec, what can I do?

Paste your OpenAPI 2.0 definition into https://editor.swagger.io and select Edit > Convert to OpenAPI 3 from the menu.

https://stackoverflow.com/a/59749691

I have openapi.yaml spec, what can I do?

Paste your yaml spec to https://editor.swagger.io and select File > Save as JSON from the menu.

How to set up credentials from OpenAPI v3 spec?

Right now you need to define it manually. Check ChatWoot node for an example.

Why it doesn't work with my OpenAPI spec?

Open a new issue and please attach your openapi.json file and describe the problem (logs are helpful too).

版本与发布记录

@devlikeapro/n8n-openapi-node 共发布 5 个版本,首次发布于 2024/09/22;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.4latest2025/02/241.7 年前
0.1.32025/02/241.7 年前
0.1.22025/02/241.7 年前
0.1.12025/02/201.7 年前
0.1.02024/09/222 年前

关于 @devlikeapro/n8n-openapi-node 的常见问题

@devlikeapro/n8n-openapi-node 是什么?

Turn OpenAPI specs into n8n node

如何安装 @devlikeapro/n8n-openapi-node?

在项目目录运行 npm install @devlikeapro/n8n-openapi-node,或使用 pnpm add / yarn add / bun add。

@devlikeapro/n8n-openapi-node 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devlikeapro/n8n-openapi-node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@devlikeapro/n8n-openapi-node 可以商用吗?

@devlikeapro/n8n-openapi-node 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@devlikeapro/n8n-openapi-node 的下载量有多少?

根据 npm 官方下载统计,@devlikeapro/n8n-openapi-node 在 2026/10/12 – 2026/11/10 这 30 天内被下载 359,099 次,日均约 11,970 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devlikeapro/n8n-openapi-node 还在维护吗?

最新版本 0.1.4 发布于 2025/02/24(1.7 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/09/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。