Skip to main content
Version: v3

Apifox Fetcher

Introduction

This plugin is used to directly import OpenAPI documents from Apifox without manually exporting local files to the project. Key features include:

  • Supports fetching OpenAPI documents directly from Apifox projects
  • Supports filtering interfaces by tags
  • Supports multiple OpenAPI versions and export formats
  • Supports custom Apifox extension properties and folder tags

After using this plugin, there is no need to set the input field.

Basic Usage

alova.config.js
import { defineConfig } from '@alova/wormhole';
import { apifox } from '@alova/wormhole/plugin';

export default defineConfig({
generator: [
{
// ...
plugin: [
// Fetch OpenAPI documents from an Apifox project
apifox({
projectId: 'proj-123',
apifoxToken: 'token-abc'
})
]
}
]
});

Configuration Parameters

interface APIFoxBody {
scope?: {
type?: 'ALL' | 'SELECTED_TAGS';
selectedTags?: string[];
excludedByTags?: string[];
};
options?: {
includeApifoxExtensionProperties?: boolean;
addFoldersToTags?: boolean;
};
oasVersion?: '2.0' | '3.0' | '3.1';
exportFormat?: 'JSON' | 'YAML';
environmentIds?: string[];
}

interface ApifoxOptions
extends Pick<APIFoxBody, 'oasVersion' | 'exportFormat'>,
Pick<
NonNullable<APIFoxBody['options']>,
'includeApifoxExtensionProperties' | 'addFoldersToTags'
> {
projectId: string;
apifoxToken: string;
locale?: string;
apifoxVersion?: string;
selectedTags?: string[];
excludedByTags?: string[];
}

function apifox(ApifoxOptions: ApifoxOptions): ApiPlugin;

Parameter Descriptions

Parameter NameTypeDefaultDescription
projectIdstring-Apifox project ID
apifoxTokenstring-Apifox access token
localestring'zh-CN'Language environment
apifoxVersionstring'2024-03-28'Apifox API version
selectedTagsstring[]-Filter interfaces by tags
excludedByTagsstring[]-Exclude interfaces by tags
oasVersion`'2.0''3.0''3.1'`
exportFormat`'JSON''YAML'`'JSON'
includeApifoxExtensionPropertiesbooleanfalseInclude Apifox extension properties
addFoldersToTagsbooleanfalseUse folder paths as tags

Advanced Usage

Filter Interfaces by Tags

// Fetch only interfaces with specific tags
apifox({
projectId: 'proj-123',
apifoxToken: 'token-abc',
selectedTags: ['order', 'user']
});

Exclude Interfaces by Tags

// Exclude interfaces with specific tags
apifox({
projectId: 'proj-123',
apifoxToken: 'token-abc',
excludedByTags: ['test', 'deprecated']
});

Custom OpenAPI Version and Export Format

// Use OpenAPI 3.1 and YAML format
apifox({
projectId: 'proj-123',
apifoxToken: 'token-abc',
oasVersion: '3.1',
exportFormat: 'YAML'
});

Include Apifox Extension Properties

// Include Apifox extension properties
apifox({
projectId: 'proj-123',
apifoxToken: 'token-abc',
includeApifoxExtensionProperties: true
});