Skip to content

Support content attribute with a schema in parameter definitions#2837

Open
nbudin wants to merge 2 commits into
openapi-ts:mainfrom
nbudin:fix/parameter-content-type-inference
Open

Support content attribute with a schema in parameter definitions#2837
nbudin wants to merge 2 commits into
openapi-ts:mainfrom
nbudin:fix/parameter-content-type-inference

Conversation

@nbudin

@nbudin nbudin commented Jun 26, 2026

Copy link
Copy Markdown

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 content attribute but no top-level schema attribute, openapi-typescript will now use the schema field of the content attribute 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:examples caused 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 content attributes in parameters, and for any schema that does, it should now infer the correct type for that parameter given the embedded schema attribute.

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 content attributes, 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

  • Unit tests updated
  • docs/ updated (if necessary) - I think not applicable for this?
  • pnpm run update:examples run (only applicable for openapi-typescript)

nbudin and others added 2 commits June 26, 2026 10:47
…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>
@nbudin nbudin requested a review from a team as a code owner June 26, 2026 18:04
@nbudin nbudin requested a review from drwpow June 26, 2026 18:04
@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 84da9a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

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

@netlify

netlify Bot commented Jun 26, 2026

Copy link
Copy Markdown

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 84da9a6

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant