Skip to content

Commit d957cb2

Browse files
olehshherunion
andauthored
feat: properly display file size feature in openapi inspect command (#1257)
| πŸš₯ Resolves ISSUE_ID | | :------------------- | ## 🧰 Changes This PR introduces handling for the new analyzer features β€” specifically `rawFileSize` and `dereferencedFileSize` β€” as introduced in [readmeio/oas#982](readmeio/oas#982). --------- Co-authored-by: Jon Ursenbach <[email protected]>
1 parent 0ff7cb0 commit d957cb2

File tree

5 files changed

+58
-40
lines changed

5 files changed

+58
-40
lines changed

β€Ž__tests__/commands/openapi/__snapshots__/inspect.test.ts.snapβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ See more help with --help],
168168
exports[`rdme openapi inspect > full reports > should generate a report for @readme/oas-examples/3.0/json/petstore.json 1`] = `
169169
"Here are some interesting things we found in your API definition. πŸ•΅οΈ
170170
171+
Β· Your dereferenced file size is 0.03 MB.
171172
Β· You are using 4 media types throughout your API: application/json, application/x-www-form-urlencoded, application/xml, and multipart/form-data
172173
Β· You have a total of 20 operations in your API.
174+
Β· Your raw file size is 0.01 MB.
173175
Β· You are using 2 security types throughout your API: apiKey and oauth2
174176
175177
🌲 OpenAPI Features
@@ -283,8 +285,10 @@ exports[`rdme openapi inspect > full reports > should generate a report for @rea
283285
exports[`rdme openapi inspect > full reports > should generate a report for @readme/oas-examples/3.0/json/readme.json 1`] = `
284286
"Here are some interesting things we found in your API definition. πŸ•΅οΈ
285287
288+
Β· Your dereferenced file size is 0.32 MB.
286289
Β· You are using 3 media types throughout your API: application/json, multipart/form-data, and text/event-stream
287290
Β· You have a total of 39 operations in your API.
291+
Β· Your raw file size is 0.05 MB.
288292
Β· You are using a single security type throughout your API: http
289293
290294
🌲 OpenAPI Features
@@ -398,8 +402,10 @@ exports[`rdme openapi inspect > full reports > should generate a report for @rea
398402
exports[`rdme openapi inspect > full reports > should generate a report for @readme/oas-examples/3.0/json/readme-extensions.json 1`] = `
399403
"Here are some interesting things we found in your API definition. πŸ•΅οΈ
400404
405+
Β· Your dereferenced file size is 0.01 MB.
401406
Β· You are using a single media type throughout your API: application/json
402407
Β· You have a total of 12 operations in your API.
408+
Β· Your raw file size is 0.01 MB.
403409
Β· You are using a single security type throughout your API: oauth2
404410
405411
🌲 OpenAPI Features
@@ -513,8 +519,10 @@ exports[`rdme openapi inspect > full reports > should generate a report for @rea
513519
exports[`rdme openapi inspect > full reports > should generate a report for @readme/oas-examples/3.1/json/train-travel.json 1`] = `
514520
"Here are some interesting things we found in your API definition. πŸ•΅οΈ
515521
522+
Β· Your dereferenced file size is 0.15 MB.
516523
Β· You are using 2 media types throughout your API: application/json and application/xml
517524
Β· You have a total of 9 operations in your API.
525+
Β· Your raw file size is 0.03 MB.
518526
Β· You are using a single security type throughout your API: oauth2
519527
520528
🌲 OpenAPI Features

β€Ž__tests__/lib/__snapshots__/analyzeOas.test.ts.snapβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
exports[`#analyzeOas > should analyze an OpenAPI definition 1`] = `
44
{
55
"general": {
6+
"dereferencedFileSize": {
7+
"found": 0.03,
8+
"name": "Dereferenced File Size",
9+
},
610
"mediaTypes": {
711
"found": [
812
"application/json",
@@ -16,6 +20,10 @@ exports[`#analyzeOas > should analyze an OpenAPI definition 1`] = `
1620
"found": 20,
1721
"name": "Operation",
1822
},
23+
"rawFileSize": {
24+
"found": 0.01,
25+
"name": "Raw File Size",
26+
},
1927
"securityTypes": {
2028
"found": [
2129
"apiKey",

β€Žpackage-lock.jsonβ€Ž

Lines changed: 21 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
"js-yaml": "^4.1.0",
6464
"json-schema-to-ts": "^3.1.1",
6565
"mime-types": "^3.0.1",
66-
"oas": "^27.0.0",
67-
"oas-normalize": "^14.0.0",
66+
"oas": "^27.1.0",
67+
"oas-normalize": "^14.1.0",
6868
"ora": "^8.1.1",
6969
"prompts": "^2.4.2",
7070
"semver": "^7.5.3",
@@ -84,7 +84,7 @@
8484
"@oclif/test": "^4.1.0",
8585
"@readme/better-ajv-errors": "^2.3.2",
8686
"@readme/eslint-config": "^14.3.0",
87-
"@readme/oas-examples": "^6.0.0",
87+
"@readme/oas-examples": "^6.1.1",
8888
"@rollup/plugin-commonjs": "^28.0.0",
8989
"@rollup/plugin-json": "^6.0.0",
9090
"@rollup/plugin-node-resolve": "^16.0.0",

β€Žsrc/commands/openapi/inspect.tsβ€Ž

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ function buildFeaturesReport(analysis: Analysis, features: string[]) {
106106

107107
function buildFullReport(analysis: Analysis, definitionVersion: string, tableBorder: Record<string, string>) {
108108
const report: string[] = ['Here are some interesting things we found in your API definition. πŸ•΅οΈ', ''];
109+
const sizeKeys = ['rawFileSize', 'dereferencedFileSize'];
109110

110111
// General API definition statistics
111112
report.push(
112113
...(Object.entries(analysis.general || {})
113-
.map(([, info]) => {
114+
.map(([key, info]) => {
114115
if (Array.isArray(info.found)) {
115116
if (!info.found.length) return false;
116117

@@ -121,17 +122,25 @@ function buildFullReport(analysis: Analysis, definitionVersion: string, tableBor
121122
}
122123

123124
return `You are using a single ${info.name.toLowerCase()} throughout your API: ${highlightedData[0]}`;
124-
} else if (info.found > 1) {
125-
let msg: string;
126-
msg = `You have a total of ${chalk.bold(info.found)} ${pluralize(info.name.toLowerCase(), info.found)} in your API.`;
127-
if (info.found > 200) {
128-
msg += ` ${chalk.cyanBright('Wow! 🀯')}`;
129-
}
125+
}
126+
127+
if (info.found === 0) return false;
128+
129+
const isSizeKey = sizeKeys.includes(key);
130+
const isPlural = info.found > 1;
131+
132+
let baseMessage = isSizeKey
133+
? `Your ${info.name.toLowerCase()} is ${chalk.bold(info.found)} MB.`
134+
: isPlural
135+
? `You have a total of ${chalk.bold(info.found)} ${pluralize(info.name.toLowerCase(), info.found)} in your API.`
136+
: `You have a single ${info.name.toLowerCase()} in your API.`;
130137

131-
return msg;
138+
const wowThreshold = isSizeKey ? 10 : 200;
139+
if (info.found > wowThreshold) {
140+
baseMessage += ` ${chalk.cyanBright('Wow! 🀯')}`;
132141
}
133142

134-
return `You have a single ${info.name.toLowerCase()} in your API.`;
143+
return baseMessage;
135144
})
136145
.filter(Boolean)
137146
.map(msg => ` Β· ${msg}`) as string[]),

0 commit comments

Comments
Β (0)