Skip to content

Commit 0f2498f

Browse files
authored
Flattened property should honor readability of internal property (Azure#51572)
* Flattend property should honor readability of inernal property * regen * add comment
1 parent f032564 commit 0f2498f

File tree

10 files changed

+24
-29
lines changed

10 files changed

+24
-29
lines changed

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Visitors/SafeFlattenVisitor.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,20 @@ internal class SafeFlattenVisitor : ScmLibraryVisitor
4747
internalizedProperties.Add(internalSingleProperty);
4848

4949
// flatten the single property to public and associate it with the internal property
50-
var flattenPropertyName = $"{singleProperty.Name}"; // TODO: handle name conflicts
50+
var flattenPropertyName = $"{internalSingleProperty.Name}{singleProperty.Name}"; // TODO: handle name conflicts
5151
var checkNullExpression = This.Property(internalSingleProperty.Name).Is(Null);
52-
var flattenPropertyBody = new MethodPropertyBody(
53-
Return(new TernaryConditionalExpression(checkNullExpression, Default, new MemberExpression(internalSingleProperty, singleProperty.Name))),
54-
new List<MethodBodyStatement>
52+
MethodBodyStatement setter = new List<MethodBodyStatement>
5553
{
5654
new IfStatement(checkNullExpression)
5755
{
5856
internalSingleProperty.Assign(New.Instance(propertyTypeProvider.Type!)).Terminate()
5957
},
6058
This.Property(internalSingleProperty.Name).Property(singleProperty.Name).Assign(Value).Terminate()
61-
});
59+
};
60+
var flattenPropertyBody = new MethodPropertyBody(
61+
Return(new TernaryConditionalExpression(checkNullExpression, Default, new MemberExpression(internalSingleProperty, singleProperty.Name))),
62+
singleProperty.Body?.HasSetter == true ? setter : null // only add setter for flattend property if the internal property has a setter
63+
);
6264
var flattenedProperty = new PropertyProvider(singleProperty.Description, singleProperty.Modifiers, singleProperty.Type, flattenPropertyName, flattenPropertyBody, type, singleProperty.ExplicitInterface, singleProperty.WireInfo, singleProperty.Attributes);
6365
flattenedProperties.Add(flattenedProperty);
6466
flattenedPropertyMap.Add(internalSingleProperty.Type, flattenedProperty);

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/bar.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ model BarSettings is ProxyResource<BarSettingsProperties> {
5252

5353
model BarSettingsProperties {
5454
/** enabled */
55+
@visibility(Lifecycle.Read)
5556
isEnabled?: boolean;
5657
}
5758

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/BarSettingsData.cs

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecModelFactory.cs

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/BarSettingsProperties.Serialization.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/BarSettingsProperties.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooSettingsPatch.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ZooPatch.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/ZooData.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4175,7 +4175,7 @@
41754175
"decorators": []
41764176
},
41774177
"optional": true,
4178-
"readOnly": false,
4178+
"readOnly": true,
41794179
"discriminator": false,
41804180
"flatten": false,
41814181
"decorators": [],

0 commit comments

Comments
 (0)