Swagger-codegen: Can't generate v3 spec by 3.0.0 cli

Created on 19 Sep 2017  路  24Comments  路  Source: swagger-api/swagger-codegen

Description

I got an email which says 3.0.0 spec is officially released. So i came to here and downloaded this 3.0.0 cli jar and use it to generate code. It works for v2 spec YAML. But generate v3 spec YAML with this error log:

[main] INFO io.swagger.parser.Swagger20Parser - reading from config/test.yml
[main] INFO io.swagger.parser.Swagger20Parser - reading from config/test.yml
[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null')
 at [Source: config/test.yml; line: 1, column: 9]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidToken(UTF8StreamJsonParser.java:3528)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2686)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:878)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:772)
        at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3850)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3799)
        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2447)
        at io.swagger.parser.SwaggerCompatConverter.readResourceListing(SwaggerCompatConverter.java:189)
        at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:116)
        at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:75)
        at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:431)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:283)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:715)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

Seems it can't parse v3 spec T_T

Swagger-codegen version

This jar from your snapshot list.

Swagger declaration file content or url

The v3 spec is from your guide page:

openapi: 3.0.0
info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: 0.1.9

servers:
  - url: http://api.example.com/v1
    description: Optional server description, e.g. Main (production) server
  - url: http://staging-api.example.com
    description: Optional server description, e.g. Internal staging server for testing

paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in CommonMark or HTML.
      responses:
        '200':    # status code
          description: A JSON array of user names
          content:
            'application/json':
              schema: 
                type: array
                items: 
                  type: string
Command line used for generation
java -jar swagger/swagger-codegen-cli-3.0.0-20170904.171256-3.jar generate \
-i config/test.yml \
-o dist/ \
-l javascript
Steps to reproduce

Download that jar and generate that demo spec.

Should i add some special arguments to active v3 support? Thanks.

Most helpful comment

damn, I've just spent a day massaging my swagger spec to fit v3 schema and now it's pointless :/

I wish the default docs were in sync with the currently released version. It's quite confusing to advertise openapi v3 on the homepage, and also link to swagger codegen which only supports v2.

All 24 comments

Same issue, very annoying. Either don't push the 3.0 spec on people by only providing the documentation for that version, or make sure your other tools work as well :-(

Well, they released the 3.0 spec to indicate that they are not going to change it and the devs of the tools can expect that the spec is solid and stable now.

That's fair, but releasing a spec is not the same as actively hiding the older version of the spec. If tooling is not ready for 3.0, I'd like to be able to easily get to the 2.0 docs. I do realise though, that that is not an issue for the swagger-codegen github.

damn, I've just spent a day massaging my swagger spec to fit v3 schema and now it's pointless :/

I wish the default docs were in sync with the currently released version. It's quite confusing to advertise openapi v3 on the homepage, and also link to swagger codegen which only supports v2.

The 3.0 Snapshots seem to not even work with it yet :'(

java -jar swagger-codegen-cli-3.0.0-20171009.075709-6.jar generate -i blx-api.json -l nodejs-server -o /tmp/test --ignore-file-override /tmp/test
[main] INFO io.swagger.parser.Swagger20Parser - reading from blx-api.json
[main] INFO io.swagger.parser.Swagger20Parser - reading from blx-api.json
[main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No test file found.
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:687)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

Built my jar from the 3.0.0 branch today. It's still failing to read the "openapi" spec. Fails for json input and yaml input (stacktraces like here in the thread before). But the editor works with 3.0.0. I am sad. Is there any hint for a date when we plan to release a codegen-cli for OAS 3?
Can I help somehow?

I watch this thread for details about either release news, or when the snapshot will begin to show signs of supporting openapi 3.0, but no news yet ---> https://github.com/swagger-api/swagger-codegen/issues/4669

Please see #7003 for an experimental implementation of the generator engine in Node.js which supports OpenAPI 3.0

Just pulled https://hub.docker.com/r/swaggerapi/swagger-codegen-cli/tags/ latest version and still getting the same error, any updates on this since Nov?
Thanks

Same here. What is the point of releasing specification that is dead on arrival?

hey @travis-sobeck , @StanislawSwierc , @poppinlp
You can try with cli on 3.0.0 branch.

It somewhat works in a sense that is parses the specification!

More than parsing I care about code generation and it doesn't seem to be at the right level. As you can tell from the second stack trace I've run it on Windows.

typescript-angular

