UNPKG

10.7 kBMarkdownView Raw
1OpenAPICMD
2==========
3[![Build Status](https://travis-ci.org/anttiviljami/openapicmd.svg?branch=master)](https://travis-ci.org/anttiviljami/openapicmd)
4[![Dependencies](https://david-dm.org/anttiviljami/openapicmd.svg)](https://david-dm.org/anttiviljami/openapicmd)
5[![npm version](https://img.shields.io/npm/v/openapicmd.svg)](https://www.npmjs.com/package/openapicmd)
6[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/anttiviljami/openapicmd/blob/master/LICENSE)
7[![Sponsored](https://img.shields.io/badge/chilicorn-sponsored-brightgreen.svg?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAPCAMAAADjyg5GAAABqlBMVEUAAAAzmTM3pEn%2FSTGhVSY4ZD43STdOXk5lSGAyhz41iz8xkz2HUCWFFhTFFRUzZDvbIB00Zzoyfj9zlHY0ZzmMfY0ydT0zjj92l3qjeR3dNSkoZp4ykEAzjT8ylUBlgj0yiT0ymECkwKjWqAyjuqcghpUykD%2BUQCKoQyAHb%2BgylkAyl0EynkEzmkA0mUA3mj86oUg7oUo8n0k%2FS%2Bw%2Fo0xBnE5BpU9Br0ZKo1ZLmFZOjEhesGljuzllqW50tH14aS14qm17mX9%2Bx4GAgUCEx02JySqOvpSXvI%2BYvp2orqmpzeGrQh%2Bsr6yssa2ttK6v0bKxMBy01bm4zLu5yry7yb29x77BzMPCxsLEzMXFxsXGx8fI3PLJ08vKysrKy8rL2s3MzczOH8LR0dHW19bX19fZ2dna2trc3Nzd3d3d3t3f39%2FgtZTg4ODi4uLj4%2BPlGxLl5eXm5ubnRzPn5%2Bfo6Ojp6enqfmzq6urr6%2Bvt7e3t7u3uDwvugwbu7u7v6Obv8fDz8%2FP09PT2igP29vb4%2BPj6y376%2Bu%2F7%2Bfv9%2Ff39%2Fv3%2BkAH%2FAwf%2FtwD%2F9wCyh1KfAAAAKXRSTlMABQ4VGykqLjVCTVNgdXuHj5Kaq62vt77ExNPX2%2Bju8vX6%2Bvr7%2FP7%2B%2FiiUMfUAAADTSURBVAjXBcFRTsIwHAfgX%2FtvOyjdYDUsRkFjTIwkPvjiOTyX9%2FAIJt7BF570BopEdHOOstHS%2BX0s439RGwnfuB5gSFOZAgDqjQOBivtGkCc7j%2B2e8XNzefWSu%2BsZUD1QfoTq0y6mZsUSvIkRoGYnHu6Yc63pDCjiSNE2kYLdCUAWVmK4zsxzO%2BQQFxNs5b479NHXopkbWX9U3PAwWAVSY%2FpZf1udQ7rfUpQ1CzurDPpwo16Ff2cMWjuFHX9qCV0Y0Ok4Jvh63IABUNnktl%2B6sgP%2BARIxSrT%2FMhLlAAAAAElFTkSuQmCC)](http://spiceprogram.org/oss-sponsorship)
8
9Command line tools for OpenAPI-enabled APIs.
10
11<!-- toc -->
12* [Features](#features)
13* [Usage](#usage)
14* [Commands](#commands)
15<!-- tocstop -->
16
17# Features
18- [x] Read and convert local and remote JSON/YAML OpenAPI definition files
19- [x] Run [Swagger UI](https://github.com/swagger-api/swagger-ui) locally
20- [x] Bundle static [Swagger UI](https://github.com/swagger-api/swagger-ui) sites
21- [x] Run [Swagger Editor](https://github.com/swagger-api/swagger-editor) locally
22- [x] Convert Swagger 2.0 to OpenAPI 3.0.x
23- [x] Run Mock APIs
24- [ ] Use as CLI client to call API operations
25
26# Usage
27<!-- usage -->
28```sh-session
29$ npm install -g openapicmd
30$ openapi COMMAND
31running command...
32$ openapi (-v|--version|version)
33openapicmd/0.1.12 darwin-x64 node-v10.17.0
34$ openapi --help [COMMAND]
35USAGE
36 $ openapi COMMAND
37...
38```
39<!-- usagestop -->
40# Commands
41<!-- commands -->
42* [`openapi help [COMMAND]`](#openapi-help-command)
43* [`openapi info [DEFINITION]`](#openapi-info-definition)
44* [`openapi init`](#openapi-init)
45* [`openapi load DEFINITION`](#openapi-load-definition)
46* [`openapi mock [DEFINITION]`](#openapi-mock-definition)
47* [`openapi read [DEFINITION]`](#openapi-read-definition)
48* [`openapi swagger-editor [DEFINITION]`](#openapi-swagger-editor-definition)
49* [`openapi swagger-ui [DEFINITION]`](#openapi-swagger-ui-definition)
50* [`openapi swagger2openapi [DEFINITION]`](#openapi-swagger2openapi-definition)
51* [`openapi unload`](#openapi-unload)
52
53## `openapi help [COMMAND]`
54
55display help for openapi
56
57```
58USAGE
59 $ openapi help [COMMAND]
60
61ARGUMENTS
62 COMMAND command to show help for
63
64OPTIONS
65 --all see all commands in CLI
66```
67
68_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.1.6/src/commands/help.ts)_
69
70## `openapi info [DEFINITION]`
71
72print information about definition file
73
74```
75USAGE
76 $ openapi info [DEFINITION]
77
78ARGUMENTS
79 DEFINITION input definition file
80
81OPTIONS
82 -h, --help show CLI help
83 --[no-]operations list operations in document
84 --[no-]schemas list schemas in document
85
86EXAMPLES
87 $ openapi info https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
88 $ openapi info ./openapi.yml
89```
90
91_See code: [src/commands/info.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/info.ts)_
92
93## `openapi init`
94
95initialise an OpenAPI definition file
96
97```
98USAGE
99 $ openapi init
100
101OPTIONS
102 -S, --server=http://localhost:9000 add servers to definition
103 -T, --title=title [default: My API] The title for the API
104 -d, --description=description Description for the API
105 -f, --format=(json|yaml|yml) [default: yaml] output format
106 -h, --help show CLI help
107 -v, --version=version [default: 0.0.1] Version of the API
108 --json format as json (short for -f json)
109 --license=mit|apache2 The license for the API
110 --terms=terms A URL to the Terms of Service for the API.
111 --yaml format as yaml (short for -f yaml)
112
113EXAMPLE
114 $ openapi init --title 'My API' > openapi.yml
115```
116
117_See code: [src/commands/init.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/init.ts)_
118
119## `openapi load DEFINITION`
120
121load an openapi definition file (writes to .openapiconfig)
122
123```
124USAGE
125 $ openapi load DEFINITION
126
127ARGUMENTS
128 DEFINITION input definition file
129
130OPTIONS
131 -V, --validate validate against openapi schema
132 -h, --help show CLI help
133
134EXAMPLES
135 $ openapi load ./openapi.yml
136 $ openapi load https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
137```
138
139_See code: [src/commands/load.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/load.ts)_
140
141## `openapi mock [DEFINITION]`
142
143start a local mock API server
144
145```
146USAGE
147 $ openapi mock [DEFINITION]
148
149ARGUMENTS
150 DEFINITION input definition file
151
152OPTIONS
153 -U, --swagger-ui=docs Swagger UI endpoint
154 -h, --help show CLI help
155 -p, --port=9000 [default: 9000] port
156 -s, --serveroverride=http://localhost:9000 override servers definition
157 --[no-]logger [default: true] log requests
158
159EXAMPLES
160 $ openapi mock ./openapi.yml
161 $ openapi mock https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
162```
163
164_See code: [src/commands/mock.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/mock.ts)_
165
166## `openapi read [DEFINITION]`
167
168read, parse and convert OpenAPI definitions
169
170```
171USAGE
172 $ openapi read [DEFINITION]
173
174ARGUMENTS
175 DEFINITION input definition file
176
177OPTIONS
178 -B, --bundle resolve remote $ref pointers
179 -D, --dereference resolve $ref pointers
180 -S, --server=http://localhost:9000 add servers to definition
181 -V, --validate validate against openapi schema
182 -f, --format=(json|yaml|yml) [default: yaml] output format
183 -h, --help show CLI help
184 --json format as json (short for -f json)
185 --yaml format as yaml (short for -f yaml)
186
187EXAMPLES
188 $ openapi read https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
189 $ openapi read ./openapi.yml -f json > openapi.json
190```
191
192_See code: [src/commands/read.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/read.ts)_
193
194## `openapi swagger-editor [DEFINITION]`
195
196serve a local Swagger UI instance
197
198```
199USAGE
200 $ openapi swagger-editor [DEFINITION]
201
202ARGUMENTS
203 DEFINITION input definition file
204
205OPTIONS
206 -h, --help show CLI help
207 -p, --port=9000 [default: 9000] port
208 --[no-]logger [default: true] log requests
209
210EXAMPLES
211 $ openapi swagger-editor
212 $ openapi swagger-editor ./openapi.yml
213 $ openapi swagger-editor ./openapi.yml --bundle static
214```
215
216_See code: [src/commands/swagger-editor.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/swagger-editor.ts)_
217
218## `openapi swagger-ui [DEFINITION]`
219
220serve or bundle a Swagger UI instance
221
222```
223USAGE
224 $ openapi swagger-ui [DEFINITION]
225
226ARGUMENTS
227 DEFINITION input definition file
228
229OPTIONS
230 -B, --bundle=outDir bundle a static site to directory
231 -S, --server=http://localhost:9000 add servers to definition
232 -h, --help show CLI help
233 -p, --port=9000 [default: 9000] port
234 --[no-]deeplinks [default: true] allow deep linking
235 --expand=full|list|none [default: list] default expansion setting for the operations and tags
236 --[no-]filter [default: true] enable filtering by tag
237 --[no-]logger [default: true] log requests
238 --[no-]operationids [default: true] display operationIds
239 --proxy set up a proxy for the api to avoid CORS issues
240 --[no-]requestduration [default: true] display request durations in "try it now"
241 --[no-]withcredentials [default: true] send cookies in "try it now"
242
243EXAMPLES
244 $ openapi swagger-ui
245 $ openapi swagger-ui ./openapi.yml
246```
247
248_See code: [src/commands/swagger-ui.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/swagger-ui.ts)_
249
250## `openapi swagger2openapi [DEFINITION]`
251
252convert Swagger 2.0 definitions to OpenAPI 3.0.x
253
254```
255USAGE
256 $ openapi swagger2openapi [DEFINITION]
257
258ARGUMENTS
259 DEFINITION input definition file
260
261OPTIONS
262 -B, --bundle resolve remote $ref pointers
263 -D, --dereference resolve $ref pointers
264 -S, --server=http://localhost:9000 add servers to definition
265 -V, --validate validate against openapi schema
266 -f, --format=(json|yaml|yml) [default: yaml] output format
267 -h, --help show CLI help
268 --json format as json (short for -f json)
269 --yaml format as yaml (short for -f yaml)
270
271EXAMPLE
272 $ openapi swagger2openapi --yaml ./swagger.json > openapi.yml
273```
274
275_See code: [src/commands/swagger2openapi.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/swagger2openapi.ts)_
276
277## `openapi unload`
278
279unload an openapi definition file (writes to .openapiconfig)
280
281```
282USAGE
283 $ openapi unload
284
285OPTIONS
286 -h, --help show CLI help
287
288EXAMPLE
289 $ openapi unload
290```
291
292_See code: [src/commands/unload.ts](https://github.com/anttiviljami/openapicmd/blob/v0.1.12/src/commands/unload.ts)_
293<!-- commandsstop -->
294
295## Contributing
296
297OpenAPI Backend is Free and Open Source Software. Issues and pull requests are more than welcome!
298
299[<img alt="The Chilicorn" src="http://spiceprogram.org/assets/img/chilicorn_sticker.svg" width="250" height="250">](https://spiceprogram.org/oss-sponsorship)