Skip to content

Move model JSON usage setting out of the emitter#1243

Open
MaiLinhP wants to merge 1 commit into
mainfrom
MaiLinhP/json-usage-visitor
Open

Move model JSON usage setting out of the emitter#1243
MaiLinhP wants to merge 1 commit into
mainfrom
MaiLinhP/json-usage-visitor

Conversation

@MaiLinhP

@MaiLinhP MaiLinhP commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Addresses #1232

With the generator update to add InputModelType Update function, we can now move model JSON usage setting from the emitter to visitor. This ensures consistency of keeping all OpenAI customization in visitors.

Copilot AI review requested due to automatic review settings July 7, 2026 18:57

Copilot AI 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.

Pull request overview

Moves the “multipart form models should also be treated as JSON models” customization from the TypeSpec emitter into the C# generator visitor layer, aligning with the plugin’s pattern of keeping OpenAI-specific generation behavior in visitors.

Changes:

  • Update ModelSerializationVisitor to set InputModelTypeUsage.Json on multipart-form models via InputModelType.Update(...).
  • Remove the emitter-side CodeModel mutation callback that previously OR’ed UsageFlags.Json onto multipart-form models.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
codegen/generator/src/Visitors/ModelSerializationVisitor.cs Adds visitor-side usage update so multipart form models are treated as JSON for MRW/serialization generation.
codegen/emitter/src/emitter.ts Removes emitter-time model usage mutation callback; now delegates behavior to the generator visitors.
Comments suppressed due to low confidence (1)

codegen/emitter/src/emitter.ts:7

  • CodeModel is no longer referenced after removing the emitCodeModel callback, leaving an unused import that can break TypeScript builds when unused imports are treated as errors.
import {
    emitCodeModel,
    CodeModel,
    CSharpEmitterOptions
} from "@typespec/http-client-csharp";

Comment on lines +16 to +20
// Ensure multipart form data models also get JSON usage so that MRW serialization is generated.
if (model.Usage.HasFlag(InputModelTypeUsage.MultipartFormData) && !model.Usage.HasFlag(InputModelTypeUsage.Json))
{
model.Update(usage: model.Usage | InputModelTypeUsage.Json);
}
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.

2 participants