fix(http-server-csharp): only emit types that belong to the service - #11520
Draft
timotheeguerin wants to merge 2 commits into
Draft
fix(http-server-csharp): only emit types that belong to the service#11520timotheeguerin wants to merge 2 commits into
timotheeguerin wants to merge 2 commits into
Conversation
Types declared outside the service namespace are now emitted only when the service references them, directly or transitively, instead of emitting every model, enum and union declared by imported libraries.
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The emitter generated a class for every model, enum and union it could reach from the global namespace, including all the declarations of any imported library, whether or not the service used them. On a spec built on a few library templates that meant dozens of dead C# classes, plus
anonymous-modelwarnings pointing at library files the spec author cannot change.Emission is now anchored on the service: declarations of the service namespace(s) are always emitted, and anything declared elsewhere is emitted only when the service references it, directly or transitively (operations, properties, base models, template arguments, union variants, array/record element types). Diagnostics follow the same rule, so warnings only point at the spec's own types.
On a sample spec using library templates this drops the generated models from 63 to 34 and the warnings from 5 to 0, with no unresolved type references in the generated project.
Two related gaps are fixed along the way: enums and unions are now discovered through references (previously only through a namespace walk), and
Record<T>value types are traversed.Specs that declare no
@servicekeep the previous behavior, since there is nothing to anchor the emit on.