You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: __tests__/commands/openapi/__snapshots__/upload.test.ts.snap
+131-3Lines changed: 131 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,22 @@ exports[`rdme openapi upload > given that the "--legacy-id" flag is passed > sho
65
65
}
66
66
`;
67
67
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...
"stdout": "🚀 Your API definition (custom-slug.yml) was successfully created in ReadMe!
80
+
",
81
+
}
82
+
`;
83
+
68
84
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`] =`
69
85
{
70
86
"result": {
@@ -80,13 +96,29 @@ exports[`rdme openapi upload > given that the API definition is a URL > and the
80
96
}
81
97
`;
82
98
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
+
-CreatingyourAPIdefinitiontoReadMe...
107
+
✔ CreatingyourAPIdefinitiontoReadMe...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`] =`
"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...
"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...
"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...
"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...
@@ -150,6 +260,24 @@ exports[`rdme openapi upload > given that the API definition is a URL > should u
150
260
}
151
261
`;
152
262
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...
"stdout": "🚀 Your API definition (no-extension.json) was successfully updated in ReadMe!
277
+
",
278
+
}
279
+
`;
280
+
153
281
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`] =`
0 commit comments