Support content attribute with a schema in parameter definitions#2837
Open
nbudin wants to merge 2 commits into
Open
Support content attribute with a schema in parameter definitions#2837nbudin wants to merge 2 commits into
nbudin wants to merge 2 commits into
Conversation
…type when schema is absent
When a parameter is defined with `content: { "application/json": { schema: ... } }`
instead of a top-level `schema`, the generated TypeScript type was falling back to
`string`. This change extracts the schema from the single required content entry
(per the OAS 3.x spec) and uses it as the parameter type.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 84da9a6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a partial fix for #2569. It only addresses the openapi-typescript side of things and not openapi-fetch, openapi-react-query, or other clients, because according to the roadmap, those libraries are being deprecated.
Changes
When generating code for a parameter that has a
contentattribute but no top-levelschemaattribute, openapi-typescript will now use theschemafield of thecontentattribute as the type of the parameter.It's still up to the client code to handle correctly serializing the data for this, and I haven't attempted to solve that part. I'd be happy to work on a solution for that as well, but I'm unsure of the direction the maintainers would like to go in for this, so if you have an idea, I'd be very much up for working on it!
How to Review
Running
pnpm run update:examplescaused a huge number of changes, I think mostly because those APIs that it's consuming have changed since the last time this was run on main. I pushed those in a separate commit to make it easier to review this PR just by looking at the first commit.This should theoretically generate identical TypeScript files for any schema that doesn't include
contentattributes in parameters, and for any schema that does, it should now infer the correct type for that parameter given the embeddedschemaattribute.I'm not sure whether or not this qualifies as a breaking change. In theory, this would change the TS output for schemas that include
contentattributes, so code relying on that could break. Arguably, the output wasn't correct before this, so it might not be a real breaking change. Happy to discuss!Checklist
docs/updated (if necessary) - I think not applicable for this?pnpm run update:examplesrun (only applicable for openapi-typescript)