Node.js-based codegen for OpenAPI documents. This project was initially a 24-hour hackathon. The local model adaptor code is entirely original and has been reverse-engineered from the existing documentation and template usage.
Work in progress
Supports OpenAPI 3.0.x natively, and Swagger/OpenAPI 1.2 and 2.0 by internal conversion. Node.js LTS versions are supported.
npm i -g openapi-codegen
or
npm i
or
npx -p openapi-codegen cg ...
cg [options] {[path]configName} {openapi-definition}
Options:
--help Show help [boolean]
--version Show version number [boolean]
--filter Filter term to use with --list [string]
--list List available templates for provider (og or sc) [string]
-d, --debug Turn on debugging information in the model [boolean]
-f, --flat Do not include config-name in output directory structure
[boolean]
-l, --lint Lint input definition [boolean]
-o, --output Specify output directory [string] [default: "./out/"]
-s, --stools Use swagger-tools to validate OpenAPI 2.0 definitions
[boolean]
-t, --templates Specify templates directory [string]
-v, --verbose Increase verbosity [boolean]
-z, --zip Create a .zip file instead of individual files [boolean]
e.g.
node cg --verbose nodejs defs/generator.yaml
In this case, the generated code will be written to the .out/nodejs
directory.
You can also load the OpenAPI definition from a URL.
const renderer = require('openapi-codegen');
// load a config and a definition
renderer.main(definition,config,configName);
The local templates were taken directly from swagger-codegen
. This project is also licensed under Apache-2.0 for this reason. Generated code is explicitly covered by the Unlicense. Code to downconvert OpenAPI 3.0 definitions is taken from Angular-Swagger-UI and is MIT licensed.
You can also use the latest online templates from two providers: og
(openapi-generator) and sc
(swagger-codegen). The --list
and --filter
options allow you to see which templates are available. Note that using the online templates involves sending your API definition to a remote server.
See here for a partial list of template contributors.
The local templates with a status have a working (if not necessarily tested) configuration in the configs directory. Contributions are welcomed from the community of new and updated configurations and template updates.
Template | Type | Status | README | Authors (TODO) | Config Maintainer |
---|---|---|---|---|---|
_common | meta | contains Apache-2.0 and Unlicense licenses | |||
Ada | client | Untested | |||
akka-scala | |||||
android | |||||
apache2 | configuration | needs work | |||
apex | |||||
aspnetcore | |||||
bash | client | Syntax ok, needs testing | @bkryza | @MikeRalphson | |
clojure | client | Untested | |||
codegen | meta | Demo only | @MikeRalphson | ||
confluenceWikiDocs | documentation | Tested with Docker server | |||
cpprest | |||||
csharp | |||||
csharp-dotnet2 | client | Untested | |||
dart | |||||
debug | meta | used for dumping the model state | @Mermade | @MikeRalphson | |
Eiffel | |||||
elixir | |||||
erlang-client | client | Untested | |||
erlang-server | server | ||||
finch | |||||
flash | |||||
flaskConnexion | server | Needs testing | |||
go | client | Builds, needs testing | |||
go-server | server | Builds and runs | |||
Groovy | ? | untested | |||
haskell-http-client | client | ||||
haskell-servant | server | Untested | |||
htmlDocs | documentation | Appears to work | |||
htmlDocs2 | documentation | Appears to work, no console errors logged | |||
Java | |||||
JavaInflector | |||||
JavaJaxRS | |||||
JavaPlayFramework | |||||
Javascript | client | Untested | |||
Javascript-Closure-Angular | client | Untested | |||
JavaSpring | |||||
JavaVertXServer | |||||
JMeter | meta | Untested | |||
kotlin-client | |||||
lua | client | Compiles OK | |||
lumen | |||||
MSF4J | |||||
nancyfx | |||||
nodejs | server | tested
|
@jfiala | @MikeRalphson | |
objc | |||||
openapi | meta | outputs the input definition (in OpenAPI 3.0.x form)
|
@Mermade | @MikeRalphson | |
perl | |||||
php | |||||
php-silex | ? | untested | |||
php-symfony | |||||
pistache-server | |||||
powershell | |||||
python | client | needs testing | @mpnordland | ||
qt5cpp | |||||
r | |||||
rails5 | |||||
restbed | server | Untested | |||
ruby | |||||
rust | |||||
rust-server | |||||
scala | |||||
scalatra | |||||
scalaz | client | Untested | |||
sinatra | server | Syntax checks OK | |||
slim | server | Untested | |||
swagger | meta | outputs the input definition (in original form if OpenAPI 2.0)
|
|||
swagger-static | documentation | tested template modified to include partials | |||
swift | |||||
swift3 | |||||
swift4 | |||||
tizen | |||||
typescript-angular | |||||
typescript-angularjs | |||||
typescript-axios | client | tested | jaredpalmer | ||
typescript-aurelia | |||||
typescript-fetch | client | compiles with tsc ok | |||
typescript-jquery | |||||
typescript-node | client | compiles with tsc ok | |||
undertow | |||||
validator | meta | uses swagger2openapi's OpenAPI 3.0 validator internally
|
|||
ze-ph |
These templates are examples of how features of OpenAPI Codegen may be used, and best-practices in naming model properties.
Template | Type | Status | README | Authors | Config Maintainer |
---|---|---|---|---|---|
testing.dredd | testing | In progress | README | @Mermade | @MikeRalphson |
我正在使用swagger-codegen为我的一个REST API生成Java REST客户端。 REST API使用可选的标头参数。客户端中生成的方法具有一个附加参数,该参数采用标头。我希望生成的方法在方法签名中没有header参数。 我已经阅读了文档,但是找不到任何参考。 例如,对于具有选项X-CUSTOM-HEADER参数的GET all API,swagger-codegen生成如下方法:
背景介绍 18年开始自己尝试改造swagger codegen maven 插件用于自身的工程管理,经过简单改造后的插件能能够胜任日常的代码开发,期间两次换公司很幸运被两家单位认可了这种模式,期间也做了几次增强以及附带改动了一些插件为了满足一键生成接口文档,且用过的都还觉得不错被几家合作单位拿出使用,感觉还是挺高兴的自己的代码得到了大多数人认可。近一年参与了一个很不错的工程,在里面体现了作用,翻来
前言:好久没写博客了,年底到前段日子很忙,加班比较多,加上本人不喜欢CV大法,这段时间一直没写博客,正好最近基于公司新项目学习swagger,故写下这篇文章供自己总结复习,供新人参考^_^。 swagger的作用 swagger是一个用于后台接口生成描述文档或者根据yaml文件生成后台接口的工具集,包括swagger UI进行功能测试、swagger Codegen进行代码生成等组件,这里介绍一下
Swagger Codegen是一个开源的代码生成器,根据Swagger定义的RESTful API可以自动建立服务端和客户端的连接。Swagger Codegen的源码可以在Github上找到。 GitHub: https://github.com/swagger-api/swagger-codegen 本文采用的是2.3.1版本,具体jar包可以在GitHub上下载。下边开始使用介绍 将swa
OpenApi Codegen的最新版本(及其Maven插件)/应该能够使用Webflux / Reative返回对象(例如Mono或Flux对象)自动生成Spring Maven的接口。 但是,我认为它无法正常工作。 这些是我pom.xml的摘录: io.swagger swagger-codegen-maven-plugin ${swagger.codegen.version} authent
<dependency> <groupId>io.swagger.codegen.v3</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>3.0.27</version> </dependency> /**
OpenAI Gym is a toolkit for developing and comparing reinforcement learning algorithms. It makes no assumptions about the structure of your agent, and is compatible with any numerical computation libr
可以通过 OpenAPI Generator,在给定 OpenAPI 规范(v2, v3)的情况下自动生成 API 客户端库、server stubs、文档以及配置。 目前支持以下语言/框架: Languages/Frameworks API clients ActionScript, Ada, Apex, Bash, C# (.net 2.0, 3.5 or later), C++ (cppre
Build, Validate, Route, Authenticate, and Mock using OpenAPI definitions. OpenAPI Backend is a Framework-agnostic middleware tool for building beautiful APIs with OpenAPI Specification. Features Build
Directory of API definitions in OpenAPI(fka Swagger) 2.0 and 3.x formats. API access to collection: Go! - We also have an RSS Feed Our goal is to create the most comprehensive, standards-compliant and
OpenAPI Specification 的目标是为 REST API 定义一个标准的、与语言无关的接口,允许人和计算机在不访问源代码、文档或通过网络的情况下发现和理解服务的功能。 通过 OpenAPI 的正确定义,消费者可以用最简答的方式理解远程服务并与其交互,消除了调用服务时的猜测。 OpenAPI不需要重写现有的API。它不需要将任何软件绑定到服务,所描述的服务甚至可能不是您的。然而,它要