Trouble installing Swagger CodeGen

后端 未结 2 1809
执笔经年
执笔经年 2021-01-03 17:39

I installed Swagger CodeGen using the command

npm install swagger-codegen -g

So I should have it installed, but there is some error/glitch

相关标签:
2条回答
  • 2021-01-03 17:57

    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:

    • Codegen 3.x JARs are here: https://oss.sonatype.org/content/repositories/releases/io/swagger/codegen/v3/swagger-codegen-cli/

    • Codegen 2.x JARs are here: http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/

    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:

    • generate the server and client code from Swagger Editor (it has an integrated codegen).
    • call the online codegen using its REST API. (Example)
    • use the Maven plugin: swagger-codegen-maven-plugin. The group ID is io.swagger for Codegen 2.x and io.swagger.codegen.v3 for Codegen 3.x.
    0 讨论(0)
  • 2021-01-03 17:57

    this module doesn't create an executable file when being installed via npm install swagger-codegen -g, that's why you see the error. Please see https://github.com/swagger-api/swagger-codegen/blob/master/README.md#prerequisites for installation instructions

    0 讨论(0)
提交回复
热议问题