Skip to content

Commit 76e60b3

Browse files
authored
fix(openapi/upload): more edge case handling for URL uploads (#1348)
| 🚥 Resolves CX-1793 | | :------------------- | ## 🧰 Changes expanding on the work from #1344, this PR tweaks a bunch of logic / DX improvements to better account for the following `rdme openapi upload` edge cases: - URL uploads that lack a path but have a custom slug with a JSON file extension (e.g., `rdme openapi upload https://example.com --custom-slug.json`) will now properly read that file and set that slug - URL uploads that lack a path but have a custom slug with a YAML file extension (e.g., `rdme openapi upload https://example.com --custom-slug.yml`) will now properly read that file and set that slug - URL uploads that lack a path and there's no `--slug` passed (e.g., `rdme openapi upload https://example.com`) will now default to `openapi.json` and emit a warning about this behavior - URL uploads with a path that lacks a file extension and there's no `--slug` passed (e.g., `rdme openapi upload https://example.com/some-path`) will now properly handle JSON/YAML and set the slug to that path (e.g., `some-path.json`). [applicable for both creates and updates] ## 🧬 QA & Testing honestly the more test cases i added, the more rework i realized this logic required 😮‍💨 the fact that they're passing brings me a lot of comfort here lol
1 parent 62bc5a4 commit 76e60b3

File tree

3 files changed

+417
-51
lines changed

3 files changed

+417
-51
lines changed

__tests__/commands/openapi/__snapshots__/upload.test.ts.snap

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ exports[`rdme openapi upload > given that the "--legacy-id" flag is passed > sho
6565
}
6666
`;
6767
68+
exports[`rdme openapi upload > given that the API definition is a URL > and the \`--slug\` flag is passed > should create a new API definition in ReadMe with a custom slug with YAML file extension where URL has no path and the file is YAML 1`] = `
69+
{
70+
"result": {
71+
"status": "done",
72+
"uri": "/branches/1.0.0/apis/custom-slug.yml",
73+
},
74+
"stderr": "- Validating the API definition located at https://example.com...
75+
Warning: Support for Postman collections is currently experimental.
76+
- Creating your API definition to ReadMe...
77+
Creating your API definition to ReadMe... done!
78+
",
79+
"stdout": "🚀 Your API definition (custom-slug.yml) was successfully created in ReadMe!
80+
",
81+
}
82+
`;
83+
6884
exports[`rdme openapi upload > given that the API definition is a URL > and the \`--slug\` flag is passed > should create a new API definition in ReadMe with the specified slug 1`] = `
6985
{
7086
"result": {
@@ -80,13 +96,29 @@ exports[`rdme openapi upload > given that the API definition is a URL > and the
8096
}
8197
`;
8298
83-
exports[`rdme openapi upload > given that the API definition is a URL > and the \`--slug\` flag is passed > should create a new API definition in ReadMe with the specified slug where URL has no path 1`] = `
99+
exports[`rdme openapi upload > given that the API definition is a URL > and the \`--slug\` flag is passed > should create a new API definition in ReadMe with the specified slug where URL has no path and the file is JSON 1`] = `
100+
{
101+
"result": {
102+
"status": "done",
103+
"uri": "/branches/1.0.0/apis/custom-slug.json",
104+
},
105+
"stderr": "- Validating the API definition located at https://example.com...
106+
- Creating your API definition to ReadMe...
107+
Creating your API definition to ReadMe... done!
108+
",
109+
"stdout": "🚀 Your API definition (custom-slug.json) was successfully created in ReadMe!
110+
",
111+
}
112+
`;
113+
114+
exports[`rdme openapi upload > given that the API definition is a URL > and the \`--slug\` flag is passed > should create a new API definition in ReadMe with the specified slug where URL has no path and the file is YAML 1`] = `
84115
{
85116
"result": {
86117
"status": "done",
87-
"uri": "/branches/1.0.0/apis/custom-slug.json.json",
118+
"uri": "/branches/1.0.0/apis/custom-slug.json",
88119
},
89120
"stderr": "- Validating the API definition located at https://example.com...
121+
Warning: Support for Postman collections is currently experimental.
90122
- Creating your API definition to ReadMe...
91123
Creating your API definition to ReadMe... done!
92124
",
@@ -99,7 +131,7 @@ exports[`rdme openapi upload > given that the API definition is a URL > and the
99131
{
100132
"result": {
101133
"status": "done",
102-
"uri": "/branches/1.0.0/apis/custom-slug.json.json",
134+
"uri": "/branches/1.0.0/apis/custom-slug.json",
103135
},
104136
"stderr": "- Validating the API definition located at https://example.com/openapi.json?somequery=true...
105137
- Creating your API definition to ReadMe...
@@ -117,6 +149,81 @@ exports[`rdme openapi upload > given that the API definition is a URL > should c
117149
"uri": "/branches/1.0.0/apis/openapi.json",
118150
},
119151
"stderr": "- Validating the API definition located at https://example.com/openapi.json...
152+
Warning: The slug of your API Definition will be set to openapi.json in
153+
ReadMe. This slug is not visible to your end users. To set this slug to
154+
something else, use the \`--slug\` flag.
155+
- Creating your API definition to ReadMe...
156+
✔ Creating your API definition to ReadMe... done!
157+
",
158+
"stdout": "🚀 Your API definition (openapi.json) was successfully created in ReadMe!
159+
",
160+
}
161+
`;
162+
163+
exports[`rdme openapi upload > given that the API definition is a URL > should create a new API definition in ReadMe if there is no file extension and the file is JSON 1`] = `
164+
{
165+
"result": {
166+
"status": "done",
167+
"uri": "/branches/1.0.0/apis/no-extension.json",
168+
},
169+
"stderr": "- Validating the API definition located at https://example.com/no-extension...
170+
Warning: The slug of your API Definition will be set to no-extension.json
171+
in ReadMe. This slug is not visible to your end users. To set this slug to
172+
something else, use the \`--slug\` flag.
173+
- Creating your API definition to ReadMe...
174+
✔ Creating your API definition to ReadMe... done!
175+
",
176+
"stdout": "🚀 Your API definition (no-extension.json) was successfully created in ReadMe!
177+
",
178+
}
179+
`;
180+
181+
exports[`rdme openapi upload > given that the API definition is a URL > should create a new API definition in ReadMe if there is no file extension and the file is YAML 1`] = `
182+
{
183+
"result": {
184+
"status": "done",
185+
"uri": "/branches/1.0.0/apis/no-extension.json",
186+
},
187+
"stderr": "- Validating the API definition located at https://example.com/no-extension...
188+
Warning: Support for Postman collections is currently experimental.
189+
Warning: The slug of your API Definition will be set to no-extension.json
190+
in ReadMe. This slug is not visible to your end users. To set this slug to
191+
something else, use the \`--slug\` flag.
192+
- Creating your API definition to ReadMe...
193+
✔ Creating your API definition to ReadMe... done!
194+
",
195+
"stdout": "🚀 Your API definition (no-extension.json) was successfully created in ReadMe!
196+
",
197+
}
198+
`;
199+
200+
exports[`rdme openapi upload > given that the API definition is a URL > should create a new API definition in ReadMe if there is no path and the file is JSON 1`] = `
201+
{
202+
"result": {
203+
"status": "done",
204+
"uri": "/branches/1.0.0/apis/openapi.json",
205+
},
206+
"stderr": "- Validating the API definition located at https://example.com...
207+
Warning: No filename could be inferred from the provided URL, so the slug
208+
will default to openapi.json. To set a custom slug, use the \`--slug\` flag.
209+
- Creating your API definition to ReadMe...
210+
✔ Creating your API definition to ReadMe... done!
211+
",
212+
"stdout": "🚀 Your API definition (openapi.json) was successfully created in ReadMe!
213+
",
214+
}
215+
`;
216+
217+
exports[`rdme openapi upload > given that the API definition is a URL > should create a new API definition in ReadMe if there is no path and the file is YAML 1`] = `
218+
{
219+
"result": {
220+
"status": "done",
221+
"uri": "/branches/1.0.0/apis/openapi.json",
222+
},
223+
"stderr": "- Validating the API definition located at https://example.com...
224+
Warning: Support for Postman collections is currently experimental.
225+
Warning: No filename could be inferred from the provided URL, so the slug
226+
will default to openapi.json. To set a custom slug, use the \`--slug\` flag.
120227
- Creating your API definition to ReadMe...
121228
✔ Creating your API definition to ReadMe... done!
122229
",
@@ -142,6 +249,9 @@ exports[`rdme openapi upload > given that the API definition is a URL > should u
142249
"uri": "/branches/1.0.0/apis/openapi.json",
143250
},
144251
"stderr": "- Validating the API definition located at https://example.com/openapi.json...
252+
Warning: The slug of your API Definition will be set to openapi.json in
253+
ReadMe. This slug is not visible to your end users. To set this slug to
254+
something else, use the \`--slug\` flag.
145255
- Updating your API definition to ReadMe...
146256
✔ Updating your API definition to ReadMe... done!
147257
",
@@ -150,6 +260,24 @@ exports[`rdme openapi upload > given that the API definition is a URL > should u
150260
}
151261
`;
152262
263+
exports[`rdme openapi upload > given that the API definition is a URL > should update an existing API definition in ReadMe and the URL lacks an extension 1`] = `
264+
{
265+
"result": {
266+
"status": "done",
267+
"uri": "/branches/1.0.0/apis/openapi.json",
268+
},
269+
"stderr": "- Validating the API definition located at https://example.com/no-extension...
270+
Warning: The slug of your API Definition will be set to no-extension.json
271+
in ReadMe. This slug is not visible to your end users. To set this slug to
272+
something else, use the \`--slug\` flag.
273+
- Updating your API definition to ReadMe...
274+
✔ Updating your API definition to ReadMe... done!
275+
",
276+
"stdout": "🚀 Your API definition (no-extension.json) was successfully updated in ReadMe!
277+
",
278+
}
279+
`;
280+
153281
exports[`rdme openapi upload > given that the API definition is a local file > and the \`--slug\` flag is passed > should emit a warning if an object ID is passed and no legacy match is found 1`] = `
154282
{
155283
"result": {

0 commit comments

Comments
 (0)