Skip to content

Commit 9151a2e

Browse files
Refine doc of resource data (#3167)
* include the original description for resource data * update the doc * regenerate * resolve comments * update shared code
1 parent 67bb7c1 commit 9151a2e

File tree

134 files changed

+653
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+653
-195
lines changed

docs/mgmt/polishing.md

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ To rename a type (models and enumerations included), you could just use this syn
112112
rename-mapping:
113113
OriginalName: NewName
114114
```
115-
where the `OriginalName` is the original name of this model in the swagger. **Please be sure the name is its original swagger name**, because our generator will dynamically change names of some models from their context and roles inside the SDK.
115+
where the `OriginalName` is the original name of this model in the swagger. **Please be sure the name is its original swagger name**, because our generator will dynamically change names of some models from their context and roles inside the SDK. About how to get their original name of a model, please refer to [`How to get original name` section](#how-to-get-original-name).
116116

117117
After applying this configuration, you will see the following changes:
118118
```diff
@@ -130,7 +130,7 @@ To rename a property in a class, you could just use this syntax:
130130
rename-mapping:
131131
Model.oldProperty: NewProperty
132132
```
133-
where the `Model` is the original name of this model in the **swagger**, and the `oldProperty` is its original name of this property in the **swagger**.
133+
where the `Model` is the original name of this model in the **swagger**, and the `oldProperty` is its original name of this property in the **swagger**. About how to get their original name of a property in model, please refer to [`How to get original name` section](#how-to-get-original-name).
134134

135135
After applying this configuration, you will see the following changes:
136136
```diff
@@ -145,51 +145,6 @@ public partial class Model
145145
}
146146
```
147147

148-
It is special that some properties might be "flattened" from another model into this property. When this happens, you will have to include a full path of the property to make sure that the generator could precisely locate the property. For instance, we might have this inside our swagger:
149-
```json
150-
"definitions": {
151-
"Model": {
152-
"type": "object",
153-
"properties": {
154-
"properties": {
155-
"$ref": "#definitions/ModelProperties",
156-
"x-ms-client-flatten": true
157-
}
158-
}
159-
},
160-
"ModelProperties": {
161-
"type": "object",
162-
"properties": {
163-
"flattenedProperty": {
164-
"type": "string"
165-
}
166-
}
167-
}
168-
}
169-
```
170-
This piece of swagger will generate into the following code:
171-
```csharp
172-
public partial class Model
173-
{
174-
/* constructors */
175-
public string FlattenedProperty { get; set; }
176-
}
177-
```
178-
The model `ModelProperties` will disappear in our generated code, and the properties inside `ModelProperties` will be promoted into the owner class. In case the name of this property needs to be changed, you will have to use the following configuration:
179-
```yaml
180-
rename-mapping:
181-
Model.properties.flattenedProperty: NewFlattenedProperty
182-
```
183-
After applying this configuration, you will see the following changes:
184-
```diff
185-
public partial class Model
186-
{
187-
/* constructors */
188-
- public string FlattenedProperty { get; set; }
189-
+ public string NewFlattenedProperty { get; set; }
190-
}
191-
```
192-
193148
### Change the format of a property
194149

195150
To assign a new format to a property, you could use this syntax:
@@ -217,14 +172,71 @@ rename-mapping:
217172
```
218173
Please note that the dash and slash `-|` here are mandatory as a placeholder for the property name. The generator uses this symbol to separate the part for property name and its format.
219174

