32

I'm trying to generate java code from swagger.json using swagger-codegen-cli.jar but I get this exception:

Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:763)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:299)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

The command I'm trying to run is the following:

java -jar swagger-codegen-cli.jar generate -i swagger.json -l java -c java-config.json -o api-client
Helen
  • 87,344
  • 17
  • 243
  • 314
Amine
  • 901
  • 2
  • 14
  • 33
  • Please check [this](https://stackoverflow.com/questions/47301891/swagger-3-0-0-codegen-failed-java-lang-runtimeexception-missing-swagger-input-o) and show your swagger.json file – Ashish Karn Jun 25 '20 at 13:45
  • Sorry can't share my swagger.json – Amine Jun 25 '20 at 13:46
  • 1
    What version of Swagger Codegen do you use (`java -jar swagger-codegen-cli.jar version`)? Is your swagger.json file `swagger: '2.0'` or `openapi: 3.0.0`? – Helen Jun 25 '20 at 13:46
  • the swagger-codegen-cli.json I cloned from master branch https://github.com/swagger-api/swagger-codegen, I don't know which version the jar corresponds to, as for the swagger.json it's openapi: 3.0.1 – Amine Jun 25 '20 at 13:50
  • 1
    @Helen I think the master branch corresponds to 2.X version of Swagger Codegen, I'm cloning from 3.0.0 branch to try it – Amine Jun 25 '20 at 13:54
  • with git clone from master version reported is 2.4.33-SNAPSHOT (yes, a few years later June 2023) – gaoithe Jun 07 '23 at 11:18

1 Answers1

47

You are using Swagger Codegen 2.x which does not support OpenAPI 3.0.

You need to use Swagger Codegen 3.x instead. You can download the latest 3.x CLI JAR from Maven Central:
https://mvnrepository.com/artifact/io.swagger.codegen.v3/swagger-codegen-cli

Here's a direct link to v. 3.0.20 CLI (the latest version as of the time of writing):
https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.20/swagger-codegen-cli-3.0.20.jar


Or if you prefer to build the codegen from the source code, version 3 is in the 3.0.0 branch:
https://github.com/swagger-api/swagger-codegen/tree/3.0.0

Helen
  • 87,344
  • 17
  • 243
  • 314
  • 1
    but if you are using the swagger codegen, why are you listing the JAR depedency? the official documentation says you need to list it in the pom.xml as a plugin? Is there something I don't understand here? – ennth Mar 31 '21 at 23:00
  • @ennth There are many ways to run Swagger Codegen: as a Maven plugin, as a CLI tool, as a Docker image, etc. This Q&A is about CLI specifically. – Helen May 06 '21 at 23:26
  • `git clone https://github.com/swagger-api/swagger-codegen; cd swagger-codegen; git checkout 3.0.0;` – gaoithe Jun 07 '23 at 11:21