8000 Does any codegen work for open api spec 3 yet? · Issue #6598 · swagger-api/swagger-codegen · GitHub
[go: up one dir, main page]

Skip to content

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

New issue
8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
slarti-b opened this issue Sep 30, 2017 · 35 comments
Closed

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

slarti-b opened this issue Sep 30, 2017 · 35 comments
Milestone

Comments

@slarti-b
Copy link
Contributor

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

@wing328
Copy link
Contributor
wing328 commented Oct 2, 2017

Not yet. Swagger Codegen relies on Swagger Parser to parse the spec and Swagger Parser 2.0.0 RC1 (which supports OAI 3.0 spec) was just released 2 days ago.

cc @HugoMario, who is working adding OAI 3.0 support to Swagger Codegen.

@wing328 wing328 added this to the v2.3.0 milestone Oct 2, 2017
@no-logic
Copy link

Open issue here as well, with no timeline for support mentioned yet. #4669

@MikeRalphson
Copy link
Contributor

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

@PFacheris
Copy link

Did some testing using 3.0.0_enhancements branch (and by extension the 2.0.0-SNAPSHOT of swagger-parser) with a semi-complex openapi 3.0 contract and ran into a small issue with Java codegen that I'll put here in hopes of being helpful:

localVarAccepts doesn't create a valid array when combining response content-types as in the below yaml:

get:
  tags:
    - task
  summary: Get task(s).
  description: ''
  operationId: getTask
  parameters:
    - in: query
      name: id
      required: true
      style: form
      schema:
        type: array
        items:
          $ref: '#/components/schemas/Task/properties/id'
  responses:
    '200':
      description: Information on the task(s).
      content:
        application/json:
          schema:
            type: object
            properties:
              task:
                type: array
                items:
                  $ref: '#/components/schemas/Task'
    '400':
      description: Invalid request.
    '403':
      description: Not allowed.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string

results in

final String[] localVarAccepts = {
    "application/json""application/json"
};

This also occurs when different content-types are used in different response codes. For now, I'm getting around this by only specifying the content-type in the 200 response.

@wing328
Copy link
Contributor
wing328 commented Nov 27, 2017

cc @HugoMario who's actively working on that branch to provide OAI 3.0 support.

@ogres
Copy link
ogres commented Dec 16, 2017

Any update?

@wing328 wing328 modified the milestones: v2.3.0, v3.0.0 Dec 16, 2017
@HugoMario
Copy link
Contributor

sorry for delay response.

Right now we're focus on java (client/server) for oas 3. I'm working on it, btw.

There is an estimate for 08/01/2018 to release this beta.

@liuweireign
Copy link

Looking forward to it.

@jeroenhuinink
Copy link

@HugoMario Would that be Jan 8th or Aug 1st for the beta release?

@HugoMario
Copy link
Contributor

@jeroenhuinink it's Jan 8th, sorry for confusion.

@yasammez
Copy link
yasammez commented Jan 9, 2018

Any updates on this?

@HugoMario
Copy link
Contributor

yes, we're having a delay, but today or tomorrow we'll release the beta.

@samvdb
Copy link
samvdb commented Jan 16, 2018

@HugoMario any news?

@stdmitry
Copy link

What's up folks? Can you give any predictions?

@HugoMario
Copy link
Contributor

@samvdb @stdmitry we pushed the beta release for new week, due we're waiting for releases on other projects (inflector, parser).

@doodyparizada
Copy link

Hey it's been a week, any update?

@eiden
Copy link
eiden commented Jan 26, 2018

@doodyparizada I saw that 3.0.0-rc0 has been released

Unfortunately, it just supports java and inflector, making it not that useful...

@nsFrankly
Copy link

any update on "go" and "nodejs-server" support for open API 3.0 ? ETA ?
we are starting a new project , would love to support open API 3.0.

@webron
Copy link
Contributor
webron commented Jan 31, 2018

@nsFrankly There's no ETA. This depends on community contributions, and are based on availability and capacity of it. You're welcome to submit PRs as well to help push this forward.

8000
@nsFrankly
Copy link
nsFrankly commented Jan 31, 2018

thx @webron , we will use swagger 2.0 , for a possible later auto conversion to open api 3 and code gen. I'll submit a new Issue request for "go" , "nodejs-server". If i have time i'll look into writing the generators

@LeonorAz
Copy link
LeonorAz commented Feb 3, 2018

Would it be possible to release a version, say 3.0.0-mininal, to support OpenApi spec 3.0 without the other major changes (handlebar, remote argument loading, moving templates, etc)?

We are happy to see those major changes but our highest priority is just OpenApi spec 3.0 support with our own mustache templates.

Thanks for great work!

@matteomazza91
Copy link

@LeonorAz
I'm currently using the 3.0.0 branch with some little changes. Until a minimal release is ready, you can give it a try with very little changes to your template.

You need to pull the 3.0.0 branch and merge the PR #7488 . Another simpler way is to pull this but you will miss the latest commits in 3.0.0 branch.
This PR is needed to load your own custom template.

@LeonorAz
Copy link
LeonorAz commented Feb 6, 2018

Thanks for information. I hope the team will consider the minimal release to make the migration easier.

@mike03081972
Copy link

I have tried this version : swagger-codegen-cli-3.0.0-20180221.003354-22.jar
It's working but not published yet to mvnrepository.com

@macjohnny
Copy link
Contributor

@slarti-b There is an alternative (community fork) supporting all languages of 2.4.0-SNAPSHOT with OpenAPI 3.0 here: https://github.com/openapitools/openapi-generator

@chrisinmtown
Copy link

No comments for almost a year, what does this mean for openapi 3.0.0 support in the swagger codgen (and the swagger codegen maven plugin)?

My first attempt with the openapi-generator wasn't promising :/

@HugoMario
Copy link
Contributor

@chrisinmtown , it means that we have an answer and is: yes, there are codegen work for open api spec 3.

check latest release https://github.com/swagger-api/swagger-codegen/releases

@chrisinmtown
Copy link
chrisinmtown commented May 2, 2019

Thanks - version 3.0.8 of the swagger codegen maven plugin is working well for generating Java client code from a openapi: 3.0.0 spec in yaml format. I configured my pom.xml file to use the plugin as follows, you have just have to define maven property client.base.package.name:

                        <plugin>
                                <!-- This 2019 version is required for OpenAPI 3 -->
                                <groupId>io.swagger.codegen.v3</groupId>
                                <artifactId>swagger-codegen-maven-plugin</artifactId>
                                <version>3.0.8</version>
                                <executions>
                                        <execution>
                                                <goals>
                                                        <goal>generate</goal>
                                                </goals>
                                                <configuration>
                                                        <inputSpec>${project.basedir}/swagger.yaml</inputSpec>
                                                        <language>java</language>
                                                        <packageName>${client.base.package.name}</packageName>
                                                        <modelPackage>${client.base.package.name}.model</modelPackage>
                                                        <apiPackage>${client.base.package.name}.api</apiPackage>
                                                        <invokerPackage>${client.base.package.name}.invoker</invokerPackage>
                                                        <configOptions>
                                                                <groupId>${project.groupId}</groupId>
                                                                <artifactId>${project.artifactId}</artifactId>
                                                                <artifactVersion>${project.version}</artifactVersion>
                                                                <library>resttemplate</library>
                                                                <java8>true</java8>
                                                                <dateLibrary>java8</dateLibrary>
                                                                <licenseName>Apache 2.0</licenseName>
                                                                <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
                                                        </configOptions>
                                                </configuration>
                                        </execution>
                                </executions>
                        </plugin>

@I302609
Copy link
I302609 commented Jun 26, 2020

Hi All,

Im using the latest version of

io.swagger.codegen.v3
swagger-codegen-generators
1.0.21-SNAPSHOT

but still when im calling the below

try {
final CodegenConfigurator configurator = new CodegenConfigurator()
.setLang("nodejs-server")
.setInputSpec(opts.getSpec().toPrettyString())
.setOutputDir(outputFolder);
clientOptInput = configurator.toClientOptInput();
} catch(RuntimeException e) {
e.printStackTrace();
}

It fails with
at io.swagger.codegen.v3.CodegenConfigLoader.forName(CodegenConfigLoader.java:31) |
2020 06 26 16:11:07#+00#ERROR#java.lang.Throwable##I302609#https-jsse-nio-8041-exec-8#na#xmjlqwr0ig#apiportaldevpluto#web#ed50aclw58#na#na#na#na# at io.swagger.codegen.v3.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:455) |

Please guide

@gtarcoder
Copy link
gtarcoder commented Aug 3, 2020

Hi, I am using the https://github.com/swagger-api/swagger-codegen/archive/v3.0.21.zip to generate code for openapi 3.0.
but meet with following errors:

`
root@49d0eaa79af2:/mlplat/swagger-codegen-3.0.21# java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ./test.yaml -l go-server -o /mlplat/go-server
[main] INFO io.swagger.parser.Swagger20Parser - reading from ./test.yaml
[main] INFO io.swagger.parser.Swagger20Parser - reading from ./test.yaml
[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (String)"openapi: 3.0.0
info:
description: |
This is a sample Petstore server. You can find
out more about Swagger at
http://swagger.io or on
irc.freenode.net, #swagger.
version: "1.0.0"
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
servers:
Added by API Auto Mocking Plugin

  • des"[truncated 17129 chars]; line: 1, column: 8]
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:722)
    at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2868)
    at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1914)
    at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:773)
    at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)
    at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2711)
    at io.swagger.parser.SwaggerCompatConverter.readResourceListing(SwaggerCompatConverter.java:210)
    at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:123)
    at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:83)
    at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:437)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:297)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
    [main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
    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)
    `
    would like to know if the swagger-codegen supports openapi-3.0 now ?

@hkosova
Copy link
hkosova commented Aug 3, 2020

@gtarcoder
Copy link

@gtarcoder download the compiled CLI JAR from
https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.21/swagger-codegen-cli-3.0.21.jar
and try again.

That works, thanks for sharing.

@neclimdul
Copy link

This probably needs a separate issue but for posterity...

I saw this close a while back and was excited to start using it. I was however frustrated to find after spending a good bit of work on converting a spec that it may be "working" but there are no containers for the 3.x branch. This means it might "work" but if you're using those containers in your CI process it is still not available You'll have to use the jars with some java container and download it every time or the openapitools fork which generates slightly different code. 😞

@hkosova
Copy link
hkosova commented Aug 4, 2020

@neclimdul if you mean Docker images for Codegen 3.x, see here:
https://github.com/swagger-api/swagger-codegen/tree/3.0.0#public-pre-built-docker-images

@vipul666
Copy link

Thanks - version 3.0.8 of the swagger codegen maven plugin is working well for generating Java client code from a openapi: 3.0.0 spec in yaml format. I configured my pom.xml file to use the plugin as follows, you have just have to define maven property client.base.package.name:

                        <plugin>
                                <!-- This 2019 version is required for OpenAPI 3 -->
                                <groupId>io.swagger.codegen.v3</groupId>
                                <artifactId>swagger-codegen-maven-plugin</artifactId>
                                <version>3.0.8</version>
                                <executions>
                                        <execution>
                                                <goals>
                                                        <goal>generate</goal>
                                                </goals>
                                                <configuration>
                                                        <inputSpec>${project.basedir}/swagger.yaml</inputSpec>
                                                        <language>java</language>
                                                        <packageName>${client.base.package.name}</packageName>
                                                        <modelPackage>${client.base.package.name}.model</modelPackage>
                                                        <apiPackage>${client.base.package.name}.api</apiPackage>
                                                        <invokerPackage>${client.base.package.name}.invoker</invokerPackage>
                                                        <configOptions>
                                                                <groupId>${project.groupId}</groupId>
                                                                <artifactId>${project.artifactId}</artifactId>
                                                                <artifactVersion>${project.version}</artifactVersion>
                                                                <library>resttemplate</library>
                                                                <java8>true</java8>
                                                                <dateLibrary>java8</dateLibrary>
                                                                <licenseName>Apache 2.0</licenseName>
                                                                <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
                                                        </configOptions>
                                                </configuration>
                                        </execution>
                                </executions>
                        </plugin>

how to make the api path dynamic though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0