Skip to content

Commit a16fcae

Browse files
fix(openapi/upload): better handling for mismatching files/slugs (#1345)
| 🚥 Resolves CX-2293 | | :------------------- | ## 🧰 Changes we previously had a restriction in place where you could not upload a JSON file (e.g., `petstore.json`) to a slug with a YAML file extension (e.g., `--slug file.yml`). the reasoning was that we didn't want to create any unexpected client-side behaviors and we wanted to prioritize explicitness. however, we've been getting feedback that it's misleading how `rdme` directs customers towards certain slugs, only to see an error that they can't use that slug due to this file extension restriction. this PR lifts that restriction and makes it so `rdme` will convert a JSON file to YAML prior to uploading if the slug has a YAML file extension (or vice versa). it will also emit a warning to the user when this happens! ## 🧬 QA & Testing added a bunch of tests for this behavior! --------- Co-authored-by: Emily Kuo <58803587+emilyskuo@users.noreply.github.com>
1 parent 70ae37e commit a16fcae

File tree

3 files changed

+261
-56
lines changed

3 files changed

+261
-56
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,40 @@ exports[`rdme openapi upload > given that the API definition is a local file > a
178178
}
179179
`;
180180
181-
exports[`rdme openapi upload > given that the API definition is a local file > and the \`--slug\` flag is passed > should handle a slug with a valid but mismatching file extension 1`] = `
181+
exports[`rdme openapi upload > given that the API definition is a local file > and the \`--slug\` flag is passed > should handle a slug with a valid but mismatching file extension (.json slug, YAML file) 1`] = `
182182
{
183-
"error": [Error: Please provide a valid file extension that matches the extension on the file you provided. Must be \`.json\`, \`.yaml\`, or \`.yml\`.],
183+
"result": {
184+
"status": "done",
185+
"uri": "/branches/1.0.0/apis/custom-slug.json",
186+
},
187+
"stderr": "- Validating the API definition located at __tests__/__fixtures__/postman/petstore.collection.yaml...
188+
Warning: Support for Postman collections is currently experimental.
189+
Warning: The file extension in your provided slug (.json) does not match
190+
the file extension of the file you're uploading (.yaml). Your API
191+
definition will be converted to JSON prior to upload.
192+
- Updating your API definition to ReadMe...
193+
Updating your API definition to ReadMe... done!
194+
",
195+
"stdout": "🚀 Your API definition (custom-slug.json) was successfully updated in ReadMe!
196+
",
197+
}
198+
`;
199+
200+
exports[`rdme openapi upload > given that the API definition is a local file > and the \`--slug\` flag is passed > should handle a slug with a valid but mismatching file extension (.yml slug, JSON file) 1`] = `
201+
{
202+
"result": {
203+
"status": "done",
204+
"uri": "/branches/1.0.0/apis/custom-slug.yml",
205+
},
184206
"stderr": "- Validating the API definition located at __tests__/__fixtures__/petstore-simple-weird-version.json...
207+
Warning: The file extension in your provided slug (.yml) does not match
208+
the file extension of the file you're uploading (.json). Your API
209+
definition will be converted to YAML prior to upload.
210+
- Updating your API definition to ReadMe...
211+
Updating your API definition to ReadMe... done!
212+
",
213+
"stdout": "🚀 Your API definition (custom-slug.yml) was successfully updated in ReadMe!
185214
",
186-
"stdout": "",
187215
}
188216
`;
189217

0 commit comments

Comments
 (0)