【发布时间】:2020-12-08 10:14:34
【问题描述】:
我使用@openapitools/openapi-generator-cli(v2.1.7) 在客户端生成API库。
它工作得很好,除了我无法按照我的意愿格式化生成的代码。
我刚刚注意到有一个新选项允许配置示例中提到的空格 ("spaces": 2):
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "4.3.1",
"storageDir": "~/my/custom/storage/dir", // optional
"generators": { // optional
"v2.0": { // any name you like (just printed to the console log)
"generatorName": "typescript-angular",
"output": "#{cwd}/output/v2.0/#{ext}/#{name}",
"glob": "examples/v2.0/{json,yaml}/*.{json,yaml}",
"additionalProperties": {
"ngVersion": "6.1.7",
"npmName": "restClient",
"supportsES6": "true",
"npmVersion": "6.9.0",
"withInterfaces": true
}
},
"v3.0": { // any name you like (just printed to the console log)
"generatorName": "typescript-fetch",
"output": "#{cwd}/output/v3.0/#{ext}/#{name}",
"glob": "examples/v3.0/petstore.{json,yaml}"
}
}
}
}
这听起来很棒!
问题是我无法使用official page中指定的配置文件:
如果在没有进一步参数的情况下调用 openapi-generator-cli generate,则配置会自动用于生成您的代码。
当我这样做时:
openapi-generator-cli generate
我一直遇到错误:
[错误] 缺少必需选项“-i”
如果我加上-i参数,例如:
openapi-generator-cli generate -i http://localhost:8081/v2/api-docs
然后“openapitools.json”文件被默认配置忽略并覆盖:
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "4.3.1"
}
}
我也尝试按照我以前的方式进行操作,并添加参数“-spaces=2”:
openapi-generator-cli generate -i http://localhost:8081/v2/api-docs -g typescript-angular -o src/app/tools/openapi -spaces=2
但还是不行,而且我现在有一个无用的文件 (openapitools.json) 烦人我的强迫症!
关于信息,我的 npm 版本 (npm -v) 是:
6.14.8
我正在使用当前最新的 Angular 版本:
11.0.0
【问题讨论】:
-
我认为 -i 选项在您的
v2.0 | v3.0内,位于密钥"input-spec":"http://localhost:port/whatever"下
标签: angular npm openapi-generator