Search code examples
jakarta-eeintellij-ideaswagger-codegen

Trouble installing Swagger CodeGen


I installed Swagger CodeGen using the command

npm install swagger-codegen -g

So I should have it installed, but there is some error/glitch going on. Everytime I enter

swagger-codegen -v

I get the following message

'swagger-codegen' is not recognized as an internal or external command, operable program or batch file.

I have no idea what to do. How should I fix this? I am trying to follow a tutorial, but the instructor nevers shows how he installs programs.

Under GitHub, the instructions don't make sense

Prerequisites If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 7 runtime at a minimum):

wget http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar -O swagger-codegen-cli.jar

java -jar swagger-codegen-cli.jar help

For Windows users, you will need to install wget or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.

Invoke-WebRequest -OutFile swagger-codegen-cli.jar http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar

Am I supposed to put those in the command line? tried that, didn't work


Solution

  • Swagger Codegen is a Java app, so you must have Java installed.

    There are two versions of Swagger Codegen - 2.x and 3.x. Use 3.x for openapi: 3.0.0 definitions and 2.x for swagger: '2.0'.

    Installing Swagger Codegen CLI (Command-Line Version)

    Windows

    Download the compiled JAR file:

    Look for the file named swagger-codegen-cli-<version>.jar, e.g. if you need v. 2.3.1:
    http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar

    Swagger Codegen JAR file


    To run the codegen, use:

    java -jar c:\path\to\swagger-codegen-cli-<version>.jar <args>
    

    (You can rename swagger-codegen-cli-<version>.jar to swagger-codegen-cli.jar for simplicity.)

    Mac

    Install using Homebrew:

    # Codegen 3.x
    brew install swagger-codegen
    
    # Codegen 2.x
    brew install swagger-codegen@2
    

    Then you can run the codegen as:

    swagger-codegen <args>
    swagger-codegen@2 <args>
    

    If you don't have Homebrew, download the JAR file from Maven and run it as explained above for Windows.

    Alternatives to CLI Version

    You can also: