Build models, properties and enums on the emitter framework - #11601
Build models, properties and enums on the emitter framework#11601Timothee Guerin (timotheeguerin) wants to merge 6 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.
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
The emitter shipped private forks of the framework's
ClassDeclaration,PropertyandEnumDeclaration— copies made because the framework offered no way to adjust them, which then drifted. With declaration overrides and component props now available (#11597, #11598), the forks go away and the divergences are expressed as configuration:virtual/override/new, error-model members, JSON attributes) becomes a registeredModelPropertydeclaration override.ServerClassDeclarationbecomesEfClassDeclarationwith an explicitpropertieslist and the generated constructors passed aschildren.Enumsrenders throughEfEnumDeclarationwith an explicitmemberslist, keeping the emitter's more permissive union-as-enum detection.models.tsxdrops from ~270 lines to ~125, and the whole change is a net -350 lines.One structural note for reviewers: the framework's
TypeExpressionrecurses into itself, not into a consumer's wrapper. Any type kind whose handling recurses into a contained type therefore has to stay in the emitter's wrapper or its divergences are silently lost for the nested type. Scalars are the exception — they go through component overrides, which apply at every level. This is now written down in a comment at the top of the wrapper, because it is not obvious and it caused a regression while writing this.Generated output is unchanged.
Part of a 7-PR stack moving
@typespec/http-server-csharponto the emitter framework. Stacked on #11600 — only the last commit is new here.