npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jlg_generate_by_swagger

v0.0.45

Published

Use swagger.json to generate the corresponding TS constraint and AXIOS interface call function

Downloads

6

Readme

jlg_generate_by_swagger

为jlg前端项目根据后端的swagger文档生成前端代码(Typescript,Axios)。

安装

npm i jlg_generate_by_swagger@latest -Dnpm i jlg_generate_by_swagger@latest -g

使用方法(局部安装)

1>: 在项目根目录中创建.generateSwaggerrc.ts文件或其它格式详情请见,内容如下:

export default {
	// 远程swagger.json文件URL
	swaggerUrl: 'http://10.1.2.9:10023/swagger/v1/swagger.json',
	// 生成的swagger.json文件路径,默认src/apiType/swagger.json
	swaggerFileName: 'test/apiType/production/swagger.json',
	// 生成的接口文件路径,默认src/apiType/api.ts
	resultFileName: 'test/apiType/production/result.ts',
	// 生成文件中的Typescript类型命名前缀,默认AT_
	interfaceNamePrepend: 'AT_',
	// 封装的axios实例引入路径,默认import axios from '@/request/index'
	axiosUrl: "import axios from '@/axios/index';",
	// 可选,是否需要生成ResponseInterface,默认true
	isNeedResponse: false,
	// 可选,在生成的result文件头部插入一段内容
	resultFileContentHeader: [
		"import { useUserInfoStoreHook } from '@/store/modules/user-info';",
		'const COMPANY_CODE = useUserInfoStoreHook().companyCode;',
	],
	// 可选,在生成的函数中自定义一段逻辑
	axiosFuncContent(_parameterStr: string, handleAxiosUrl: string) {
		if (handleAxiosUrl.includes('${FirmCodeURL}')) {
			return `const FirmCodeURL = COMPANY_CODE`;
		} else {
			return '';
		}
	},
};

2>: 在package.json中添加如下命令:

    "scripts": {
        // ...其它命令
        "jlg_generate_by_swagger": "npx jlg_generate_by_swagger"
    },

3>: 启动终端,在项目根目录下执行命令:npm run jlg_generate_by_swagger等待一段时间之后将会在src文件夹中生成apiType文件夹,文件夹中包含swagger.jsonresult.ts文件。

使用方法(全局安装)

1>: 如同局部安装第一步一致

2>: 启动终端,在项目根目录下执行命令:jlg_generate_by_swagger等待一段时间之后将会在src文件夹中生成apiType文件夹,文件夹中包含swagger.jsonresult.ts文件。

特性

示例

API文档

许可证

Apache

作者/维护者

LiuJie wx:steady_silence

常见问题(FAQ)

1>: 提示类似如下Error代表无法连接远程swagger.json的URL,检测URL拼写是否正确,电脑VPN是否正常连接,后端服务是否正常启动

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled
with .catch(). The promise rejected with the reason "下载Swagger JSON文件时发生错误:connect ETIMEDOUT 10.1.2.9:10031".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

 *  终端进程“C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command npm run jlg_generate_by_swagger”已终止,退出代码: 1。

2>: 如遇其它问题,请及时联系开发人员

参考资料