无法安装Swagger CodeGen [英] Trouble installing Swagger CodeGen
问题描述
我使用命令安装了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
我收到以下消息
'swagger-codegen'无法识别为内部或外部命令, 可操作的程序或批处理文件.
'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.
在GitHub下,说明没有意义
Under GitHub, the instructions don't make sense
先决条件 如果您正在寻找最新的稳定版本,则可以直接从Maven.org(至少Java 7运行时)中获取它:
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
对于Windows用户,您将需要安装wget或可以在PowerShell(3.0+)中使用Invoke-WebRequest,例如
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
推荐答案
Swagger Codegen是Java应用程序,因此您必须安装Java.
Swagger Codegen is a Java app, so you must have Java installed.
Swagger Codegen有两个版本-2.x和3.x.对于openapi: 3.0.0
定义使用3.x,对于swagger: '2.0'
使用2.x.
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'
.
下载已编译的JAR文件:
Download the compiled JAR file:
-
Codegen 3.x JAR位于此处: https://oss.sonatype.org/content/repositories/releases/io/swagger/codegen/v3/swagger-codegen-cli/
Codegen 2.x JAR位于此处: http: //central.maven.org/maven2/io/swagger/swagger-codegen-cli/
Codegen 2.x JARs are here: http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/
查找名为swagger-codegen-cli-<version>.jar
的文件,例如如果需要2.3.1节:
http ://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar
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
要运行代码生成,请使用:
To run the codegen, use:
java -jar c:\path\to\swagger-codegen-cli-<version>.jar <args>
(为简单起见,您可以将swagger-codegen-cli-<version>.jar
重命名为swagger-codegen-cli.jar
.)
(You can rename swagger-codegen-cli-<version>.jar
to swagger-codegen-cli.jar
for simplicity.)
使用自制软件安装:
# 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>
如果您没有Homebrew,请从Maven下载JAR文件并按照上面针对Windows的说明运行该文件.
If you don't have Homebrew, download the JAR file from Maven and run it as explained above for Windows.
您还可以:
- 从 Swagger编辑器(具有集成的代码生成器)生成服务器和客户端代码.
- 使用其 REST API 调用在线代码生成器. (示例)
- 使用Maven插件:
swagger-codegen-maven-plugin
.对于Codegen 2.x,组ID为io.swagger
,对于Codegen 3.x,组ID为io.swagger.codegen.v3
.
- 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 isio.swagger
for Codegen 2.x andio.swagger.codegen.v3
for Codegen 3.x.
这篇关于无法安装Swagger CodeGen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!