关于使用openapi-typescript-codegen遇到的坑

今天打算自己写一个项目,想自己用用openapi-typescript-codegen生成一下调用后端的api接口,然后掉了两个坑。

问题1:

使用 npm install openapi-typescript-codegen --save-dev 命令安装后,在终端使用 openapi命令后提示没有这个命令

解决:

    方法一:使用 npm install openapi-typescript-codegen -g 全局安装

    方法二:在使用openapi命令前面加上 npx

问题2:

使用 openapi --input http://localhost:8080/api/v2/api-docs --output ./generated --client axios 命令后出现

{ stack: 'JSONParserError: Error downloading http\://localhost:8101/api/v2/api-docs \n' + 'fetch is not defined\n' + ' at download (C:\\\Users\\\28242\\\AppData\\\Roaming\\\npm\\\node\_modules\\\openapi-typescript-codegen\\\node\_modules\\\\@apidevtools\\\json-schema-ref-parser\\\dist\\\lib\\\resolvers\\\http.js:113:15)', code: 'ERESOLVER', name: 'ResolverError', message: 'Error downloading http\://localhost:8101/api/v2/api-docs \n' + 'fetch is not defined', source: 'http\://localhost:8101/api/v2/api-docs', path: null, toJSON: \[Function: toJSON], footprint: 'null+http\://localhost:8101/api/v2/api-docs+ERESOLVER+Error downloading http\://localhost:8101/api/v2/api-docs \n' + 'fetch is not defined', toString: \[Function: toString] }

解决:将openapi-typescript-codegen版本降级到0.25.0后,即可解决

参考:Behavior change for relative input path in 0.26.0 · Issue #1970 · ferdikoomen/openapi-typescript-codegen (github.com)

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
布布
下载 APP