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
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.
Open issue here as well, with no timeline for support mentioned 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
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.
cc @HugoMario who's actively working on that branch to provide OAI 3.0 support.
Any update?
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.
Looking forward to it.
@hugoMario Would that be Jan 8th or Aug 1st for the beta release?
@jeroenhuinink it's Jan 8th, sorry for confusion.
Any updates on this?
yes, we're having a delay, but today or tomorrow we'll release the beta.
@HugoMario any news?
What's up folks? Can you give any predictions?
@samvdb @stdmitry we pushed the beta release for new week, due we're waiting for releases on other projects (inflector, parser).
Hey it's been a week, any update?
@doodyparizada I saw that 3.0.0-rc0 has been released
Unfortunately, it just supports java and inflector, making it not that useful...
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.
@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.
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
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!
@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.
Thanks for information. I hope the team will consider the minimal release to make the migration easier.
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
@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
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 :/
@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
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>
Hi All,
Im using the latest version of
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
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: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
servers:
Added by API Auto Mocking Plugin
@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.
@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.
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. :disappointed:
@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
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.
Most helpful comment
@slarti-b There is an alternative (community fork) supporting all languages of
2.4.0-SNAPSHOTwith OpenAPI 3.0 here: https://github.com/openapitools/openapi-generator