Context
All generated model properties use { get; set; } regardless of whether the type is an input model (caller constructs it) or an output model (service returns it). Azure SDK guidelines recommend { get; init; } for output-only model properties to prevent accidental mutation after deserialization.
Problem
// Current — all properties settable after construction
public class VisualizeResults
{
public string Body { get; set; }
public string BodyHtml { get; set; }
public string AttachmentContent { get; set; }
// ...
}
VisualizeResults is only ever returned by the service — callers never construct it. Allowing set; means callers can silently overwrite a deserialized value, which leads to subtle bugs and reduces the ability to reason about data provenance.
Proposed change
Use { get; init; } for properties on output-only model types:
public class VisualizeResults
{
[JsonPropertyName("body")]
public string Body { get; init; }
[JsonPropertyName("bodyHtml")]
public string BodyHtml { get; init; }
// ...
}
Input models (used as request bodies, e.g., QueryAndListSchema) keep { get; set; } for convenient object initializer syntax.
Scope
Generator template change — the CodefulSdkGenerator must distinguish input vs output types (based on whether the type appears as a method parameter or only as a return type) and emit init accordingly. The KustoModelFactory pattern already exists to support constructing output models in tests, so init setters are compatible with the existing test infrastructure.
Azure SDK guideline
Output model properties should be read-only after construction
Context
All generated model properties use
{ get; set; }regardless of whether the type is an input model (caller constructs it) or an output model (service returns it). Azure SDK guidelines recommend{ get; init; }for output-only model properties to prevent accidental mutation after deserialization.Problem
VisualizeResultsis only ever returned by the service — callers never construct it. Allowingset;means callers can silently overwrite a deserialized value, which leads to subtle bugs and reduces the ability to reason about data provenance.Proposed change
Use
{ get; init; }for properties on output-only model types:Input models (used as request bodies, e.g.,
QueryAndListSchema) keep{ get; set; }for convenient object initializer syntax.Scope
Generator template change — the
CodefulSdkGeneratormust distinguish input vs output types (based on whether the type appears as a method parameter or only as a return type) and emitinitaccordingly. TheKustoModelFactorypattern already exists to support constructing output models in tests, soinitsetters are compatible with the existing test infrastructure.Azure SDK guideline
Output model properties should be read-only after construction