Socket
Book a DemoInstallSign in
Socket

@pubinfo/openapi

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pubinfo/openapi

Generate request files according to the OpenAPI.

latest
Source
npmnpm
Version
0.9.0
Version published
Maintainers
3
Created
Source

@pubinfo/openapi

npm version Monorepo License

Generate request files according to the OpenAPI.

Usage

Need config file in your project root directory:

// openapi.config.js / openapi.config.ts
export default {
  /* options */
}

and then run:

npx @pubinfo/openapi@latest generate

Configuration

import { defineConfig } from '@pubinfo/openapi'

export default defineConfig({
  // 是否启用,默认 true
  enabled: true,

  // 忽略缓存强制生成接口文件,默认 false
  force: false,

  // 预设配置
  presets: [
    presetName({ /* preset options */ }),
  ],

  // 文件默认导入
  imports: {
    '@/api': 'request', // import request from '@/api'
    'request': ['foo', 'bar'], // import { foo , bar } from 'request'
    './api': [{ name: 'foo', as: 'bar' }] // import { foo as bar } from './api'
  },

  // Swagger2.0 / OpenAPI3.0 地址,直接指向JSON的地址
  input: 'http://your/api-doc',

  // 文件输出目录
  output: '/src/api',

  // 缓存目录
  cacheDir: 'node_modules/.pubinfo-openapi',

  // 自定义 hooks, 透传 `@umijs/openapi` 的 `hook` 配置
  hooks: {
    customFunctionName: data => data.operationId
  },

  // 接口文档登录凭证
  credentials: {
    username: '',
    password: ''
  },

  // 请求远程文档时的超时时间, 为0不限制超时时间
  timeout: 5000,

  // 批量配置
  batch: [
    {
      imports: {},
      input: '',
      output: '',
      hooks: {},
      presets: [],
      credentials: {},
      timeout: 0
    }
  ]
})

Keywords

openapi

FAQs

Package last updated on 18 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts