Repository navigation
fix(typespec-ts): make read-only request model properties optional - #5622
Open
Glenn Harper (glharper) wants to merge 1 commit into
Open
Glenn Harper (glharper) wants to merge 1 commit into
Glenn Harper (glharper) wants to merge 1 commit into
Conversation
Fixes Azure#5621. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 40bd2bb4-54cf-4b12-b492-b278172dd8c7
Contributor
|
All changed packages have been documented.
Show changes
|
Contributor
📦 Package size report✅ No notable package size changes compared to the base branch. 14 package(s) with no notable change
Packed = gzipped |
commit: |
Contributor
|
You can try these changes here
|
This branch has not been deployed
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.
Fixes #5621.
Summary
The default emitter shares model interfaces between requests and responses, but currently emits required
@visibility(Lifecycle.Read)properties as required TypeScript fields even on request-used models. This forces callers to supply fields that the request serializers omit, including fields on nested models.Use one optionality helper for named interfaces and inline model expressions. Read-only properties become optional only when the containing model has
UsageFlags.Inputand experimental visibility splitting is disabled. Writable required properties, response-only models, and the opt-in split-model response contracts remain unchanged. The SDK model metadata is not mutated, preserving serializer/deserializer behavior and nullable response values.Add regression coverage for the reported create-body example, arrays, dictionaries, nullable/union nesting, inheritance, cycles, inline models, response-only contracts, and visibility splitting. The reproduction also type-checks the generated TypeScript with a create payload that omits both top-level and nested read-only fields. Update two directly affected inherited/flattened model snapshots and add a package bug-fix change entry.
Validation
The regression tests were run against unmodified main first: six input/nesting assertions failed because read-only fields were required; the two preservation assertions passed. The inline-model regression separately failed before that emission path was fixed.
pnpm -r --filter "@azure-tools/typespec-ts..." build— passed.pnpm --filter @azure-tools/typespec-ts build— passed after the fix.pnpm exec vitest run --project unit-modular --maxWorkers=4(frompackages/typespec-ts) — passed: 744 tests in 49 files, including all ten new regression tests.pnpm test-next(frompackages/typespec-ts) — passed: 268 tests in 17 files.pnpm format— passed.pnpm lint— passed.pnpm exec prettier --check .chronus/changes/typespec-ts-optional-readonly-input.md packages/typespec-ts/src/modular/emit-models.ts packages/typespec-ts/src/modular/helpers/visibility-helpers.ts packages/typespec-ts/src/modular/type-expressions/get-model-expression.ts packages/typespec-ts/test/modular-unit/readonly-properties.test.ts packages/typespec-ts/test/modular-unit/scenarios/models/property-flatten/singleLayer.md— passed.Spector integration tests and the unrelated full-workspace test/build suites were not run.