Skip to content

Commit 8a7b077

Browse files
committed
Took care of review comments for documentation and added a few more
scenarios to the attributes and accompanying tests.
1 parent edf75ae commit 8a7b077

11 files changed

+261
-33
lines changed

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ For the Storage data plane project, this change log is located at `src\Storage\C
117117

118118
#### Breaking Changes
119119

120-
Breaking changes should **not** be introduced into the repository without giving customers at least six months notice. For a description of breaking changes in Azure PowerShell, see [here](documentation/breaking-changes/breaking-changes-definition.md).
120+
Breaking changes should **not** be introduced into the repository without giving customers at least six months notice. For a description of breaking changes in Azure PowerShell and how to declare them in the code using the [various breaking change attributes](documentation/breaking-changes/breaking-changes-attribute-help.md), see [here](documentation/breaking-changes/breaking-changes-definition.md).
121121

122122
Whenever a service team announces a breaking change, they must add it to the `upcoming-breaking-changes.md` file in their respective service folder. When the service team is ready to release the module with the breaking change, they must move the corresponding information from `upcoming-breaking-changes.md` into the `current-breaking-changes.md` file located in their service folder.
123123

Diff for: documentation/breaking-changes/breaking-changes-attribute-help.md

+90-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Breaking Changes Attribute Help
22

3-
Below are descriptionsof the various types of Breaking Change Attributes (custom attributes) that can be used to decorate the cmdlet or its paramters to call out various [types of deprecations](https://github.com/praries880/azure-powershell/blob/breakingchangeattribute/documentation/breaking-changes/breaking-changes-definition.md).
3+
Below is description of the various types of Breaking Change Attributes (custom attributes) that can be used to decorate the cmdlet or its paramters to call out various [types of breaking changes](https://github.com/praries880/azure-powershell/blob/breakingchangeattribute/documentation/breaking-changes/breaking-changes-definition.md).
44

55
## The different types of attributes
66

@@ -41,6 +41,24 @@ NOTE :
4141
- The only time you will see the output (at runtime) of an attribute applied to a parameter (property or field) is if the parameter is actually invoked on the cmdline. The breaking change attributes to all parameters that are not invoked are ignored.
4242

4343
### Examples (with GenericBreakingChangeAttribute)
44+
#### With a simple message
45+
```cs
46+
[GenericBreakingChange("Message 1")]
47+
[Cmdlet(VerbsCommon.Get, "SomeObject0"), OutputType(typeof(Foo))]
48+
class GetSomeObject0 : AzureRMCmdlet
49+
{
50+
51+
}
52+
```
53+
54+
##### Effects at runtime:
55+
```
56+
Get-SomeObject0 <parms here>
57+
...
58+
Breaking changes in the cmdlet : Get-SomeObject0
59+
- Message 1
60+
```
61+
4462
#### With "GenericBreakingChange"
4563
```cs
4664
[GenericBreakingChange("Message 1", "5.0.0.0")]
@@ -101,7 +119,7 @@ Cmdlet invocation changes :
101119

102120
#### With ChangeDescription property and multiple attributes in the cmdlet
103121
```cs
104-
[GenericBreakingChange("Message5"]
122+
[GenericBreakingChange("Message5")]
105123
[Cmdlet(VerbsCommon.Get, "SomeObjectD"), OutputType(typeof(Foo))]
106124
class GetSomeObjectD : AzureRMCmdlet
107125
//This is just as an example, to call out a param change we would not use the generic attribute. Use "CmdletParameterBreakingChangeMarker" instead
@@ -139,7 +157,7 @@ This attribute marks a cmdlet for deprecation.
139157
#### Constructor Arguments
140158
None, other than the two inherited from GenericBreakingChangeAttribute
141159

142-
#### When there is a replacement cmdlet for the one that is being deprecated :
160+
#### When there is a replacement cmdlet
143161
```cs
144162
[CmdletDeprecation(ReplacementCmdletName = "Get-SomeObjectC")]
145163
[Cmdlet(VerbsCommon.Get, "SomeObjectA"), OutputType(typeof(Foo))]
@@ -197,6 +215,26 @@ Note :
197215
- deprecatedCmdletOutputTypeName : String, represents the type of the existing output type,
198216
- The two inherited from GenericBreakingChangeAttribute
199217

218+
#### The output return type is being dropped
219+
```cs
220+
[CmdletOutputBreakingChange(typeof(Foo))]
221+
[Cmdlet(VerbsCommon.Get, "SomeObjectA"), OutputType(typeof(Foo))]
222+
public class GetSomeObjectA : AzureRMCmdlet
223+
{
224+
protected override void BeginProcessing()
225+
{
226+
// cmdlet logic
227+
}
228+
}
229+
```
230+
##### Effect at runtime
231+
```
232+
Get-SomeObjectA <parms here>
233+
...
234+
Breaking changes in the cmdlet : Get-SomeObjectA
235+
- The output type 'Foo' is being deprecated without a replacement.
236+
```
237+
200238
#### The output return type is changing
201239
```cs
202240
[CmdletOutputBreakingChange(typeof(List<Foo>), ReplacementCmdletOutputTypeName = "Dictionary<String, Foo>")]
@@ -305,6 +343,31 @@ NOTE :
305343
- nameOfParameterChanging : String, represents the name of the existing parameter,
306344
- The two inherited from GenericBreakingChangeAttribute
307345

346+
#### Generic change in a parameter
347+
```cs
348+
[Cmdlet(VerbsCommon.Get, "SomeObjectA0"), OutputType(typeof(Foo))]
349+
public class GetSomeObjectA0 : AzureRMCmdlet
350+
{
351+
public const String ChangeDesc = "Change description Foo bar";
352+
[CmdletParameterBreakingChange("Param1", ChangeDescription = ChangeDesc)]
353+
[Parameter(Mandatory = false)]
354+
public String Param1;
355+
protected override void BeginProcessing()
356+
{
357+
// cmdlet logic
358+
}
359+
}
360+
```
361+
362+
##### Effect at runtime
363+
```
364+
Get-SomeObjectA0 -Param1=...
365+
...
366+
Breaking changes in the cmdlet : Get-SomeObjectA0
367+
- The parameter 'Param1' is changing
368+
Change description : Change description Foo bar
369+
```
370+
308371
#### A Parameter is being deprecated
309372
```cs
310373
[Cmdlet(VerbsCommon.Get, "SomeObjectA"), OutputType(typeof(Foo))]
@@ -330,6 +393,30 @@ Breaking changes in the cmdlet : Get-SomeObjectA
330393
Change description : Parameter is being deprecated without being replaced
331394
```
332395

396+
#### A Parameter is changing its type
397+
```cs
398+
[Cmdlet(VerbsCommon.Get, "SomeObjectA1"), OutputType(typeof(Foo))]
399+
public class GetSomeObjectA1 : AzureRMCmdlet
400+
{
401+
[CmdletParameterBreakingChange("Param1", OldParameterType = typeof(String), NewParameterTypeName="FooBar")]
402+
[Parameter(Mandatory = false)]
403+
public String Param1;
404+
protected override void BeginProcessing()
405+
{
406+
// cmdlet logic
407+
}
408+
}
409+
```
410+
411+
##### Effect at runtime
412+
```
413+
Get-SomeObjectA1 -Param1=...
414+
...
415+
Breaking changes in the cmdlet : Get-SomeObjectA1
416+
- The parameter 'Param1' is changing
417+
The type of the parameter is changing from 'String' to 'FooBar'.
418+
```
419+
333420
#### A Parameter is being replaced
334421
```cs
335422
[Cmdlet(VerbsCommon.Get, "SomeObjectB"), OutputType(typeof(Foo))]
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
11
# Breaking Change Definition
22

3+
This document lists the various types of breaking changes and how to call them out in your code using the [breaking change attributes](./breaking-changes-attribute-help.md).
4+
35
Breaking changes in cmdlets are defined as follows:
46

57
## Cmdlets
68
- Removing a cmdlet
9+
- Use the breaking change attribute ["CmdletDeprecationAttribute"](./breaking-changes-attribute-help.md##cmdletdeprecationattribute), more specificallly the ["cmdlet deprecation without replacement"](./breaking-changes-attribute-help.md####when-there-is-no-replacement-cmdlet) option
710
- Changing a cmdlet name without an alias to the original name
11+
- Use the breaking change attribute ["CmdletDeprecationAttribute"](./breaking-changes-attribute-help.md##cmdletdeprecationattribute), more specificallly the ["cmdlet deprecation with replacement"](./breaking-changes-attribute-help.md####when-there-is-a-replacement-cmdlet) option
812
- Removing or changing a cmdlet alias
13+
- Use the generic breaking change attribute ["GenericBreakingChangeAttribute"](./breaking-changes-attribute-help.md###genericbreakingchangeattribute) with a [simple message](./breaking-changes-attribute-help.md####with-a-simple-message) calling out the alias that is being deprecated
914
- Removing a cmdlet attribute option (`SupportShouldProcess`, `SupportsPaging`)
15+
- Use the generic breaking change attribute ["GenericBreakingChangeAttribute"](./breaking-changes-attribute-help.md###genericbreakingchangeattribute) with a [simple message](./breaking-changes-attribute-help.md####with-a-simple-message) calling out the cmdlet attribute that is being removed
1016
- Breaking change in `OutputType` or removal of `OutputType` attribute
17+
- Use the cmdlet output type breaking change attribute ["CmdletOutputBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletoutputbreakingchangeattribute)
18+
- To call out the output type being changed use the above attribute [as described here](./breaking-changes-attribute-help.md####the-output-return-type-is-changing).
19+
- To deprecate an output type use the above attribute [as described here](./breaking-changes-attribute-help.md####the-output-return-type-is-being-dropped).
1120

1221
## Parameters
1322
- Removing a parameter
23+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####a-parameter-is-being-deprecated) to call out a parameter being removed.
1424
- Changing the name of a parameter without an alias to the original parameter name
25+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####a-parameter-is-being-replaced) to call out a parameter name change.
1526
- Breaking change in parameter type
27+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####a-parameter-is-changing-its-type) to call out a parameter name change.
1628
- Adding a required parameter to an existing parametrer set (adding new parameter sets or adding additional optional parameters is not a breaking change)
29+
- An existing parameter becomes mandatry :
30+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####a-parameter-is-becoming-mandatory) to call out a parameter becoming mandatory.
31+
- Adding a new mandatory parameter to a parameter set:
32+
- Use the generic breaking change attribute ["GenericBreakingChangeAttribute"](./breaking-changes-attribute-help.md###genericbreakingchangeattribute) with a [custom message](./breaking-changes-attribute-help.md####with-a-simple-message) calling out the new mandatiry parameter that is going to be added to the parameter set.
1733
- Changing parameter order for parameter sets with ordered parameters
34+
- Use the generic breaking change attribute ["GenericBreakingChangeAttribute"](./breaking-changes-attribute-help.md###genericbreakingchangeattribute) with a [custom message](./breaking-changes-attribute-help.md####with-a-simple-message) calling out the new order in the parameter set.
1835
- Removing or changing a parameter alias
36+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change by altering the change description.
1937
- Removing or changing existing parameter attribute values
38+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change by altering the change description.
2039
- Making parameter validation more exclusive (_e.g.,_ removing values from a `ValidateSet`)
40+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change by altering the change description.
2141

2242
## Output and Parameter Types
2343
- Changing property names without an accompanying alias to the original name
44+
- In the output type
45+
- Use the cmdlet output type breaking change attribute ["CmdletOutputBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletoutputbreakingchangeattribute) [as follows](./breaking-changes-attribute-help.md####a-mixed-example) to call out property name changes (do not specify the attribute property "ReplacementCmdletOutputTypeName" for this purpose).
46+
- In a parameter
47+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change.
2448
- Removing properties
49+
- In the output type
50+
- Use the cmdlet output type breaking change attribute ["CmdletOutputBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletoutputbreakingchangeattribute) [as follows](./breaking-changes-attribute-help.md####a-few-properties-in-the-output-type-are-being-deprecated) to call out derecated properties.
51+
- In a parameter
52+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change.
2553
- Adding additional required properties
54+
- In the output type
55+
- Use the cmdlet output type breaking change attribute ["CmdletOutputBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletoutputbreakingchangeattribute) [as follows](./breaking-changes-attribute-help.md####a-few-new-properties-are-bing-added-to-the-output-type) to call out derecated properties.
56+
- In a parameter
57+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change.
2658
- Adding required parameters, changing parameter names, or parameter types for methods or constructors
59+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change.
2760
- Changing return types of methods
61+
- Use the parameter breaking change attribute ["CmdletParameterBreakingChangeAttribute"](./breaking-changes-attribute-help.md##cmdletparameterbreakingchangeattribute) as [described here](./breaking-changes-attribute-help.md####generic-change-in-a-parameter) to call out the change.

Diff for: src/Common/Commands.Common/CustomAttributes.Test/AzureRMTestCmdletDefinitiona.cs

+18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ class AzureRMTestCmdletWithCmdletDeprecationMarkerAttributeAndDescription : Azur
5252
public const string Description = "CmdletA2 is being replaced by CmdletA21";
5353
}
5454

55+
[Cmdlet(VerbNameHolder.CmdletNameVerb, AzureRMTestCmdletWithCmdletWithOutputTypeDropped.CmdletName)]
56+
[OutputType(typeof(string))]
57+
[CmdletOutputBreakingChange(typeof(string))]
58+
class AzureRMTestCmdletWithCmdletWithOutputTypeDropped : AzureRMCmdlet
59+
{
60+
public const string CmdletName = "CmdletB0";
61+
}
62+
5563
[Cmdlet(VerbNameHolder.CmdletNameVerb, AzureRMTestCmdletWithCmdletWithOutputTypeChange.CmdletName)]
5664
[OutputType(typeof(string))]
5765
[CmdletOutputBreakingChange(typeof(string), "5.0.0.0", ReplacementCmdletOutputTypeName ="List<string>")]
@@ -87,6 +95,16 @@ class AzureRMTestCmdletWithDeprecatedParam
8795
public string Param1;
8896
}
8997

98+
[Cmdlet(VerbNameHolder.CmdletNameVerb, AzureRMTestCmdletWithParamTypeChange.CmdletName)]
99+
class AzureRMTestCmdletWithParamTypeChange
100+
{
101+
public const string CmdletName = "CmdletC1A";
102+
//This deprecation marker should not have the OldWay=x New way=y printed as New way is not specified
103+
[CmdletParameterBreakingChange("Param1", OldParamaterType = typeof(string), NewParameterTypeName = "List<string>")]
104+
[Parameter(Mandatory = false)]
105+
public string Param1;
106+
}
107+
90108
[Cmdlet(VerbNameHolder.CmdletNameVerb, AzureRMTestCmdletWithReplacedParam.CmdletName)]
91109
class AzureRMTestCmdletWithReplacedParam
92110
{

Diff for: src/Common/Commands.Common/CustomAttributes.Test/BreakingChangeAttributeTests.cs

+46
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ public void TestForCmdletDeprecationAttributeWithDescription()
9292
Assert.False(messages[0].Contains("powershell\r\n# Old"));
9393
}
9494

95+
[Fact]
96+
[Trait(Category.AcceptanceType, Category.CheckIn)]
97+
public void TestForCmdletOutputTypeDropped()
98+
{
99+
List<GenericBreakingChangeAttribute> attribs = BreakingChangeAttributeHelper.GetAllBreakingChangeAttributesInType(typeof(AzureRMTestCmdletWithCmdletWithOutputTypeDropped), null);
100+
101+
Assert.Equal(1, attribs.Count);
102+
Assert.False(attribs[0].ChangeInEfectByDateSet);
103+
Assert.False(attribs[0].DeprecateByVersionSet);
104+
105+
string pat = @"(The output type ')(.*)(' is being deprecated without a replacement.)";
106+
Regex reg = new Regex(pat, RegexOptions.IgnoreCase | RegexOptions.Singleline);
107+
List<string> messages = BreakingChangeAttributeHelper.GetBreakingChangeMessagesForType(typeof(AzureRMTestCmdletWithCmdletWithOutputTypeDropped));
108+
Assert.Equal(1, messages.Count);
109+
Assert.True(reg.IsMatch(messages[0]));
110+
Assert.True(messages[0].Contains(" - Cmdlet : '" + VerbNameHolder.CmdletNameVerb + "-" + AzureRMTestCmdletWithCmdletWithOutputTypeDropped.CmdletName));
111+
Assert.False(messages[0].Contains("This change will take effect on '"));
112+
Assert.False(messages[0].Contains("Change description : "));
113+
Assert.False(messages[0].Contains("The change is expected to take effect from the version"));
114+
Assert.False(messages[0].Contains("powershell\r\n# Old"));
115+
}
116+
95117
[Fact]
96118
[Trait(Category.AcceptanceType, Category.CheckIn)]
97119
public void TestForCmdletOutputTypeDeprecation()
@@ -181,6 +203,30 @@ public void TestForCmdletWithParamDeprecatedNoReplacement()
181203
Assert.True(messages[0].Contains("Change description : " + AzureRMTestCmdletWithDeprecatedParam.ChangeDesc));
182204
}
183205

206+
[Fact]
207+
[Trait(Category.AcceptanceType, Category.CheckIn)]
208+
public void TestForCmdletWithParamTypeChange()
209+
{
210+
List<GenericBreakingChangeAttribute> attribs = BreakingChangeAttributeHelper.GetAllBreakingChangeAttributesInType(typeof(AzureRMTestCmdletWithParamTypeChange), null);
211+
Assert.Equal(1, attribs.Count);
212+
Assert.False(attribs[0].ChangeInEfectByDateSet);
213+
Assert.False(attribs[0].DeprecateByVersionSet);
214+
215+
string pat = @"(The parameter : ')(.*)(' is changing)";
216+
string pat1 = @"(The type of the parameter is changing from ')(.*)(' to ')(.*)('.)";
217+
Regex reg = new Regex(pat, RegexOptions.IgnoreCase | RegexOptions.Singleline);
218+
Regex reg1 = new Regex(pat1, RegexOptions.IgnoreCase | RegexOptions.Singleline);
219+
List<string> messages = BreakingChangeAttributeHelper.GetBreakingChangeMessagesForType(typeof(AzureRMTestCmdletWithParamTypeChange));
220+
Assert.Equal(1, messages.Count);
221+
Assert.True(reg.IsMatch(messages[0]));
222+
Assert.True(reg1.IsMatch(messages[0]));
223+
Assert.True(messages[0].Contains(" - Cmdlet : '" + VerbNameHolder.CmdletNameVerb + "-" + AzureRMTestCmdletWithParamTypeChange.CmdletName));
224+
Assert.False(messages[0].Contains("This change will take effect on '"));
225+
Assert.False(messages[0].Contains("The change is expected to take effect from the version"));
226+
Assert.False(messages[0].Contains("powershell\r\n# Old"));
227+
Assert.False(messages[0].Contains("Change description : "));
228+
}
229+
184230
[Fact]
185231
[Trait(Category.AcceptanceType, Category.CheckIn)]
186232
public void TestForCmdletWithParamDeprecatedWithReplacement()

0 commit comments

Comments
 (0)