Search code examples
dockeropenapi-generatoropenapi-generator-cli

Docker openapi client generator can't find "spec file"


I have generated a openapi json file, and I wish to create a typescript client using docker. I have tried to do something similar to what is on the openapi generator site (https://openapi-generator.tech/ - scroll down to docker part), but it doesn't work.

Command from site:

docker run --rm \
    -v $PWD:/local openapitools/openapi-generator-cli generate \
    -i /local/petstore.yaml \
    -g go \
    -o /local/out/go

What I have tried:

docker run --rm -v  \
    $PWD:/local openapitools/openapi-generator-cli generate -i ./openapi.json \ 
    -g typescript-axios 

No matter what I do, there is always a problem with the ./openapi.json file. The error which occours:

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

I have tried the things below:

-i ~/compass_backend/openapi.json
-i openapi.json
-i ./openapi.json
-i $PWD:/openapi.json
cat openapi.json | docker run .... (error, -i is required)

I am out of ideas. The error is always the same. What am I doing wrong?


Solution

  • I was able to solve the problem by switching from bash to powershell. Docker uses windows path notation and I was trying to use bash notation. If you type pwd in bash you get this:

    /c/Users/aniemirka/compass_backend
    

    And if you type pwd in powershell you get this:

    C:\Users\aniemirka\compass_backend
    

    So docker was trying to mount a volume to /c/Users/aniemirka/compass_backend\local, and it couldn't read it because it is not windows notation, so the volume didn't exist.