Caused by: java.io.FileNotFoundException: /v2\typescript-angular/v2/typescript-angular/model.mustache
        at com.github.jknack.handlebars.io.URLTemplateLoader.sourceAt(URLTemplateLoader.java:70)
        at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:357)
        at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:343)
        at io.swagger.codegen.DefaultGenerator.getHandlebars(DefaultGenerator.java:1026)
        at io.swagger.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:744)
        at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:396)
        ... 3 more

Java

Exception in thread "Thread-1" java.lang.RuntimeException: Could not generate model 'Choice'        
        at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:409)            
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:728)                  
        at io.swagger.codegen.cmd.Generate.run(Generate.java:331)                                   
        at java.lang.Thread.run(Unknown Source)                                                     
Caused by: java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 3 
v2\Java                                                                                             
   ^                                                                                                
        at java.util.regex.Pattern.error(Unknown Source)                                            
        at java.util.regex.Pattern.escape(Unknown Source)                                           
        at java.util.regex.Pattern.atom(Unknown Source)                                             
        at java.util.regex.Pattern.sequence(Unknown Source)                                         
        at java.util.regex.Pattern.expr(Unknown Source)                                             
        at java.util.regex.Pattern.compile(Unknown Source)                                          
        at java.util.regex.Pattern.<init>(Unknown Source)                                           
        at java.util.regex.Pattern.compile(Unknown Source)                                          
        at java.lang.String.replaceFirst(Unknown Source)                                            
        at io.swagger.codegen.DefaultGenerator.getHandlebars(DefaultGenerator.java:1014)            
        at io.swagger.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:744)     
        at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:396)            

We know about this issue, i hope it could be fixed next week.

@HugoMario Since I'm a windows admin with a windows machine ... I rely on docker. Looks like the the container hasn't been updated in awhile https://hub.docker.com/r/swaggerapi/swagger-codegen-cli/ so I forked master today and tried to build a container based off the Dockerfile in master. It threw the following error
[ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] Child module /opt/swagger-codegen/modules/swagger-generator of /opt/swagger-codegen/pom.xml does not exist @ @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project io.swagger:swagger-codegen-project:2.4.0-SNAPSHOT (/opt/swagger-codegen/pom.xml) has 1 error [ERROR] Child module /opt/swagger-codegen/modules/swagger-generator of /opt/swagger-codegen/pom.xml does not exist
Oh, the docker file is missing
COPY ./modules/swagger-generator ${GEN_DIR}/modules/swagger-generator

@HugoMario I added that COPY line into the Dockerfile, ran build and that didn't really go well.

hey @StanislawSwierc, sorry for late response. the path error has been already fixed, can you please check and let me know if it's still present.

@travis-sobeck , can you please file that error in a new issue?

I'm going to close this issue since we can generate now v3 spec using 3.0.0 cli.

Same issue with swagger-codegen-cli-3.0.0-rc1.jar

Same problem with swaggerapi/swagger-codegen-cli:unstable:
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null') at [Source: (String)"openapi: 3.0.0

Same problem
Using docker image to generate

version: "2"
services:
  gen-swagger:
    volumes:
    - ./docs:/docs
    image: swaggerapi/swagger-codegen-cli
    command: generate -i /docs/admin-openapi.yaml -l swagger -o /docs

Error:

gen-swagger_1  | [main] INFO io.swagger.parser.Swagger20Parser - reading from /docs/admin-openapi.yaml
gen-swagger_1  | [main] INFO io.swagger.parser.Swagger20Parser - reading from /docs/admin-openapi.yaml
gen-swagger_1  | [main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
gen-swagger_1  | com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null')
gen-swagger_1  |  at [Source: (String)"openapi: 3.0.3
gen-swagger_1  | # Added by API Auto Mocking Plugin
gen-swagger_1  | servers:
gen-swagger_1  | # Added by API Auto Mocking Plugin

I just git cloned the repo and changed to branch 3.0.0. I got the exact same error:

$ java -jar ${SWAGGER_DIR}/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate --lang=restbed --output=. --input-spec=FILE.yaml
[main] INFO io.swagger.parser.Swagger20Parser - reading from FILE.yaml
[main] INFO io.swagger.parser.Swagger20Parser - reading from FILE.yaml
[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null')
 at [Source: (String)"openapi: 3.0.0

Make sure you rebuild the jar by running mvn clean package after you checkout 3.0.0

Was this page helpful?
0 / 5 - 0 ratings