Generate the JSON converter helpers with the emitter framework - #11602
Generate the JSON converter helpers with the emitter framework#11602Timothee Guerin (timotheeguerin) wants to merge 7 commits into
Conversation
Adds handling for Tuple, StringTemplate, EnumMember, ModelProperty, UnionVariant, template parameters and the full Intrinsic set. An unsupported type now reports a diagnostic and falls back to `object` instead of throwing. Also fixes the C# components reporting a TypeScript diagnostic for unsupported scalars, and corrects the C# expressions emitted for the `null` and `never` intrinsics. Adds an `isCSharpValueType` util.
…al_ComponentOverrides The `declaration` descriptor existed but nothing dispatched to it, so an emitter could override how a type is referenced but not how it is declared. The C# `ClassDeclaration`, `Property` and `EnumDeclaration` now render through the override point.
ClassDeclaration takes an explicit property list and extra members, Property takes the full Alloy property prop set plus name/csharpType overrides, EnumDeclaration takes an explicit member list and jsonAttributes, and JsonConverter takes doc, access modifiers, extra members and an explicit csharpType.
…xt.Json symbols Deletes the emitter's own C# keyword table and its re-declaration of the System.Text.Json.Serialization attributes, both of which are provided by @alloy-js/csharp. Namespace segments colliding with BCL type names are still renamed, now via a dedicated getCSharpNamespaceName helper.
…ource of truth The emitter had three disagreeing scalar-to-C# name maps, so error model constructors declared parameters such as DateOnly, Uri and sbyte while the matching properties were DateTime, string and SByte - code that does not compile. NumericConstraintAttribute<T> had the same mismatch.
…he emitter framework Replaces the private forks of ClassDeclaration, Property and EnumDeclaration with the framework components, expressing the emitter's own behavior as a declaration override and component props. Generated output is unchanged.
…h the emitter framework TimeSpanDurationConverter, Base64UrlJsonConverter and the Unix epoch converters were raw string templates. Output is unchanged apart from an explicit `using System;` that was previously implicit via ImplicitUsings.
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
TimeSpanDurationConverter,Base64UrlJsonConverterand the two Unix epoch converters were emitted as raw string templates — no symbol resolution, nousingmanagement, hand-maintained indentation. They are now built from the framework'sJsonConvertercomponent, so the C# they reference is real symbols and Alloy owns the formatting.This is the last of the stack, so it is also where the only output drift lands. Three files gain an explicit
using System;(previously implicit via<ImplicitUsings>enable</ImplicitUsings>, so inert), and one method signature inUnixEpochDateTimeOffsetConverter.csis wrapped by Alloy's printer:Everything else in the snapshot is byte-identical.
Follow-up
The framework's
createJsonConverterResolveris deliberately not adopted here. It keys converters by exact(type, encoding, encodeType), while this emitter switches on the std base scalar and ignores@encodeentirely — so adopting it would change the wire format for specs using e.g.@encode(DurationKnownEncoding.seconds, int32). That is a real improvement (the emitter currently ignores that encoding) but it is a behavior change and belongs in its own PR with its own tests.Final PR of a 7-PR stack moving
@typespec/http-server-csharponto the emitter framework. Stacked on #11601 — only the last commit is new here.