Skip to content

Does any codegen work for open api spec 3 yet? #6598

@slarti-b

Description

@slarti-b

I know it's not released, but I got the impression much of the functionality was there for the version 3 spec. Particularly interested in the server stub generation.

I tried both the 3.0.0 branch (checkout and mvn clean package) and the snapshot from 24 Sept from https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/3.0.0-SNAPSHOT/

I tried with a sample.yml which is a direct copy of the basic example from https://swagger.io/docs/specification/basic-structure/

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

It fails on the first line with Unrecognized token 'openapi': was expecting ('true', 'false' or 'null')

Full output (with -v)

[adamc@adamc-centos push]$ java -jar ./swagger-codegen-cli-3.0.0-20170924.102354-5.jar generate   -i sample.yml   -l aspnetcore   -o samples3/server/aspnetcore -v
[main] INFO io.swagger.codegen.config.CodegenConfigurator -
VERBOSE MODE: ON. Additional debug options are injected
 - [debugSwagger] prints the swagger specification as interpreted by the codegen
 - [debugModels] prints models passed to the template engine
 - [debugOperations] prints operations passed to the template engine
 - [debugSupportingFiles] prints additional data passed to the template engine
[main] INFO io.swagger.parser.Swagger20Parser - reading from sample.yml
[main] INFO io.swagger.parser.Swagger20Parser - reading from sample.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: sample.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)
[main] WARN io.swagger.codegen.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.swager-codegen-ignore) will be evaluated.
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)

Am I doing something wrong? Do I need to call it differently for version 3 (help generate seems the same, although I'm new to swagger and don't know what all the options do). I not ice it's using io.swagger.parser.Swagger20Parser, which I guess is the 2.0 parser. Or is this not implemented yet for 3.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions