fix(cli): use schema-level examples for OpenAPI parameters - #17658
fix(cli): use schema-level examples for OpenAPI parameters#17658willkendall01 wants to merge 2 commits into
Conversation
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.
AI Review Summary
Small, focused change that falls back to schema-level examples for OpenAPI parameters before autogenerating. Logic looks correct; main nits are around the example-name generation loop and a subtle name-collision path with the earlier parameter-example naming.
- 🔵 3 suggestion(s)
To request another review, comment /ai-review on this pull request.
| const exampleName = this.context.generateUniqueName({ | ||
| prefix: `${this.parameter.name}_example`, | ||
| existingNames: Object.keys(v2Examples.userSpecifiedExamples) | ||
| }); |
There was a problem hiding this comment.
🔵 suggestion
generateUniqueName is called with existingNames: Object.keys(v2Examples.userSpecifiedExamples), but this block only runs when that map is empty — so on the first iteration there are no existing names, and only subsequent iterations get uniqueness. That works, but it means the first schema example may collide with an autogenerated name later (${parameter.name}_example) if downstream code merges maps. Worth double-checking the naming convention matches what Api-Arg_example vs AccountPhotoGetArg_example_0 in the snapshot implies — the two differing conventions in the snapshot suggest two different code paths are producing names, which is easy to trip over later.
| - circle_crop: false | ||
| dbx_account_id: "dbid:plant-fern-123" | ||
| expect_account_photo: true | ||
| size: 128x128 |
There was a problem hiding this comment.
🔵 suggestion
size: 128x128 is unquoted here but the expected value is the string "128x128". YAML parses this as a string anyway, but quoting it (like dbx_account_id) makes the intent explicit and avoids surprises if the value ever becomes something like 128e2.
| size: 128x128 | |
| size: "128x128" |
| expect(endpoint).toBeDefined(); | ||
|
|
||
| const header = endpoint?.headers.find((header) => getWireValue(header.name) === "Api-Arg"); | ||
| expect(header).toBeDefined(); | ||
|
|
||
| const expectedExample = { | ||
| circle_crop: false, | ||
| dbx_account_id: "dbid:plant-fern-123", | ||
| expect_account_photo: true, | ||
| size: "128x128" | ||
| }; | ||
| expect(Object.values(header?.v2Examples?.userSpecifiedExamples ?? {})).toEqual([expectedExample]); |
There was a problem hiding this comment.
🔵 suggestion
Optional chaining after expect(...).toBeDefined() means a missing endpoint/header silently degrades into toEqual([]) failures elsewhere rather than a clear failure. Consider narrowing with a non-optional assertion (e.g. if (endpoint == null) throw ... or expect(header).toBeDefined(); const h = header!;) so the subsequent assertions actually test what they claim.
…ate register snapshot Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Docs Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on
Docs generation runs |
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 N/A
When an OpenAPI parameter has no
example/examplesof its own,AbstractParameterConverter.convertParameterExamplesskipped straight to autogenerating an example from property types (e.g.{"dbx_account_id": "string"}), ignoringexample/examplesdeclared on the parameter's schema (including$ref'd object schemas used for JSON-encoded headers viarespect-parameter-content).Now the converter resolves the original parameter schema (following
$refalias chains, with a cycle guard) and, if it declares examples, uses those asuserSpecifiedExamplesbefore falling back to autogeneration:Changes Made
AbstractParameterConverter: passoriginalSchemaintoconvertParameterExamples; newresolveSchemaReferenceChainfollows$ref→$refaliases; read schema-level examples viacontext.getExamplesFromSchemawhen the parameter has none.parameter-contentfixture: addexamplestoAccountPhotoGetArgand anX-Plant-Idheader whose schema isPlantIdAlias -> PlantId(withexample); snapshot updated.parameter-schema-examples.test.tscovering the JSON-encoded header case and the alias-chain case.packages/cli/registeropenapi-from-flag-simple-ir.snapupdated:userIdpath param's schemaexample: user123is now reported as user-specified instead of autogenerated.packages/cli/cli/changes/unreleased/.Testing
packages/cli/**package tests pass locally (162 turbo tasks, excluding ete which needs a built CLI).Link to Devin session: https://app.devin.ai/sessions/a8d6b5bbe5bf499ab4137b2172d4f5df
Open in Devin Desktop: https://app.devin.ai/desktop/session/a8d6b5bbe5bf499ab4137b2172d4f5df?variant=devin
Requested by: @willkendall01