PoC: visibility-based model splitting in typespec-ts emitter - #5081
Draft
JialinHuang803 wants to merge 3 commits into
Draft
PoC: visibility-based model splitting in typespec-ts emitter#5081JialinHuang803 wants to merge 3 commits into
JialinHuang803 wants to merge 3 commits into
Conversation
Adds an experimental, flag-gated (experimental-split-models-by-visibility, default OFF) emitter pre-pass that projects request-body models to their write visibility so read-only properties (e.g. required @visibility(Lifecycle.Read) ARM props) no longer leak into generated input types. Implemented entirely in the JS emitter (src/modular/helpers/visibility-helpers.ts), with no TCGC changes beyond the public SdkModelType shape and the stable @typespec/http visibility helpers. Includes runnable scenarios 01-03 (split, collapse, nested propagation, name collision) with generated output. Tests are intentionally excluded from this draft PoC. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 742ec718-6a39-4e6d-bf72-74d80f6a2b9e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 742ec718-6a39-4e6d-bf72-74d80f6a2b9e
commit: |
Contributor
|
❌ There is undocummented changes. Run The following packages have changes but are not documented.
Show changes |
Contributor
|
You can try these changes here
|
Route any model in a discriminated hierarchy (base or a subtype reached directly) through the discriminator root so the whole subtype tree is projected together and cached once. This fixes the unresolved polymorphic placeholder in write bodies and prevents a subtype used directly (e.g. a Cat body) from producing a duplicate CatCreate. Add scenario 04-discriminated-polymorphic (with a subtype-first createCat operation) and document it in the design doc Scenarios section. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 742ec718-6a39-4e6d-bf72-74d80f6a2b9e
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.
PoC: visibility-based model splitting in
typespec-tsExperimental, flag-gated emitter feature that prevents read-only properties (e.g. required
@visibility(Lifecycle.Read)ARM props likeid/name) from leaking into generated input types. When enabled, a request-body model is projected to its write view (WidgetCreate,WidgetCreateOrUpdate, ...) while responses keep the full read model.Tracks #4710.
Design
src/modular/helpers/visibility-helpers.ts— no TCGC changes beyond the publicSdkModelTypeshape and the stable@typespec/httpvisibility helpers (resolveRequestVisibility,createMetadataInfo,getVisibilitySuffix).applyVisibilityModelSplit) right beforevisitPackageTypes, so the repointed graph is what gets emitted.experimental-split-models-by-visibility(default OFF).packages/typespec-ts/design/visibility-model-split-design.md.Included scenarios (
visibility-scenarios/)Runnable projects (spec +
tspconfig.yaml+ generated code) to eyeball output:WidgetCreate) plus a no-read-only model that collapses to itself (Gadget, shared request/response, no rename).ACreateOrUpdate+BCreateOrUpdate) and nested-change propagation (CCreatesynthesized purely because nestedDmust change).WidgetCreatecollides with a synthesized one; binder falls back to positionalWidgetCreate_1(open question).Notes