118*_*218 7 npm angular openapi-generator
我使用@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}"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这听起来很棒!
问题是我无法使用官方页面中指定的配置文件:
如果 openapi-generator-cli generate 在没有其他参数的情况下被调用,那么配置将自动用于生成您的代码。
当我这样做时:
openapi-generator-cli generate
Run Code Online (Sandbox Code Playgroud)
我一直被一个错误困住:
[错误] 缺少必需的选项“-i”
如果我添加 -i 参数,例如:
openapi-generator-cli generate -i http://localhost:8081/v2/api-docs
Run Code Online (Sandbox Code Playgroud)
然后“openapitools.json”文件被默认配置忽略并覆盖:
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "4.3.1"
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试按照我以前使用的方式进行操作,并添加参数“-spaces=2”:
openapi-generator-cli generate -i http://localhost:8081/v2/api-docs -g typescript-angular -o src/app/tools/openapi -spaces=2
Run Code Online (Sandbox Code Playgroud)
但它再次不起作用,而且我现在有一个无用的文件 (openapitools.json) 烦扰我的强迫症!
有关信息,我的 npm 版本 (npm -v) 是:
6.14.8
我使用的是当前最新的 Angular 版本:
11.0.0
小智 3
我也遇到过和你描述的类似的问题;特别是“被默认配置覆盖”。
我确实认为无效的 opanapitools.json 导致它被完全重置。看来这些评论导致了这些验证错误。
也许删除它们并重试。
希望这有帮助,我用这样的 package.json->scripts 运行它。
虽然“spaces”属性似乎只被使用,但当 cli 编写它自己的配置文件时。
| 归档时间: |
|
| 查看次数: |
2163 次 |
| 最近记录: |