175+
About how to get their original name of a property in model, please refer to [`How to get original name` section](#how-to-get-original-name).
176+
220177
### Rename an enumeration value in an enumeration type
221178

222179
The generator regards the enumeration values as static properties, therefore you could use basically the same syntax as renaming a property to rename an enumeration value:
223180
```yaml
224181
rename-mapping:
225182
EnumType.enum_value: NewValue
226183
```
227-
where the `EnumType` is the original name of the enumeration type in the **swagger**, and `enum_value` is the original name of the enumeration value in the **swagger**. In case we have spaces or other special character, you might need to use quotes to enclosing the key in this mapping to ensure everything is good without compile errors.
184+
where the `EnumType` is the original name of the enumeration type in the **swagger**, and `enum_value` is the original name of the enumeration value in the **swagger**. In case we have spaces or other special character, you might need to use quotes to enclosing the key in this mapping to ensure everything is good without compile errors. About how to get their original name of enum classes or enum values, please refer to [`How to get original name` section](#how-to-get-original-name).
185+
186+
### How to get original name
187+
188+
The `rename-mapping` configuration requires an "original name" as its key to rename an element (model name, property name, enum name, enum value name or format of a property) in the generated SDK. We have a debug flag to show the original names of those elements that support to rename.
189+
190+
Add the following configuration to your `autorest.md` and regenerate the SDK:
191+
```yaml
192+
mgmt-debug:
193+
show-serialized-names: true
194+
```
195+
You will see changes like this:
196+
```diff
197+
/// <summary>
198+
/// A class representing the Image data model.
199+
/// The source user image virtual hard disk. The virtual hard disk will be copied before being attached to the virtual machine. If SourceImage is provided, the destination virtual hard drive must not exist.
200+
+ /// Serialized Name: Image
201+
/// </summary>
202+
public partial class ImageData : TrackedResourceData
203+
```
204+
or on a property:
205+
```diff
206+
/// <summary>
207+
/// Specifies the storage settings for the virtual machine disks.
208+
+ /// Serialized Name: Image.properties.storageProfile
209+
/// </summary>
210+
public ImageStorageProfile StorageProfile { get; set; }
211+
```
212+
or on an enum and its values:
213+
```diff
214+
/// <summary>
215+
/// Specifies the caching requirements. &lt;br&gt;&lt;br&gt; Possible values are: &lt;br&gt;&lt;br&gt; **None** &lt;br&gt;&lt;br&gt; **ReadOnly** &lt;br&gt;&lt;br&gt; **ReadWrite** &lt;br&gt;&lt;br&gt; Default: **None for Standard storage. ReadOnly for Premium storage**
216+
+ /// Serialized Name: CachingTypes
217+
/// </summary>
218+
public enum CachingType
219+
{
220+
/// <summary>
221+
/// None
222+
+ /// Serialized Name: CachingTypes.None
223+
/// </summary>
224+
None,
225+
/// <summary>
226+
/// ReadOnly
227+
+ /// Serialized Name: CachingTypes.ReadOnly
228+
/// </summary>
229+
ReadOnly,
230+
/// <summary>
231+
/// ReadWrite
232+
+ /// Serialized Name: CachingTypes.ReadWrite
233+
/// </summary>
234+
ReadWrite
235+
}
236+
```
237+
The content after `Serialized Name:` is the "original name" you would like to use as keys in `rename-mapping`.
238+
239+
Because this configuration adds quite a few extra content to the xml documents, it is not recommended to have this flag on an official SDK, be sure to remove the configuration and regenerate the SDK after all the rename work is done.
228240

229241
## Rename a parameter in an operation
230242

samples/Azure.Management.Storage/Generated/BlobContainerData.cs

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

samples/Azure.Management.Storage/Generated/BlobInventoryPolicyData.cs

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

samples/Azure.Management.Storage/Generated/BlobServiceData.cs

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

samples/Azure.Management.Storage/Generated/DeletedAccountData.cs

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

samples/Azure.Management.Storage/Generated/EncryptionScopeData.cs

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

samples/Azure.Management.Storage/Generated/FileServiceData.cs

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

samples/Azure.Management.Storage/Generated/FileShareData.cs

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

samples/Azure.Management.Storage/Generated/ImmutabilityPolicyData.cs

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

samples/Azure.Management.Storage/Generated/ManagementPolicyData.cs

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

0 commit comments

Comments
 (0)