UNPKG

10.8 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/1.1.1 darwin-x64 node-v12.9.1
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/v1.1.1/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/v1.1.1/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/v1.1.1/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 --[no-]validate [default: true] validate requests according to schema
159
160EXAMPLES
161 $ openapi mock ./openapi.yml
162 $ openapi mock https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
163```
164
165_See code: [src/commands/mock.ts](https://github.com/anttiviljami/openapicmd/blob/v1.1.1/src/commands/mock.ts)_
166
167## `openapi read [DEFINITION]`
168
169read, parse and convert OpenAPI definitions
170
171```
172USAGE
173 $ openapi read [DEFINITION]
174
175ARGUMENTS
176 DEFINITION input definition file
177
178OPTIONS
179 -B, --bundle resolve remote $ref pointers
180 -D, --dereference resolve $ref pointers
181 -S, --server=http://localhost:9000 add servers to definition
182 -V, --validate validate against openapi schema
183 -f, --format=(json|yaml|yml) [default: yaml] output format
184 -h, --help show CLI help
185 --json format as json (short for -f json)
186 --yaml format as yaml (short for -f yaml)
187
188EXAMPLES
189 $ openapi read https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
190 $ openapi read ./openapi.yml -f json > openapi.json
191```
192
193_See code: [src/commands/read.ts](https://github.com/anttiviljami/openapicmd/blob/v1.1.1/src/commands/read.ts)_
194
195## `openapi swagger-editor [DEFINITION]`
196
197serve a local Swagger UI instance
198
199```
200USAGE
201 $ openapi swagger-editor [DEFINITION]
202
203ARGUMENTS
204 DEFINITION input definition file
205
206OPTIONS
207 -h, --help show CLI help
208 -p, --port=9000 [default: 9000] port
209 --[no-]logger [default: true] log requests
210
211EXAMPLES
212 $ openapi swagger-editor
213 $ openapi swagger-editor ./openapi.yml
214 $ openapi swagger-editor ./openapi.yml --bundle static
215```
216
217_See code: [src/commands/swagger-editor.ts](https://github.com/anttiviljami/openapicmd/blob/v1.1.1/src/commands/swagger-editor.ts)_
218
219## `openapi swagger-ui [DEFINITION]`
220
221serve or bundle a Swagger UI instance
222
223```
224USAGE
225 $ openapi swagger-ui [DEFINITION]
226
227ARGUMENTS
228 DEFINITION input definition file
229
230OPTIONS
231 -B, --bundle=outDir bundle a static site to directory
232 -S, --server=http://localhost:9000 add servers to definition
233 -h, --help show CLI help
234 -p, --port=9000 [default: 9000] port
235 --[no-]deeplinks [default: true] allow deep linking
236 --expand=full|list|none [default: list] default expansion setting for the operations and tags
237 --[no-]filter [default: true] enable filtering by tag
238 --[no-]logger [default: true] log requests
239 --[no-]operationids [default: true] display operationIds
240 --proxy set up a proxy for the api to avoid CORS issues
241 --[no-]requestduration [default: true] display request durations in "try it now"
242 --[no-]withcredentials [default: true] send cookies in "try it now"
243
244EXAMPLES
245 $ openapi swagger-ui
246 $ openapi swagger-ui ./openapi.yml
247```
248
249_See code: [src/commands/swagger-ui.ts](https://github.com/anttiviljami/openapicmd/blob/v1.1.1/src/commands/swagger-ui.ts)_
250
251## `openapi swagger2openapi [DEFINITION]`
252
253convert Swagger 2.0 definitions to OpenAPI 3.0.x
254
255```
256USAGE
257 $ openapi swagger2openapi [DEFINITION]
258
259ARGUMENTS
260 DEFINITION input definition file
261
262OPTIONS
263 -B, --bundle resolve remote $ref pointers
264 -D, --dereference resolve $ref pointers
265 -S, --server=http://localhost:9000 add servers to definition
266 -V, --validate validate against openapi schema
267 -f, --format=(json|yaml|yml) [default: yaml] output format
268 -h, --help show CLI help
269 --json format as json (short for -f json)
270 --yaml format as yaml (short for -f yaml)
271
272EXAMPLE
273 $ openapi swagger2openapi --yaml ./swagger.json > openapi.yml
274```
275
276_See code: [src/commands/swagger2openapi.ts](https://github.com/anttiviljami/openapicmd/blob/v1.1.1/src/commands/swagger2openapi.ts)_
277
278## `openapi unload`
279
280unload an openapi definition file (writes to .openapiconfig)
281
282```
283USAGE
284 $ openapi unload
285
286OPTIONS
287 -h, --help show CLI help
288
289EXAMPLE
290 $ openapi unload
291```
292
293_See code: [src/commands/unload.ts](https://github.com/anttiviljami/openapicmd/blob/v1.1.1/src/commands/unload.ts)_
294<!-- commandsstop -->
295
296## Contributing
297
298OpenAPI Backend is Free and Open Source Software. Issues and pull requests are more than welcome!
299
300[<img alt="The Chilicorn" src="http://spiceprogram.org/assets/img/chilicorn_sticker.svg" width="250" height="250">](https://spiceprogram.org/oss-sponsorship)