microsoft / microsoft/typespec

AdditionalProperties property type should be based on the visibility rather than the usage

Open
#7,387 6 comments 0 reactions 1 assignee Claimed by @JoshLove-msft View on GitHub
emitter:client:csharp
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

If an InputModel is only used for Output, all of its properties should be readonly.

The below anonymous model is only used for Output
https://github.com/microsoft/typespec/blob/fdefc060e7ee20ccee94143872baa1d7dd50176c/docs/samples/client/csharp/SampleService/main.tsp#L406C4-L411
```
op ListWithNextLink(): {
@pageItems
things: Thing[];

@nextLink next?: url;
};
```
The usage is correct in [tspCodeModel.json](https://github.com/microsoft/typespec/blob/fdefc060e7ee20ccee94143872baa1d7dd50176c/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/tspCodeModel.json#L2796-L2799)

But the generated SDK is not readonly, it should be IReadOnlyList
https://github.com/microsoft/typespec/blob/fdefc060e7ee20ccee94143872baa1d7dd50176c/docs/samples/client/csharp/SampleService/SampleClient/src/Generated/Models/ListWithNextLinkResponse.cs#L36

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.