You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker环境下使用openapi-generator生成API客户端遇文件未找到错误

解决Docker中OpenAPI Generator找不到Spec文件的问题

问题重现

执行以下Docker命令生成TypeScript-Angular客户端时:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i ./petstore.yml -g typescript-angular -o api/petstore

出现错误:

[error] The spec file is not found: ./petstore.yml
[error] Check the path of the OpenAPI spec and try again.

修改挂载参数或相对路径后问题仍未解决。

核心原因

你将本地当前目录挂载到了容器的/local目录,但命令中指定的-i路径是相对于容器默认工作目录(而非挂载的/local目录)的,导致容器无法定位到目标文件。

解决方案

使用容器内的挂载路径/local/petstore.yml作为Spec文件路径,同时输出目录也需指定容器内的/local/api/petstore(会自动同步到本地当前目录的api/petstore)。

正确命令

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/petstore.yml -g typescript-angular -o /local/api/petstore

额外检查项

  • 确认本地当前目录下确实存在petstore.yml,可执行ls ${PWD}验证。
  • Windows环境下,将${PWD}替换为%cd%:
    docker run --rm -v "%cd%:/local" openapitools/openapi-generator-cli generate -i /local/petstore.yml -g typescript-angular -o /local/api/petstore
    
  • 若仍有问题,检查文件权限,确保容器进程能读取该文件(可临时赋予可读权限:chmod +r petstore.yml)。

内容的提问来源于stack exchange,提问作者Yura Demkiv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 11:03:20