UNPKG

6.62 kBMarkdownView Raw
1# OpenAPI-CodeGen
2
3[![Build status](https://travis-ci.org/Mermade/openapi-codegen.svg?branch=master)](https://travis-ci.org/Mermade/openapi-codegen)
4[![Greenkeeper badge](https://badges.greenkeeper.io/Mermade/openapi-codegen.svg)](https://greenkeeper.io/)
5
6Node.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.
7
8**Work in progress**
9
10Supports OpenAPI 3.0.x natively, and Swagger/OpenAPI 1.2 and 2.0 by internal conversion. Node.js LTS versions are supported.
11
12## Usage
13
14### Installing
15
16`npm i -g openapi-codegen`
17
18or
19
20* clone the repository, and
21* `npm i`
22
23or
24
25`npx -p openapi-codegen cg ...`
26
27### CLI
28
29```
30cg [options] {[path]configName} {openapi-definition}
31
32Options:
33 --help Show help [boolean]
34 --version Show version number [boolean]
35 --filter Filter term to use with --list [string]
36 --list List available templates for provider (og or sc) [string]
37 -d, --debug Turn on debugging information in the model [boolean]
38 -f, --flat Do not include config-name in output directory structure
39 [boolean]
40 -l, --lint Lint input definition [boolean]
41 -o, --output Specify output directory [string] [default: "./out/"]
42 -s, --stools Use swagger-tools to validate OpenAPI 2.0 definitions
43 [boolean]
44 -t, --templates Specify templates directory [string]
45 -v, --verbose Increase verbosity [boolean]
46 -z, --zip Create a .zip file instead of individual files [boolean]
47```
48
49e.g.
50
51```
52node cg --verbose nodejs defs/generator.yaml
53```
54
55In this case, the generated code will be written to the `.out/nodejs` directory.
56
57You can also load the OpenAPI definition from a URL.
58
59### API
60
61```javascript
62const renderer = require('openapi-codegen');
63// load a config and a definition
64renderer.main(definition,config,configName);
65```
66
67## Templates
68
69The local templates were taken directly from `swagger-codegen`. This project is also licensed under [Apache-2.0](LICENSE) for this reason. Generated code is explicitly covered by the [Unlicense](templates/_common/UNLICENSE). Code to downconvert OpenAPI 3.0 definitions is taken from [Angular-Swagger-UI](https://github.com/Orange-OpenSource/angular-swagger-ui) and is MIT licensed.
70
71You can also use the latest online templates from two providers: `og` ([openapi-generator](https://github.com/OpenAPITools/openapi-generator)) and `sc` ([swagger-codegen](https://github.com/swagger-api/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.
72
73### Contributors
74
75See [here](https://github.com/swagger-api/swagger-codegen#template-creator) for a partial list of template contributors.
76
77### Status of the template configurations
78
79The 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.
80
81<details>
82<summary>Click here to expand...</summary>
83
84|Template|Type|Status|README|Authors (TODO)|Config Maintainer|
85|---|---|---|---|---|---|
86|**\_common**|meta| *contains Apache-2.0 and Unlicense licenses*||
87|**Ada**|client|**Untested**
88|akka-scala||
89|android||
90|**apache2**|configuration|**needs work**||
91|apex||
92|aspnetcore||
93|**bash**|client|**Syntax ok, needs testing**||@bkryza|@MikeRalphson
94|**clojure**|client|**Untested**|
95|**codegen**|meta|**Demo only**|||@MikeRalphson
96|**confluenceWikiDocs**|documentation|**Tested** with Docker [server](https://hub.docker.com/r/atlassian/confluence-server/)||
97|cpprest||
98|csharp||
99|**csharp-dotnet2**|client|**Untested**||
100|dart||
101|**debug**|meta|*used for dumping the model state*||@Mermade|@MikeRalphson
102|Eiffel||
103|elixir||
104|**erlang-client**|client|**Untested**||
105|erlang-server|server|
106|finch||
107|flash||
108|**flaskConnexion**|server|**Needs testing**||
109|**go**|client|**Builds, needs testing**||
110|**go-server**|server|**Builds and runs**||
111|**Groovy**|?|**untested**||
112|haskell-http-client|client||||
113|**haskell-servant**|server|**Untested**||
114|**htmlDocs**|documentation|*Appears to work*||
115|**htmlDocs2**|documentation|*Appears to work, no console errors logged*||
116|Java||
117|JavaInflector||
118|JavaJaxRS||
119|JavaPlayFramework||
120|**Javascript**|client|**Untested**||
121|**Javascript-Closure-Angular**|client|**Untested**
122|JavaSpring||
123|JavaVertXServer||
124|**JMeter**|meta|**Untested**||
125|kotlin-client||
126|**lua**|client|**Compiles OK**|
127|lumen||
128|MSF4J||
129|nancyfx||
130|**nodejs**|server|**tested** :white_check_mark:||@jfiala|@MikeRalphson|
131|objc||
132|**openapi**|meta|*outputs the input definition (in OpenAPI 3.0.x form)* :white_check_mark:||@Mermade|@MikeRalphson
133|perl||
134|php||
135|**php-silex**|?|**untested**||
136|php-symfony||
137|pistache-server||
138|powershell||
139|**python**|client|**needs testing**|||@mpnordland
140|qt5cpp||
141|r||
142|rails5||
143|**restbed**|server|**Untested**||
144|ruby||
145|rust||
146|rust-server||
147|scala||
148|scalatra||
149|scalaz|client|**Untested**||
150|**sinatra**|server|**Syntax checks OK**||
151|**slim**|server|**Untested**||
152|**swagger**|meta|*outputs the input definition (in original form if OpenAPI 2.0)* :white_check_mark:||
153|**swagger-static**|documentation|**tested** *template modified to include partials*||
154|swift||
155|swift3||
156|swift4||
157|tizen||
158|typescript-angular||
159|typescript-angularjs||
160|**typescript-axios**|client|**tested**||jaredpalmer|
161|typescript-aurelia||
162|**typescript-fetch**|client|**compiles with tsc ok**||
163|typescript-jquery||
164|**typescript-node**|client|**compiles with tsc ok**||
165|undertow||
166|**validator**|meta|*uses swagger2openapi's OpenAPI 3.0 validator internally* :white_check_mark:||
167|ze-ph|
168
169### New Templates
170
171These templates are examples of how features of OpenAPI Codegen may be used, and best-practices in naming model properties.
172
173|Template|Type|Status|README|Authors|Config Maintainer|
174|---|---|---|---|---|---|
175|testing.dredd|testing|**In progress**|[README](templates/testing.dredd/README.md.mustache)|@Mermade|@MikeRalphson|
176</details>
177
178## Documentation
179
180* [See here](docs/README.md) - contributions welcome
181