Skip to content

fix(openapi/upload): better handling for mismatching files/slugs#1345

Merged
kanadgupta merged 13 commits intonextfrom
kanad-2025-09-16/CX-2293
Sep 17, 2025
Merged

fix(openapi/upload): better handling for mismatching files/slugs#1345
kanadgupta merged 13 commits intonextfrom
kanad-2025-09-16/CX-2293

Conversation

@kanadgupta
Copy link
Copy Markdown
Contributor

@kanadgupta kanadgupta commented Sep 16, 2025

🚥 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!

@kanadgupta kanadgupta added command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands bug Something isn't working labels Sep 16, 2025
@kanadgupta kanadgupta marked this pull request as ready for review September 16, 2025 22:59
Copy link
Copy Markdown
Contributor

@emilyskuo emilyskuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One clarifying question and one minor copy tweak, but otherwise looks good!

filename =
// biome-ignore lint/nursery/noUnnecessaryConditions: false positive
extensionsMatch && fileExtension
? `${this.flags.slug.replace(slugExtension, '')}${fileExtension}`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this replace only changing the filename in the case where slugExtension is .yml and fileExtension is .yaml (and vice versa)? If extensions match and are .json, the result is the same right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main reason this is here is to account for if someone passes in something like rdme openapi upload some-file.json --slug custom-slug — in this case it would add the .json to the custom-slug prior to upload. but yes, in most cases, the replacement isn't actually changing the slug's file extension!

if (fileExtension !== slugExtension && !(isFileYaml && yamlExtensions.includes(slugExtension))) {
extensionsMatch = false;
this.warn(
`The file extension in your provided slug (${slugExtension}) does not match the file extension of the file you're uploading (${fileExtension}). Your API definition will be uploaded as ${isFileYaml ? 'JSON' : 'YAML'}.`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's implied, but might be nice to explicitly say that we're converting the file

Suggested change
`The file extension in your provided slug (${slugExtension}) does not match the file extension of the file you're uploading (${fileExtension}). Your API definition will be uploaded as ${isFileYaml ? 'JSON' : 'YAML'}.`,
`The file extension in your provided slug (${slugExtension}) does not match the file extension of the file you're uploading (${fileExtension}). Your API definition will be converted and uploaded as ${isFileYaml ? 'JSON' : 'YAML'}.`,

Copy link
Copy Markdown
Contributor Author

@kanadgupta kanadgupta Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes agreed 🧠 i went a little further to clean this up, let me know what you think! 83dd203

kanadgupta and others added 5 commits September 16, 2025 17:18
@kanadgupta kanadgupta merged commit a16fcae into next Sep 17, 2025
9 checks passed
@kanadgupta kanadgupta deleted the kanad-2025-09-16/CX-2293 branch September 17, 2025 00:41
kanadgupta pushed a commit that referenced this pull request Sep 17, 2025
## [10.5.2-next.2](v10.5.2-next.1...v10.5.2-next.2) (2025-09-17)

### Bug Fixes

* **openapi/upload:** better handling for mismatching files/slugs ([#1345](#1345)) ([a16fcae](a16fcae))

[skip ci]
@kanadgupta
Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 10.5.2-next.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

kanadgupta pushed a commit that referenced this pull request Sep 24, 2025
## [10.5.2](v10.5.1...v10.5.2) (2025-09-24)

### Bug Fixes

* **openapi/upload:** better handling for mismatching files/slugs ([#1345](#1345)) ([a16fcae](a16fcae))
* **openapi/upload:** handle funky URLs ([#1344](#1344)) ([9a827ab](9a827ab))

[skip ci]
@kanadgupta
Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 10.5.2 🎉

The release is available on:

(Note: Kanad wrote this by hand this because the semantic-release workflow failed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands released on @next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants