openapi-generatoropenapi-generator-clidevcontainer

Using openapi-generator-cli inside a devcontainer


I am trying to run openapi-generator-cli from a devcontainer. Here are the files I used :

// .devcontainer/devcontainer.json
{
  "name": "OpenAPI DevContainer",
  "dockerFile": "Dockerfile",
  "mounts": [
     "source=${localWorkspaceFolder}/openapi_specs,target=/workspaces/openapi_specs,type=bind,consistency=cached",
     "source=${localWorkspaceFolder}/my_client_library,target=/workspace/my_client_library,type=bind,consistency=cached"
   ]
}

and

# .devcontainer/Dockerfile
# Use the official openapi-generator-cli Docker image as the base image
FROM openapitools/openapi-generator-cli:latest

# Set the PATH environment variable to include openapi-generator-cli
ENV PATH="/usr/local/bin:${PATH}"

However when the container is built, the following command

openapi-generator-cli --version

returns a "command not found" in the terminal. And a quick search in /usr/bin and /usr/local/bin confirms that it's not in there. So where is it? What am I missing ?

Thanks in advance

Edit :

So I've found a directory openapi-generator-cli inside /opt/openapi-generator/modules, which I then tried to add to PATH, but with no success


Solution

  • Try this in your docker file:

    # Install OpenJDK and other dependencies for openapi-generator-cli
    RUN apt-get update && apt-get install -y openjdk-11-jdk maven
    
    # Download and install the openapi-generator-cli
    RUN curl -fsSL https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh -o /usr/local/bin/openapi-generator-cli \
        && chmod +x /usr/local/bin/openapi-generator-cli
    
    # Set environment variable for the openapi-generator-cli version
    ENV OPENAPI_GENERATOR_VERSION 5.3.0