Skip to content

Commit daa5346

Browse files
erunionkanadgupta
andauthored
feat(openapi): introduction of a new openapi:inspect command (#698)
* feat: introduction of a new `openapi:uses` command * fix: clarifying that our openapi commands accept urls * feat: swapping out the analysis work with it now living in `oas` * fix: updating oas to move the reducer back to where it was * feat: adding `--feature` args to `openapi:uses` * feat: improvements to readme and circularRef reporting * test: adding tests * fix: fixing spacing bugs and adding tests * fix: check for features length * Update src/lib/softError.ts Co-authored-by: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com> * Update src/cmds/openapi/uses.ts Co-authored-by: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com> * fix: pr feedback * fix: renaming the command to `openapi:uses` * docs: `openapi:inspect` (#706) * fix: file placeholders * docs: add docs on inspect Co-authored-by: Kanad Gupta <git@kanad.dev> Co-authored-by: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com>
1 parent 526e716 commit daa5346

21 files changed

+1525
-342
lines changed

README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ With `rdme`, you have access to a variety of tools to manage your API definition
140140
- [Syncing](#syncing-an-api-definition-to-readme) 🦉
141141
- [Validation](#validating-an-api-definition)
142142
- [Reduction](#reducing-an-api-definition) 📉
143+
- [Inspection](#inspecting-an-api-definition) 🔍
143144

144145
`rdme` supports [OpenAPI 3.1](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md), [OpenAPI 3.0](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md), and [Swagger 2.x](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md).
145146

146147
<!--alex ignore postman-postwoman-->
147148

148-
You can also pass in [Postman Collections](https://www.postman.com/collection/). Postman Collections are converted to OpenAPI using [`postman-to-openapi`](https://github.com/joolfe/postman-to-openapi) prior to any syncing/validation/reduction.
149+
You can also pass in [Postman Collections](https://www.postman.com/collection/). Postman Collections are converted to OpenAPI using [`postman-to-openapi`](https://github.com/joolfe/postman-to-openapi) prior to any syncing/validation/etc.
149150

150151
The following examples use JSON files, but `rdme` supports API Definitions that are written in either JSON or YAML.
151152

@@ -175,32 +176,32 @@ rdme openapi
175176

176177
##### Uploading a New API Definition to ReadMe
177178

178-
This will upload `path-to-openapi.json` to your project and return an ID and URL for you to later update your file, and view it in the client.
179+
This will upload the API definition at the given URL or path to your project and return an ID and URL for you to later update your file, and view it in the client.
179180

180181
```sh
181-
rdme openapi [path-to-file.json]
182+
rdme openapi [url-or-local-path-to-file]
182183
```
183184

184185
If you want to bypass the prompt to create or update an API definition, you can pass the `--create` flag:
185186

186187
```sh
187-
rdme openapi [path-to-file.json] --version={project-version} --create
188+
rdme openapi [url-or-local-path-to-file] --version={project-version} --create
188189
```
189190

190191
##### Editing (Re-Syncing) an Existing API Definition
191192

192193
This will edit (re-sync) an existing API definition (identified by `--id`) within your ReadMe project. **This is the recommended approach for usage in CI environments.**
193194

194195
```sh
195-
rdme openapi [path-to-file.json] --id={existing-id}
196+
rdme openapi [url-or-local-path-to-file] --id={existing-id}
196197
```
197198

198199
##### Uploading or Editing an API Definition in a Project Version
199200

200201
You can additionally include a version flag, specifying the target version for your file's destination. This approach will provide you with CLI prompts, so we do not recommend this technique in CI environments.
201202

202203
```sh
203-
rdme openapi [path-to-file.json] --version={project-version}
204+
rdme openapi [url-or-local-path-to-file] --version={project-version}
204205
```
205206

206207
If you wish to use the version specified [in the `info.version` field of your API definition](https://spec.openapis.org/oas/v3.1.0#fixed-fields-0), you can pass the `--useSpecVersion` option. For example, say [the `info` object](https://spec.openapis.org/oas/v3.1.0#info-object) of your API definition looks like this:
@@ -216,13 +217,13 @@ If you wish to use the version specified [in the `info.version` field of your AP
216217
You can pass in the `--useSpecVersion` option, which would be equivalent to passing in `--version=1.2.3`:
217218

218219
```sh
219-
rdme openapi [path-to-file.json] --useSpecVersion
220+
rdme openapi [url-or-local-path-to-file] --useSpecVersion
220221
```
221222

222223
You can add `--update` to the command so if there's only one API definition for the given project version to update, it will select it without any prompts:
223224

224225
```sh
225-
rdme openapi [path-to-file.json] --version={project-version} --update
226+
rdme openapi [url-or-local-path-to-file] --version={project-version} --update
226227
```
227228

228229
##### Override the Working Directory
@@ -238,7 +239,7 @@ rdme openapi petstore.json --workingDirectory=[path to directory]
238239
You can also perform a local validation of your API definition (no ReadMe account required!), which can be useful when constructing or editing your API definition.
239240

240241
```sh
241-
rdme openapi:validate [path-to-file.json]
242+
rdme openapi:validate [url-or-local-path-to-file]
242243
```
243244

244245
Similar to the `openapi` command, you can also [omit the file path](#omitting-the-file-path).
@@ -248,7 +249,7 @@ Similar to the `openapi` command, you can also [omit the file path](#omitting-th
248249
We also offer a tool that allows you to reduce a large API definition down to a specific set of tags or paths (again, no ReadMe account required!). This can be useful if you're debugging a problematic schema somewhere, or if you have a file that is too big to maintain.
249250

250251
```sh
251-
rdme openapi:reduce [path-to-file.json]
252+
rdme openapi:reduce [url-or-local-path-to-file]
252253
```
253254

254255
The command will ask you a couple questions about how you wish to reduce the file and then do so. If you wish to automate this command, you can pass in CLI arguments to bypass the prompts. Here's an example use case:
@@ -265,6 +266,22 @@ rdme openapi:reduce petstore.json --path /pet/{id} --method get --method put --o
265266

266267
As with the `openapi` command, you can also [omit the file path](#omitting-the-file-path).
267268

269+
#### Inspecting an API Definition
270+
271+
This tool can also perform a comprehensive analysis (again, no ReadMe account required!) of your API definition to determine how it's utilizing aspects of [the OpenAPI Specification](https://spec.openapis.org/oas/v3.1.0.html) (such as circular references, polymorphism, etc.) and any [ReadMe-specific extensions](https://docs.readme.com/main/docs/openapi-extensions) you might be using.
272+
273+
```sh
274+
rdme openapi:inspect [url-or-local-path-to-file]
275+
```
276+
277+
This command contains a `--feature` flag so you can filter for one or several specific features. If you pass in one or more `--feature` flags, the command returns a `0` exit code if your definition contains all of the given features and a `1` exit code if your definition lacks any of the given features.
278+
279+
```sh
280+
rdme openapi:inspect [url-or-local-path-to-file] --feature circularRefs --feature polymorphism
281+
```
282+
283+
As with the `openapi` command, you can also [omit the file path](#omitting-the-file-path).
284+
268285
### Docs (a.k.a. Guides) 📖
269286

270287
The Markdown files will require YAML front matter with certain ReadMe documentation attributes. Check out [our docs](https://docs.readme.com/docs/rdme#markdown-file-setup) for more info on setting up your front matter.

__tests__/__snapshots__/index.test.ts.snap

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Upload, or resync, your OpenAPI/Swagger definition to ReadMe.
66
77
Usage
88
9-
rdme openapi [file] [options]
9+
rdme openapi [file|url] [options]
1010
1111
Options
1212
@@ -30,8 +30,10 @@ Options
3030
3131
Related commands
3232
33-
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
34-
$ rdme openapi:validate Validate your OpenAPI/Swagger definition.
33+
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
34+
$ rdme openapi:validate Validate your OpenAPI/Swagger definition.
35+
$ rdme openapi:inspect Analyze an OpenAPI/Swagger definition for various OpenAPI and ReadMe
36+
feature usage.
3537
"
3638
`;
3739

@@ -41,7 +43,7 @@ Upload, or resync, your OpenAPI/Swagger definition to ReadMe.
4143
4244
Usage
4345
44-
rdme openapi [file] [options]
46+
rdme openapi [file|url] [options]
4547
4648
Options
4749
@@ -65,8 +67,10 @@ Options
6567
6668
Related commands
6769
68-
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
69-
$ rdme openapi:validate Validate your OpenAPI/Swagger definition.
70+
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
71+
$ rdme openapi:validate Validate your OpenAPI/Swagger definition.
72+
$ rdme openapi:inspect Analyze an OpenAPI/Swagger definition for various OpenAPI and ReadMe
73+
feature usage.
7074
"
7175
`;
7276

@@ -76,7 +80,7 @@ Upload, or resync, your OpenAPI/Swagger definition to ReadMe.
7680
7781
Usage
7882
79-
rdme openapi [file] [options]
83+
rdme openapi [file|url] [options]
8084
8185
Options
8286
@@ -100,8 +104,10 @@ Options
100104
101105
Related commands
102106
103-
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
104-
$ rdme openapi:validate Validate your OpenAPI/Swagger definition.
107+
$ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset.
108+
$ rdme openapi:validate Validate your OpenAPI/Swagger definition.
109+
$ rdme openapi:inspect Analyze an OpenAPI/Swagger definition for various OpenAPI and ReadMe
110+
feature usage.
105111
"
106112
`;
107113

0 commit comments

Comments
 (0)