You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Financials/Financials/readme.md
+24-1Lines changed: 24 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,9 +32,32 @@ title: $(service-name)
32
32
subject-prefix: ''
33
33
34
34
```
35
+
36
+
### Directives
37
+
38
+
> see https://github.com/Azure/autorest/blob/master/docs/powershell/directives.md
39
+
40
+
```yaml
41
+
directive:
42
+
# Modify generated .dictionary.cs model classes in Financials module.
43
+
- from: source-file-csharp
44
+
where: $
45
+
transform: >
46
+
if (!$documentPath.match(/generated%5Capi%5CModels%5CMicrosoftGraph\w*\d*.dictionary.cs/gm))
47
+
{
48
+
return $;
49
+
} else {
50
+
// Rename additionalProperties indexer name in Financials module from Item to EntityItem to avoid property name conflict. salesOrderLine has a property named item.
51
+
// See https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/using-indexers
52
+
let indexerRegex = /(^\s*)(public\s*global::System.Object this\[global::System.String index\]\s*{\W.*}$)/gm
// Pass exclusion properties to base classes during serialization.
379
+
let baseClassInitializerRegex = /(new\s*Microsoft.Graph.PowerShell.Models.MicrosoftGraph\w*\(\s*json\s*,\s*new\s*global::System.Collections.Generic.HashSet<string>\()(\){\W.*}\);)/gm
380
+
$ = $.replace(baseClassInitializerRegex, '$1(exclusions ?? new System.Collections.Generic.HashSet<string>())$2');
376
381
return $;
377
382
}
383
+
# Modify generated .cs model classes.
378
384
- from: source-file-csharp
379
385
where: $
380
386
transform: >
@@ -388,6 +394,24 @@ directive:
388
394
$ = $.replace(valuesPropertiesRegex, '$1$2 new $3');
389
395
}
390
396
397
+
// Add new modifier to 'additionalProperties' properties of classes that derive from an IAssociativeArray. See example https://regex101.com/r/hnX7xO/2.
398
+
let additionalPropertiesRegex = /(SerializedName\s*=\s*@"additionalProperties".*\s*.*)(\s*)(.*AdditionalProperties\s*{\s*get;\s*set;\s*})/gmi
399
+
if($.match(additionalPropertiesRegex)) {
400
+
$ = $.replace(additionalPropertiesRegex, '$1$2 new $3');
401
+
}
402
+
403
+
// Add new modifier to 'keys' properties of classes that derive from an IAssociativeArray. See example https://regex101.com/r/hnX7xO/2.
404
+
let keysRegex = /(SerializedName\s*=\s*@"keys".*\s*.*)(\s*)(.*Keys\s*{\s*get;\s*set;\s*})/gmi
405
+
if($.match(keysRegex)) {
406
+
$ = $.replace(keysRegex, '$1$2 new $3');
407
+
}
408
+
409
+
// Add new modifier to 'count' properties of classes that derive from an IAssociativeArray. See example https://regex101.com/r/hnX7xO/2.
410
+
let countRegex = /(SerializedName\s*=\s*@"count".*\s*.*)(\s*)(.*Count\s*{\s*get;\s*set;\s*})/gmi
411
+
if($.match(countRegex)) {
412
+
$ = $.replace(countRegex, '$1$2 new $3');
413
+
}
414
+
391
415
let regexPattern = /^\s*public\s*partial\s*class\s*MicrosoftGraph(?<EntityName>.*):$/gm;
392
416
let regexArray;
393
417
while ((regexArray = regexPattern.exec($)) !== null) {
@@ -404,29 +428,36 @@ directive:
404
428
}
405
429
return $;
406
430
}
407
-
#Override OnDefault to handle all success, 2xx responses, as success and not error.
431
+
#Modify generated .cs cmdlets.
408
432
- from: source-file-csharp
409
433
where: $
410
434
transform: >
411
435
if (!$documentPath.match(/generated%2Fcmdlets%2F\w*\d*.cs/gm))
412
436
{
413
437
return $;
414
438
} else {
439
+
// Initialize AdditionalProperties prop to a new Hashtable by default.
440
+
let additionalPropertiesPropRegex = /System.Collections.Hashtable\s*AdditionalProperties\s*{\s*get;\s*set;\s*}$/gmi
441
+
let newAdditionalPropertiesProp = "System.Collections.Hashtable AdditionalProperties { get; set; } = new System.Collections.Hashtable();"
0 commit comments