skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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:Usersaniemirkacompass_backend
    

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


  2. I solved this using bash using the following command:

    docker run --rm -v ${PWD}:/local alpine sh -c "apk add --no-cache openjdk11 && wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.3.0/openapi-generator-cli-5.3.0.jar -O /opt/openapi-generator-cli.jar && java -jar /opt/openapi-generator-cli.jar generate -i /local/api.yaml -g go-server -o /local/api/gen"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search