fix: resolve default values from emitter options JSON schema#9971
fix: resolve default values from emitter options JSON schema#9971
Conversation
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Merge latest main and reapply changes cleanly. Added useDefaults option to JSONSchemaValidatorOptions and enabled it for emitter option validation. Added tests for schema default values. Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
|
@copilot Please pull the latest and fix merge conflicts therre are far too many changes in this PR |
…th bytes in multipart body (#10046) - [x] Analyze root cause of "Duplicate type name" error for multipart union with bytes - [x] Fix `addUsagesInOperation` in `visibility-usage.ts` to traverse multipart body part types - [x] Add test case for union with bytes in multipart body - [x] Add changelog entry - [x] Build and test changes (all 2482 tests pass) - [x] Apply prettier formatting <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>OpenAPI emitter fails on union with bytes for multipart</issue_title> > <issue_description>The following definition > > ```tsp > import "@typespec/http"; > using Http; > > union CreateVideoMultipartBodyInputReference { > bytes, > ImageRefParam, > } > union ImageRefParam { > { > @maxlength(20971520) > image_url: url, > }, > { > file_id: string, > }, > } > model CreateVideoMultipartBody { > > input_reference?: HttpPart<CreateVideoMultipartBodyInputReference>; > } > > op createVideo( > @Header > contentType: "multipart/form-data", > > @multipartBody > body: CreateVideoMultipartBody, > ): void; > ``` > > Fails with this error message : Duplicate type name: 'CreateVideoMultipartBodyInputReference'. Check @FriendlyName decorators and overlap with types in TypeSpec or service namespace. > > Interestingly, if we replace bytes by string or something else, the emission starts working. I'd expect it to work with bytes as well. > </issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #10045 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Enable useDefaults in AJV for the emitter option validator so that default values defined in the JSON schema are applied to context.options. Fixes #8489
Remove files that were accidentally included via a merge commit. Only the emitter options defaults fix should be in this PR. Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Remove remaining C# generator files that were accidentally changed from the original branch merge. Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Pulled latest main and cleaned up the branch. Removed all unrelated files that were accidentally included via the merge commit. The PR diff is now just 4 files with 86 insertions (commits
Note: GitHub may still show some C# files in the diff because the PR's merge-base hasn't caught up to latest main yet, but those files are identical between the branch and main HEAD. |
|
@copilot Try to find a way to fix this issue without requiring a breaking change across all these tests |
The fix itself is minimal and non-breaking — only 4 files are actually changed:
No C# tests are modified by this fix. The C# and openapi3 files visible in GitHub's PR diff are artifacts from the merge history — they are byte-for-byte identical to current main at the branch tip. The I wasn't able to force-push a clean rebase through the available tooling. The branch may need a manual |
Minimal fix — only 4 files changed, no breaking changes to existing tests.
Changes Made
schema-validator.ts: AdduseDefaultsoption toJSONSchemaValidatorOptionsinterface and pass it through to AJV (+2 lines)library.ts: EnableuseDefaults: truewhen creating the emitter option validator (+1 line)emitter-options.test.ts: Add 3 test cases for schema defaults — applies defaults when no options provided, user values override defaults, and partial defaults for missing options (+76 lines)@typespec/compilerHow It Works
The fix enables AJV's built-in
useDefaultsoption specifically for the emitter option validator. When an emitter definesdefaultvalues in its JSON schema options, those defaults are now applied tocontext.optionsduring$onEmit. This is a non-breaking, additive change — existing emitters withoutdefaultvalues in their schemas are unaffected.Testing
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.