feat(ir): extract per-content-type OAS examples into endpoint-level v2Examples#16718
feat(ir): extract per-content-type OAS examples into endpoint-level v2Examples#16718adidavid014 wants to merge 4 commits into
Conversation
When an OpenAPI operation declares multiple content types (e.g. application/json and application/ld+json) with distinct per-mediaType examples, the importer now elevates those body-level examples into endpoint-level v2Examples tagged with their content type. Changes: - Add optional contentType field to V2HttpEndpointExample (IR v67.7.0) - Implement synthesizeEndpointExamplesFromPerContentTypeRequestBodies() in OperationConverter.ts - Add extractNativeResponseExamplesByContentType() helper to pair response examples with the correct content type - Add test fixture: multi-content-type-examples This enables the docs UI to display the correct example body when the user switches content types in the playground/API reference. Resolves: FER-11417 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
🚩 Pre-existing counter bug in OpenRPC example conversion causes unnamed examples to overwrite each other
The ++i increment at packages/cli/api-importers/openrpc-to-ir/src/1.x/methods/MethodConverter.ts:360 is placed outside the for loop (lines 275–358) but inside the if block. This means i stays at 0 for every iteration of the loop. When multiple examples lack an explicit name, they all receive the fallback key "Example 1" (line 305: resolvedExample.name ?? \Example ${i + 1}`), and each subsequent unnamed example silently overwrites the previous one in the examplesrecord. Only the last unnamed example survives. This is a pre-existing bug not introduced by this PR (which only addedcontentType: undefined` at line 330), but it's in the same function and worth noting for a follow-up fix.
(Refers to line 360)
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Good catch — this is indeed a pre-existing bug (the ++i is outside the loop). This PR only added contentType: undefined at line 330 and doesn't change the iteration logic. I'll note this for a follow-up fix.
Docs Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on
Docs generation runs |
…pe endpoints only - Change fallback condition from convertedRequestBodies.length > 0 to > 1 so single-content-type endpoints keep using normal v1→v2 example synthesis - Remove debug console.logs from schema-level and response-level tests - Add multi-content-type-examples test fixture and snapshot - Update all affected snapshots (contentType field addition) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ixture Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
Description
Linear ticket: Refs FER-11417
When an OpenAPI operation declares multiple content types (e.g.
application/jsonandapplication/ld+json) that share the same schema but define distinct per-content-type examples, those examples were lost in the CLI → FDR pipeline. This PR preserves them by:contentTypefield toV2HttpEndpointExamplein the IRChanges Made
IR schema (
packages/ir-sdk/)contentType: stringtoV2HttpEndpointExampleinexamples.ymlOAS importer (
packages/cli/api-importers/openapi-to-ir/)OperationConverter.ts: AddedsynthesizeEndpointExamplesFromPerContentTypeRequestBodies()— when endpoint-level examples are empty AND there are multiple content types, iterates eachConvertedRequestBody.v2Examples, pairs them with matching response examples, and creates endpoint-levelV2HttpEndpointExampleentries tagged withcontentTypeconvertedRequestBodies.length > 1— single-content-type endpoints continue using the normal v1→v2 synthesis pipelineIR utils / other importers
generateEndpointExample.ts: Passes throughcontentType: undefinedfor non-content-type examplesMethodConverter.ts,InitializeEmptyServiceExample.ts: AddedcontentTypefield to satisfy typeTest fixtures
multi-content-type-examplesfixture with two content types (application/json,application/ld+json) sharing a schema but with distinct examples including@context/@typefieldscontentType: undefinedfield on existing examples)Testing
multi-content-type-examplestest casecontentType: undefinedadditions, no example quality degradationpnpm lint:biome --fix && pnpm format:fix && pnpm check:fixall passpnpm turbo run compile --filter=@fern-api/openapi-to-ir --filter=@fern-api/registerpassesLink to Devin session: https://app.devin.ai/sessions/55c94557f22f484f81fcad5894748003
Requested by: @adidavid014