Skip to content

Commit

Permalink
Fix model fields READ-ONLY comment (#1392)
Browse files Browse the repository at this point in the history
Model fields are read-only if the only visibility decorator set is Read.
  • Loading branch information
jhendrixMSFT authored Jun 18, 2024
1 parent b686c51 commit 0d3ce80
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
12 changes: 6 additions & 6 deletions packages/typespec-go/src/tcgcadapter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class typeAdapter {
if (prop.kind !== 'path' && prop.kind !== 'property') {
throw new Error(`unexpected kind ${prop.kind} for property ${prop.name} in model ${modelType.name}`);
}
const annotations = new go.ModelFieldAnnotations(prop.optional == false, false, false, false);
const annotations = new go.ModelFieldAnnotations(prop.optional === false, false, false, false);
// for multipart/form data containing models, default to fields not being pointer-to-type as we
// don't have to deal with JSON patch shenanigans. only the optional fields will be pointer-to-type.
const isMultipartFormData = (modelType.usage & tcgc.UsageFlags.MultipartFormData) === tcgc.UsageFlags.MultipartFormData;
Expand All @@ -579,11 +579,11 @@ export class typeAdapter {
type = this.getMultipartContent(prop.type.kind === 'array');
}
if (prop.visibility) {
for (const vis of prop.visibility) {
if (vis === http.Visibility.Read) {
annotations.readOnly = true;
break;
}
// the field is read-only IFF the only visibility attribute present is Read.
// a field can have Read & Create set which means it's required on input and
// returned on output.
if (prop.visibility.length === 1 && prop.visibility[0] === http.Visibility.Read) {
annotations.readOnly = true;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-go/test/armapicenter/zz_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/typespec-go/test/armcodesigning/zz_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions packages/typespec-go/test/armcommunitymanagement/zz_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/typespec-go/test/armdatabasewatcher/zz_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/typespec-go/test/armlargeinstance/zz_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/typespec-go/test/armloadtestservice/zz_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d3ce80

Please sign in to comment.