1 | <h1 align="center">OpenAPI Command Line Tool</h1>
|
2 |
|
3 | [![CI](https://github.com/anttiviljami/openapicmd/workflows/CI/badge.svg)](https://github.com/anttiviljami/openapicmd/actions?query=workflow%3ACI)
|
4 | [![npm version](https://img.shields.io/npm/v/openapicmd.svg)](https://www.npmjs.com/package/openapicmd)
|
5 | [![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/anttiviljami/openapicmd/blob/master/LICENSE)
|
6 | [![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)
|
7 | [![Buy me a coffee](https://img.shields.io/badge/donate-buy%20me%20a%20coffee-orange)](https://buymeacoff.ee/anttiviljami)
|
8 |
|
9 | <p align="center">openapicmd - The CLI for all things OpenAPI and Swagger</p>
|
10 |
|
11 | # Install
|
12 |
|
13 | ```
|
14 | npm install -g openapicmd
|
15 | openapi help
|
16 | ```
|
17 |
|
18 | # Features
|
19 | - [x] Read and convert local and remote JSON/YAML OpenAPI definition files
|
20 | - [x] Use as CLI client to easily call API endpoints
|
21 | - [x] Run [Swagger UI](https://github.com/swagger-api/swagger-ui) locally
|
22 | - [x] Bundle static [Swagger UI](https://github.com/swagger-api/swagger-ui) sites
|
23 | - [x] Run [Swagger Editor](https://github.com/swagger-api/swagger-editor) locally
|
24 | - [x] Convert Swagger 2.0 to OpenAPI 3.0.x
|
25 | - [x] Run Local Mock APIs
|
26 |
|
27 | # Commands
|
28 |
|
29 | * [`openapi help`](#openapi-help)
|
30 | * [`openapi read`](#openapi-read)
|
31 | * [`openapi info`](#openapi-info)
|
32 | * [`openapi swagger-ui`](#openapi-swagger-ui)
|
33 | * [`openapi swagger-editor`](#openapi-swagger-editor)
|
34 | * [`openapi call`](#openapi-call)
|
35 | * [`openapi mock`](#openapi-mock)
|
36 | * [`openapi swagger2openapi`](#openapi-swagger2openapi)
|
37 | * [`openapi init`](#openapi-init)
|
38 | * [`openapi load`](#openapi-load)
|
39 | * [`openapi unload`](#openapi-unload)
|
40 |
|
41 | ## `openapi help`
|
42 |
|
43 | display help for openapi
|
44 |
|
45 | ```
|
46 | USAGE
|
47 | $ openapi help [COMMAND]
|
48 |
|
49 | ARGUMENTS
|
50 | COMMAND command to show help for
|
51 |
|
52 | OPTIONS
|
53 | --all see all commands in CLI
|
54 | ```
|
55 |
|
56 | ## `openapi read`
|
57 |
|
58 | Read and manipulate definition files
|
59 |
|
60 | ```
|
61 | USAGE
|
62 | $ openapi read [DEFINITION]
|
63 |
|
64 | ARGUMENTS
|
65 | DEFINITION input definition file
|
66 |
|
67 | OPTIONS
|
68 | -B, --bundle resolve remote $ref pointers
|
69 | -D, --dereference resolve $ref pointers
|
70 | -H, --header=header add request headers when calling remote urls
|
71 | -R, --root=/ override API root path
|
72 | -S, --server=http://localhost:9000 override servers definition
|
73 | -V, --validate validate against openapi schema
|
74 | -f, --format=(json|yaml|yml) [default: yaml] output format
|
75 | -h, --help show CLI help
|
76 | --json format as json (short for -f json)
|
77 | --yaml format as yaml (short for -f yaml)
|
78 |
|
79 | EXAMPLES
|
80 | $ openapi read https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
|
81 | $ openapi read ./openapi.yml -f json > openapi.json
|
82 | ```
|
83 |
|
84 | ## `openapi info`
|
85 |
|
86 | Display API information
|
87 |
|
88 | ```
|
89 | USAGE
|
90 | $ openapi info [DEFINITION]
|
91 |
|
92 | ARGUMENTS
|
93 | DEFINITION input definition file
|
94 |
|
95 | OPTIONS
|
96 | -B, --bundle resolve remote $ref pointers
|
97 | -D, --dereference resolve $ref pointers
|
98 | -H, --header=header add request headers when calling remote urls
|
99 | -R, --root=/ override API root path
|
100 | -S, --server=http://localhost:9000 override servers definition
|
101 | -V, --validate validate against openapi schema
|
102 | -h, --help show CLI help
|
103 | --operations list operations in document
|
104 | --schemas list schemas in document
|
105 |
|
106 | EXAMPLES
|
107 | $ openapi info https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
|
108 | $ openapi info ./openapi.yml
|
109 | ```
|
110 |
|
111 | ## `openapi swagger-ui`
|
112 |
|
113 | Start or bundle a Swagger UI instance
|
114 |
|
115 | ```
|
116 | USAGE
|
117 | $ openapi swagger-ui [DEFINITION]
|
118 |
|
119 | ARGUMENTS
|
120 | DEFINITION input definition file
|
121 |
|
122 | OPTIONS
|
123 | -B, --bundle=outDir bundle a static site to directory
|
124 | -H, --header=header add request headers when calling remote urls
|
125 | -R, --root=/ override API root path
|
126 | -S, --server=http://localhost:9000 override servers definition
|
127 | -h, --help show CLI help
|
128 | -p, --port=9000 [default: 9000] port
|
129 | --[no-]deeplinks [default: true] allow deep linking
|
130 | --expand=full|list|none [default: list] default expansion setting for the operations and tags
|
131 | --[no-]filter [default: true] enable filtering by tag
|
132 | --[no-]logger [default: true] log requests
|
133 | --[no-]operationids [default: true] display operationIds
|
134 | --proxy set up a proxy for the api to avoid CORS issues
|
135 | --[no-]requestduration [default: true] display request durations in "try it now"
|
136 | --[no-]withcredentials [default: true] send cookies in "try it now"
|
137 |
|
138 | EXAMPLES
|
139 | $ openapi swagger-ui
|
140 | $ openapi swagger-ui ./openapi.yml
|
141 | $ openapi swagger-ui ./openapi.yml --bundle outDir
|
142 | ```
|
143 |
|
144 | ## `openapi swagger-editor`
|
145 |
|
146 | Start a Swagger Editor instance
|
147 |
|
148 | ```
|
149 | USAGE
|
150 | $ openapi swagger-editor [DEFINITION]
|
151 |
|
152 | ARGUMENTS
|
153 | DEFINITION input definition file
|
154 |
|
155 | OPTIONS
|
156 | -H, --header=header add request headers when calling remote urls
|
157 | -h, --help show CLI help
|
158 | -p, --port=9000 [default: 9000] port
|
159 | --[no-]logger [default: true] log requests
|
160 |
|
161 | EXAMPLES
|
162 | $ openapi swagger-editor
|
163 | $ openapi swagger-editor ./openapi.yml
|
164 | ```
|
165 |
|
166 | ## `openapi call`
|
167 |
|
168 | Call API endpoints
|
169 |
|
170 | ```
|
171 | USAGE
|
172 | $ openapi call [DEFINITION]
|
173 |
|
174 | ARGUMENTS
|
175 | DEFINITION input definition file
|
176 |
|
177 | OPTIONS
|
178 | -B, --bundle resolve remote $ref pointers
|
179 | -D, --dereference resolve $ref pointers
|
180 | -H, --header=header add request headers when calling remote urls
|
181 | -R, --root=/ override API root path
|
182 | -S, --server=http://localhost:9000 override servers definition
|
183 | -V, --validate validate against openapi schema
|
184 | -d, --data=data request body
|
185 | -h, --help show CLI help
|
186 | -i, --include include status code and response headers the output
|
187 | -o, --operation=operationId operationId
|
188 | -p, --param=key=value parameter
|
189 |
|
190 | EXAMPLES
|
191 | $ openapi call -o getPets
|
192 | $ openapi call -o getPet -p id=1
|
193 | $ openapi call -o createPet -d '{ "name": "Garfield" }'
|
194 | ```
|
195 |
|
196 | ## `openapi mock`
|
197 |
|
198 | Start a local mock API server
|
199 |
|
200 | ```
|
201 | USAGE
|
202 | $ openapi mock [DEFINITION]
|
203 |
|
204 | ARGUMENTS
|
205 | DEFINITION input definition file
|
206 |
|
207 | OPTIONS
|
208 | -H, --header=header add request headers when calling remote urls
|
209 | -R, --root=/ override API root path
|
210 | -S, --server=http://localhost:9000 override servers definition
|
211 | -U, --swagger-ui=docs Swagger UI endpoint
|
212 | -h, --help show CLI help
|
213 | -p, --port=9000 [default: 9000] port
|
214 | --[no-]logger [default: true] log requests
|
215 | --[no-]validate [default: true] validate requests according to schema
|
216 |
|
217 | EXAMPLES
|
218 | $ openapi mock ./openapi.yml
|
219 | $ openapi mock https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
|
220 | ```
|
221 |
|
222 | ## `openapi swagger2openapi`
|
223 |
|
224 | Convert Swagger 2.0 definitions to OpenAPI 3.0.x
|
225 |
|
226 | ```
|
227 | USAGE
|
228 | $ openapi swagger2openapi [DEFINITION]
|
229 |
|
230 | ARGUMENTS
|
231 | DEFINITION input definition file
|
232 |
|
233 | OPTIONS
|
234 | -B, --bundle resolve remote $ref pointers
|
235 | -D, --dereference resolve $ref pointers
|
236 | -H, --header=header add request headers when calling remote urls
|
237 | -R, --root=/ override API root path
|
238 | -S, --server=http://localhost:9000 override servers definition
|
239 | -V, --validate validate against openapi schema
|
240 | -f, --format=(json|yaml|yml) [default: yaml] output format
|
241 | -h, --help show CLI help
|
242 | --json format as json (short for -f json)
|
243 | --yaml format as yaml (short for -f yaml)
|
244 |
|
245 | EXAMPLE
|
246 | $ openapi swagger2openapi --yaml ./swagger.json > openapi.yml
|
247 | ```
|
248 |
|
249 | ## `openapi init`
|
250 |
|
251 | Initialise a definition file from scratch
|
252 |
|
253 | ```
|
254 | USAGE
|
255 | $ openapi init
|
256 |
|
257 | OPTIONS
|
258 | -S, --server=http://localhost:9000 override servers definition
|
259 | -T, --title=title [default: My API] The title for the API
|
260 | -d, --description=description Description for the API
|
261 | -f, --format=(json|yaml|yml) [default: yaml] output format
|
262 | -h, --help show CLI help
|
263 | -v, --version=version [default: 0.0.1] Version of the API
|
264 | --json format as json (short for -f json)
|
265 | --license=mit|apache2 The license for the API
|
266 | --terms=terms A URL to the Terms of Service for the API.
|
267 | --yaml format as yaml (short for -f yaml)
|
268 |
|
269 | EXAMPLE
|
270 | $ openapi init --title 'My API' > openapi.yml
|
271 | ```
|
272 |
|
273 | ## `openapi load`
|
274 |
|
275 | Set the default definition file for a workspace (writes to .openapiconfig)
|
276 |
|
277 | ```
|
278 | USAGE
|
279 | $ openapi load DEFINITION
|
280 |
|
281 | ARGUMENTS
|
282 | DEFINITION input definition file
|
283 |
|
284 | OPTIONS
|
285 | -V, --validate validate against openapi schema
|
286 | -h, --help show CLI help
|
287 |
|
288 | EXAMPLES
|
289 | $ openapi load ./openapi.yml
|
290 | $ openapi load https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
|
291 | ```
|
292 |
|
293 | ## `openapi unload`
|
294 |
|
295 | Unset the default definition file for a workspace (writes to .openapiconfig)
|
296 |
|
297 | ```
|
298 | USAGE
|
299 | $ openapi unload
|
300 |
|
301 | OPTIONS
|
302 | -h, --help show CLI help
|
303 |
|
304 | EXAMPLE
|
305 | $ openapi unload
|
306 | ```
|
307 |
|
308 |
|
309 | ## Contributing
|
310 |
|
311 | OpenAPI Backend is Free and Open Source Software. Issues and pull requests are more than welcome!
|
312 |
|
313 | [<img alt="The Chilicorn" src="http://spiceprogram.org/assets/img/chilicorn_sticker.svg" width="250" height="250">](https://spiceprogram.org/oss-sponsorship)
|