2

I am trying to configure swagger on my pc, so as to work with it. I am facing an issue with swagger-codegen is not recognized. This is the command I want to execute on command line:

swagger-codegen generate -i <path to your swagger file> -l html2 -o <path to output location> -t <templates path>

This is the source when I am based: Generate static docs with swagger

Please help me!

Abaya
  • 47
  • 1
  • 8

2 Answers2

1

On Windows, assuming that you downloaded the standalone swagger-codegen-cli-2.2.2.jar from here:
http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.2/swagger-codegen-cli-2.2.2.jar

you can run it as follows:

java -jar C:\path\to\swagger-codegen-cli-2.2.2.jar generate -i http://petstore.swagger.io/v2/swagger.json -l html2 -o C:\petstore\html2

Your original example is missing java -jar. Codegen is run via the Java launcher because it's a JAR file and not an standaline .exe file.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • for path I need to add jar file path or swagger path? – Abaya Jun 26 '17 at 10:11
  • It depends. If you use absolute paths, there's no need to change the `PATH`. If you want to use just the file names e.g. `-i petstore.json` or `java -jar swagger-codegen-cli-2.2.2.jar`, add the folders containing these files. – Helen Jun 26 '17 at 10:44
  • I already face the problem swagger is not recognized as an internal or external command – Abaya Jun 26 '17 at 13:49
0

Download Swagger Codegen from this linkhow to download For convert swagger to html: Write bottom code in cmd for get swagger.json file info from url and generate html code in intarface folder path:

java -jar {your downloaded above file, folder path}\swagger-codegen-cli-3.0.36.jar generate -i {your swagger web url}/swagger.json -l html2 -o {your output folder}

In my case is:

java -jar D:\Projects\swagger-codegen-master\swagger-codegen-cli-3.0.36.jar generate -i http://localhost:22293/swagger/v1/swagger.json -l html2 -o D:\Projects\swagger-codegen-master\interfaces

For convert swagger to angular classes: Write bottom code in cmd for get swagger.json file info from url and generate angular code in intarface folder path:

java -jar {your downloaded above file, folder path}\swagger-codegen-cli-3.0.36.jar generate -i {your swagger web url}/swagger.json -l typescript-angular -o {your output folder}

In my case is:

java -jar D:\Projects\swagger-codegen-master\swagger-codegen-cli-3.0.36.jar generate -i http://localhost:22293/swagger/v1/swagger.json -l typescript-angular -o D:\Projects\swagger-codegen-master\interfaces

Here you are. Your APIs is ready to use in angular: converted Angular apis and models in VS code

Ali Rasouli
  • 1,705
  • 18
  • 25