问题1:
提示没有 openapi 命令
解决(两种方案取其一):
1. 使用 npm install openapi-typescript-codegen -g 命令,全局安装
2. 使用 npx openapi --input http://localhost:8080/api/v2/api-docs --output ./generated --client axios
问题2:
执行命令后出现
{
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版本
参考: