Skip to content

Skip convenience method generation for multipart/mixed requests#10967

Merged
jorgerangel-msft merged 5 commits into
mainfrom
copilot/skip-generating-convenience-methods-again
Jun 11, 2026
Merged

Skip convenience method generation for multipart/mixed requests#10967
jorgerangel-msft merged 5 commits into
mainfrom
copilot/skip-generating-convenience-methods-again

Conversation

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The C# emitter does not support multipart/mixed requests, yet since the addition of multipart/form-data support it would emit an incorrect convenience method for them. This disables convenience method generation for multipart content types other than multipart/form-data and surfaces a diagnostic instead.

The detection lives in the emitter so the generator simply honors the resulting generateConvenienceMethod flag.

Changes

  • operation-converter.ts: In fromSdkServiceMethodOperation, when an operation uses a multipart/* content type other than multipart/form-data, generateConvenienceMethod is set to false (protocol methods still emitted) and a warning diagnostic is reported. A small isUnsupportedMultipart helper inspects the request media types.
  • lib.ts: Added the unsupported-multipart-convenience-method warning diagnostic.
  • Tests: Added emitter unit tests in operation-converter.test.tsmultipart/mixed turns off convenience method generation and emits the warning, while multipart/form-data keeps convenience methods with no diagnostic.
const requestMediaTypes = getRequestMediaTypes(method.operation);
if (generateConvenience && isUnsupportedMultipart(requestMediaTypes)) {
  diagnostics.add(
    createDiagnostic({
      code: "unsupported-multipart-convenience-method",
      format: { methodCrossLanguageDefinitionId: method.crossLanguageDefinitionId },
      target: method.__raw ?? NoTarget,
    }),
  );
  generateConvenience = false;
}

No existing test specs use multipart/mixed, so generated library output is unchanged.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jun 11, 2026
Copilot AI changed the title [WIP] Disable generating convenience methods for multipart/mixed requests Skip convenience method generation for multipart/mixed requests Jun 11, 2026
Copilot AI requested a review from jorgerangel-msft June 11, 2026 18:13
@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10967

commit: a434666

@jorgerangel-msft jorgerangel-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot ensure we add proper unit tests for our changes

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

@jorgerangel-msft jorgerangel-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot ensure we are regenerating all test libraries

Comment thread packages/http-client-csharp/emitter/src/lib/operation-converter.ts Outdated
Comment thread packages/http-client-csharp/emitter/src/lib/operation-converter.ts
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ensure we add proper unit tests for our changes

Added emitter unit tests in operation-converter.test.ts: one verifies multipart/mixed turns off generateConvenienceMethod and emits the unsupported-multipart-convenience-method warning, and another verifies multipart/form-data keeps convenience methods with no diagnostic.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ensure we are regenerating all test libraries

Ran eng/scripts/Generate.ps1 to regenerate all test libraries. No generated output changed since no test specs use multipart/mixed.

@jorgerangel-msft jorgerangel-msft added this pull request to the merge queue Jun 11, 2026
Merged via the queue into main with commit 7d060ec Jun 11, 2026
29 checks passed
@jorgerangel-msft jorgerangel-msft deleted the copilot/skip-generating-convenience-methods-again branch June 11, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants