@azure-tools/typespec-providerhub-controller 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/generate.d.ts +13 -0
  3. package/dist/src/generate.d.ts.map +1 -0
  4. package/dist/src/generate.js +1592 -0
  5. package/dist/src/generate.js.map +1 -0
  6. package/dist/src/index.d.ts +3 -0
  7. package/dist/src/index.d.ts.map +1 -0
  8. package/dist/src/index.js +3 -0
  9. package/dist/src/index.js.map +1 -0
  10. package/dist/src/lib.d.ts +202 -0
  11. package/dist/src/lib.d.ts.map +1 -0
  12. package/dist/src/lib.js +143 -0
  13. package/dist/src/lib.js.map +1 -0
  14. package/dist/src/testing/index.d.ts +3 -0
  15. package/dist/src/testing/index.d.ts.map +1 -0
  16. package/dist/src/testing/index.js +29 -0
  17. package/dist/src/testing/index.js.map +1 -0
  18. package/package.json +74 -0
  19. package/readme.md +66 -0
  20. package/templates/liftr/closedEnum.sq +27 -0
  21. package/templates/liftr/model.sq +43 -0
  22. package/templates/liftr/openEnum.sq +34 -0
  23. package/templates/liftr/resourceControllerBase.sq +140 -0
  24. package/templates/liftr/serviceRoutingConstants.sq +35 -0
  25. package/templates/liftr/single/Operation.sq +40 -0
  26. package/templates/liftr/single/OperationAction.sq +31 -0
  27. package/templates/liftr/single/OperationControllerBase.sq +38 -0
  28. package/templates/liftr/single/OperationDisplay.sq +35 -0
  29. package/templates/liftr/single/OperationListResult.sq +17 -0
  30. package/templates/liftr/single/OperationOrigin.sq +31 -0
  31. package/templates/providerhub/closedEnum.sq +24 -0
  32. package/templates/providerhub/model.sq +103 -0
  33. package/templates/providerhub/modelCopy.sq +98 -0
  34. package/templates/providerhub/modelCopyExtension.sq +39 -0
  35. package/templates/providerhub/modelVersionComposite.sq +69 -0
  36. package/templates/providerhub/modelVersionStandard.sq +62 -0
  37. package/templates/providerhub/openEnum.sq +34 -0
  38. package/templates/providerhub/resourceController.sq +20 -0
  39. package/templates/providerhub/resourceControllerBase.Logger.sq +48 -0
  40. package/templates/providerhub/resourceControllerBase.sq +154 -0
  41. package/templates/providerhub/resourceProviderRegistration.sq +11 -0
  42. package/templates/providerhub/resourceRegistration.sq +27 -0
  43. package/templates/providerhub/serviceRoutingConstants.sq +38 -0
  44. package/templates/providerhub/single/OperationControllerBase.sq +52 -0
  45. package/templates/providerhub/versionCollection.sq +28 -0
  46. package/templates/providerhub/versionedContractResolver.sq +57 -0
  47. package/templates/providerhub/versionedSerializer.sq +38 -0
package/readme.md ADDED
@@ -0,0 +1,66 @@
1
+ # TypeSpec Service Code Generator for ProviderHub
2
+
3
+ The TypeSpec service code generator for ProviderHub creates an abstract UserRP implementation of specs using the typespec-providerhub extension. Code is generating using the ASP.NET MVC framework. This doc discusses the high-level design, challenges, and remaining work.
4
+
5
+ We recommend consuming this package through the [typespec-providerhub-templates](https://github.com/Azure/typespec-azure/tree/main/packages/typespec-providerhub-templates), which contains a full service implementation in ASP.Net Core MVC, and sets the appropriate configurations for swagger generation, hosting your service, RP and resource registration, and end-to-end testing in RPaaS OneBox.
6
+
7
+ ## Usage
8
+
9
+ Any TypeSpec spec defined with `@azure-tools/typespec-azure-resource-manager` can have server-side controller stub code generated by following these steps:
10
+
11
+ 1. Ensure `@azure-tools/typespec-providerhub-controller` is a `dependency` in your project's `package.json` file
12
+ 1. Ensure this line is in your main spec file's imports: `import "@azure-tools/typespec-providerhub-controller"`
13
+ 1. Run the following command in your project folder:
14
+
15
+ ```
16
+ tsp compile . --emit @azure-tools/typespec-providerhub-controller
17
+ ```
18
+
19
+ ### Emitter Options
20
+
21
+ Emitter options can be configured via the `tspconfig.yaml` configuration:
22
+
23
+ ```yaml
24
+ emitters:
25
+ '@azure-tools/typespec-providerhub-controller':
26
+ <optionName>: <value>
27
+
28
+
29
+ # For example
30
+ emitters:
31
+ '@azure-tools/typespec-providerhub-controller':
32
+ include-operation-controller: true
33
+ ```
34
+
35
+ or via the command line with
36
+
37
+ ```bash
38
+ --option "@azure-tools/typespec-providerhub-controller.<optionName>=<value>"
39
+
40
+ # For example
41
+ --option "@azure-tools/typespec-providerhub-controller.include-operation-controller=true"
42
+ ```
43
+
44
+ #### `output-dir`
45
+
46
+ Path where the service code will be generated. By default will use the compiler `output-dir`.
47
+
48
+ #### `include-operation-controller`
49
+
50
+ An `OperationController` will be generated to handle operation endpoint requests in your service. This is not enabled by default since most ProviderHub services will use the operation endpoint that is provided automatically by Azure Resource Manager.
51
+ **NOTE:** This is not usually needed for ProviderHub services.
52
+
53
+ #### `operation-polling-location`
54
+
55
+ Determines whether a tenant-level ("tenant") or subscription-level ("subscription") status monitor is used for long-running operations. By default, uses the tenant-level status monitor provided by RPaaS.
56
+
57
+ #### `registration-output-path`
58
+
59
+ When set to a valid path, generates provider and type registration documents to the specified path. These can be used to register your resource provider and your resource types with RPaaS, for later creation of your manifest.
60
+
61
+ #### `code-kind`
62
+
63
+ Type of generation:
64
+
65
+ - When set to `controller`, generates only controller code and assume that the model will be generated in separate process.
66
+ - When set to `model` , generates only model code and assume that the controller will be generated in separate process.
@@ -0,0 +1,27 @@
1
+ //-----------------------------------------------------------------------------
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ //-----------------------------------------------------------------------------
4
+
5
+ // <auto-generated />
6
+
7
+ using System;
8
+
9
+ namespace Microsoft.{{serviceName}}.Service.Models
10
+ {
11
+ {{#if isDefined(description) }}
12
+ /// <summary>
13
+ {{> renderComment content=description}}
14
+ /// </summary>
15
+ {{/if}}
16
+ public enum {{name}}
17
+ {
18
+ {{#each values}}
19
+ {{#if isDefined(description)}}
20
+ /// <summary>
21
+ {{> renderComment content=description}}
22
+ /// </summary>
23
+ {{/if}}
24
+ {{name}} = "{{#if isDefined(value)}}{{value}}{{else}}{{name}}"{{ #unless @last }},{{/unless}}
25
+ {{/each}}
26
+ }
27
+ }
@@ -0,0 +1,43 @@
1
+ //-----------------------------------------------------------------------------
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ //-----------------------------------------------------------------------------
4
+
5
+ // <auto-generated />
6
+
7
+ using System;
8
+ using System.Collections.Generic;
9
+ using Microsoft.TypeSpec.ProviderHub.Controller;
10
+ {{#if (hasConverter this)}}
11
+ using Newtonsoft.Json;
12
+ {{/if}}
13
+
14
+ namespace Microsoft.{{serviceName}}.Service.Models
15
+ {
16
+ {{#if description}}
17
+ /// <summary>
18
+ {{> renderComment content=description}}
19
+ /// </summary>
20
+ {{/if}}
21
+ public class {{name}}{{#if (or isDerivedType isImplementer)}} : {{#if baseClass}}{{baseClass.name}}{{#if baseClass.typeParameters}}<{{typeParamList baseClass}}>{{/if}}{{/if}}{{#if implements}}{{#if isDerivedType}}, {{/if}}{{join implements ", "}}{{/if}}{{/if}}
22
+ {
23
+ {{#each properties}}
24
+ {{#if description}}
25
+ /// <summary>
26
+ /// {{description}}
27
+ /// </summary>
28
+ {{/if}}
29
+ {{#if validations}}
30
+ {{#each validations}}
31
+ [{{name}}({{#each parameters}}{{#if (eq type "string")}}@"{{/if}}{{value}}{{#if (eq type "string")}}"{{/if}}{{#unless @last}}, {{/unless}}{{/each}})]
32
+ {{/each}}
33
+ {{/if}}
34
+ {{#if converters}}
35
+ {{#each converters}}
36
+ [JsonConverter(typeof({{name}}))]
37
+ {{/each}}
38
+ {{/if}}
39
+ public {{type.name}}{{#if type.typeParameters}}<{{typeParamList type}}>{{/if}} {{name}} { get; set; }{{#if default}} = {{default}};{{/if}}
40
+
41
+ {{/each}}
42
+ }
43
+ }
@@ -0,0 +1,34 @@
1
+ //-----------------------------------------------------------------------------
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ //-----------------------------------------------------------------------------
4
+
5
+ // <auto-generated />
6
+
7
+ namespace Microsoft.{{serviceName}}.Service.Models
8
+ {
9
+ {{#if description}}
10
+ /// <summary>
11
+ {{> renderComment content=description}}
12
+ /// </summary>
13
+ {{/if}}
14
+ public struct {{name}}
15
+ {
16
+ public static readonly {{name}} {{#each values as |value valueIndex|}}{{value.name}} = "{{#if value.value}}{{value.value}}{{else}}{{value.name}}{{/if}}"{{#if @last}};{{else}},{{/if}} {{/each}}
17
+
18
+ private readonly string _value;
19
+
20
+ public {{name}}(string value)
21
+ {
22
+ _value = value;
23
+ }
24
+
25
+ public override string ToString() =>
26
+ _value;
27
+
28
+ public static implicit operator string({{name}} objValue) =>
29
+ objValue.ToString();
30
+
31
+ public static implicit operator {{name}}(string other) =>
32
+ new {{name}}(other);
33
+ }
34
+ }
@@ -0,0 +1,140 @@
1
+ // <auto-generated />
2
+
3
+ {{#with this as |res|}}
4
+ using System;
5
+ using System.Net;
6
+ using System.Threading.Tasks;
7
+ using Microsoft.TypeSpec.ProviderHub.Controller;
8
+ using {{nameSpace}}.Service.Models;
9
+ using {{nameSpace}}.Service.Controllers;
10
+ using Microsoft.AspNetCore.Http;
11
+ using Microsoft.AspNetCore.Mvc;
12
+ using Microsoft.Extensions.Logging;
13
+
14
+ namespace {{nameSpace}}.Service
15
+ {
16
+ /// <summary>
17
+ /// Controller for user RP operations on the {{res.name}} resource.
18
+ /// </summary>
19
+ [ApiController]
20
+ public abstract class {{res.name}}ControllerBase : ControllerBase
21
+ {
22
+ protected readonly ILogger<{{res.name}}ControllerBase> _logger;
23
+
24
+ protected {{res.name}}ControllerBase(ILogger<{{res.name}}ControllerBase> logger)
25
+ {
26
+ _logger = logger;
27
+ }
28
+ {{#each operations as |operation operationIndex|}}
29
+
30
+ {{#if (getOperationAction operation)}}
31
+ {{#if (notCustomOp operation)}}
32
+ /// <summary>
33
+ /// Validate the request to {{getOperationAction operation}} the {{res.name}} resource.
34
+ /// </summary>
35
+ {{#each operation.parameters as |parameter index |}}
36
+ /// <param name="{{parameter.name}}">
37
+ {{> renderComment content=parameter.description}}
38
+ /// </param>
39
+ {{/each}}
40
+ /// <returns> A ValidationResponse indicating the validity of the {{getOperationAction operation}} request.</returns>
41
+ [HttpPost]
42
+ [Route({{res.serviceName}}ServiceRoutes.{{res.name}}Validate{{getOperationAction operation}})]
43
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ValidationResponse))]
44
+ public async Task<ValidationResponse> Validate{{getOperationAction operation}}Async({{decl operation}})
45
+ {
46
+ _logger.LogInformation($"Validate{{getOperationAction operation}}Async()");
47
+ {{#if (isDefined operation.requestParameter)}}
48
+ var modelValidation = ValidationHelpers.ValidateModel({{operation.requestParameter.name}});
49
+ if (modelValidation.IsValid)
50
+ {
51
+ modelValidation = await OnValidate{{getOperationAction operation}}Async({{call operation}});
52
+ }
53
+
54
+ {{else}}
55
+ var modelValidation = await OnValidate{{getOperationAction operation}}Async({{call operation}});
56
+ {{/if}}
57
+ return modelValidation;
58
+ }
59
+
60
+ {{/if}}
61
+ /// <summary>
62
+ /// {{getOperationAction operation}} the {{res.name}} resource.
63
+ /// </summary>
64
+ {{#each operation.parameters as |parameter index|}}
65
+ /// <param name="{{parameter.name}}">
66
+ {{> renderComment content=parameter.description}}
67
+ /// </param>
68
+ {{/each}}
69
+ /// <returns> The {{res.name}} resource.</returns>
70
+ [Http{{initialCaps operation.verb }}]
71
+ [Route({{res.serviceName}}ServiceRoutes.{{res.name}}Item{{#unless (notCustomOp operation)}}{{getOperationAction operation}}{{/unless}})]
72
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof({{operation.returnType}}))]
73
+ {{#if (or (eq (getOperationAction operation) "Create") (eq (getOperationAction operation) "Patch"))}}
74
+ [ProducesResponseType((int)HttpStatusCode.Created, Type = typeof({{operation.returnType}}))]
75
+ {{/if}}
76
+ {{#if (eqi operation.verb "DELETE")}}
77
+ [ProducesResponseType((int)HttpStatusCode.NoContent, Type = typeof({{operation.returnType}}))]
78
+ {{/if}}
79
+ public async Task<IActionResult> {{getOperationAction operation}}Async({{decl operation}})
80
+ {
81
+ _logger.LogInformation("{{getOperationAction operation}}Async()");
82
+ {{#if operation.requestParameter}}
83
+ {{operation.requestParameter.name}} = {{operation.requestParameter.name}} ?? throw new ArgumentNullException(nameof({{operation.requestParameter.name}}));
84
+
85
+ {{/if}}
86
+ if (Request == null)
87
+ {
88
+ _logger.LogError($"Http request is null");
89
+ return BadRequest("Http request is null");
90
+ }
91
+
92
+ return await On{{getOperationAction operation}}Async({{call operation }});
93
+
94
+ }
95
+
96
+ protected abstract Task<IActionResult> OnValidate{{getOperationAction operation}}Async({{decl operation}});
97
+
98
+ protected abstract Task<IActionResult> On{{getOperationAction operation}}Async({{decl operation}});
99
+
100
+ {{/if}}
101
+ {{/each}}
102
+ {{#if res.hasSubscriptionList}}
103
+ /// <summary>
104
+ /// List Organization resources in the specified subscription.
105
+ /// </summary>
106
+ /// <param name="subscriptionId"> The subscription id.</param>
107
+ /// <returns> The list of {{res.name}} Resources in the specified subscription.</returns>
108
+ [HttpGet]
109
+ [Route({{res.serviceName}}ServiceRoutes.{{res.name}}ListBySubscription)]
110
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof({{res.specificationListModelName}}))]
111
+ public Task<{{res.specificationListModelName}}> ListBySubscription(string subscriptionId)
112
+ {
113
+ _logger.LogInformation("ListBySubscriptionAsync()");
114
+ return OnListBySubscription(subscriptionId);
115
+ }
116
+
117
+ protected abstract Task<{{res.specificationListModelName}}> OnListBySubscription(string subscriptionId);
118
+
119
+ {{/if}}
120
+ {{#if res.hasResourceGroupList}}
121
+ /// <summary>
122
+ /// List {{res.name}} resources in the specified resource group.
123
+ /// </summary>
124
+ /// <param name="subscriptionId"> The subscription id.</param>
125
+ /// <param name="resourceGroupName"> The resource group name.</param>
126
+ /// <returns> The list of {{res.name}} Resources in the specified resource group.</returns>
127
+ [HttpGet]
128
+ [Route({{res.serviceName}}ServiceRoutes.{{res.name}}ListByResourceGroup)]
129
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof({{res.specificationListModelName}}))]
130
+ public Task<{{res.specificationListModelName}}> ListByResourceGroupAsync(string subscriptionId, string resourceGroupName)
131
+ {
132
+ _logger.LogInformation("ListByResourceGroupAsync()");
133
+ return OnListByResourceGroupAsync(subscriptionId, resourceGroupName);
134
+ }
135
+
136
+ protected abstract Task<{{res.specificationListModelName}}> OnListByResourceGroupAsync(string subscriptionId, string resourceGroupName);
137
+ {{/if}}
138
+ }
139
+ }
140
+ {{/with}}
@@ -0,0 +1,35 @@
1
+ // <auto-generated />
2
+
3
+ namespace {{nameSpace}}.Service.Controllers
4
+ {
5
+ public static class {{serviceName}}ServiceRoutes
6
+ {
7
+ {{#if includeOperationController}}
8
+ public const string ListOperations = "providers/{{nameSpace}}/operations";
9
+ {{/if}}
10
+ {{#each resources as |resource index |}}
11
+ public const string {{resource.name}}Item = "{{resource.itemPath}}";
12
+ {{#if resource.hasSubscriptionList}}
13
+ public const string {{resource.name}}ListBySubscription = "/subscriptions/{subscriptionId}/providers/{{resource.nameSpace}}/{{resource.serializedName}}";
14
+ {{/if}}
15
+ {{#if resource.hasResourceGroupList}}
16
+ public const string {{resource.name}}ListByResourceGroup = "/subscriptions/{subscriptionId}/resourceGroups{resourceGroupName}/providers/{{resource.nameSpace}}/{{resource.serializedName}}";
17
+ {{/if}}
18
+ {{#each resource.operations as | operation opIndex |}}
19
+ {{#if (eqi operation.verb "PUT")}}
20
+ public const string {{resource.name}}ValidateCreate = "{{resource.itemPath}}/validateCreate";
21
+ {{/if}}
22
+ {{#if (eqi operation.verb "PATCH")}}
23
+ public const string {{resource.name}}ValidatePatch = "{{resource.itemPath}}/validatePatch";
24
+ {{/if}}
25
+ {{#if (eqi operation.verb "DELETE")}}
26
+ public const string {{resource.name}}ValidateDelete = "{{resource.itemPath}}/validateDelete";
27
+ {{/if}}
28
+ {{#if (eqi operation.verb "POST")}}
29
+ public const string {{resource.name}}Validate{{operation.name}} = "{{resource.itemPath}}/validate{{initialCaps operation.subPath}}";
30
+ public const string {{resource.name}}Item{{operation.name}} = "{{resource.itemPath}}/{{operation.subPath}}";
31
+ {{/if}}
32
+ {{/each}}
33
+ {{/each}}
34
+ }
35
+ }
@@ -0,0 +1,40 @@
1
+ // <auto-generated />
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Threading.Tasks;
7
+
8
+ namespace Microsoft.{{serviceName}}.Service.Models
9
+ {
10
+ /// <summary>
11
+ /// Description of an RP Operation.
12
+ /// </summary>
13
+ public class Operation
14
+ {
15
+ /// <summary>
16
+ /// The name of the operation, as per Resource-Based Access Control (RBAC). Examples: \"Microsoft.Compute/virtualMachines/write\", \"Microsoft.Compute/virtualMachines/capture/action\
17
+ /// </summary>
18
+ public string Name { get; internal set; }
19
+
20
+ /// <summary>
21
+ /// Whether the operation applies to data-plane. This is \"true\" for data-plane operations and \"false\" for ARM/control-plane operations.
22
+ /// </summary>
23
+ public bool IsDataAction {get; internal set;}
24
+
25
+ /// <summary>
26
+ /// Localized display information for this particular operation.
27
+ /// </summary>
28
+ public OperationDisplay Display {get; internal set;}
29
+
30
+ /// <summary>
31
+ /// The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is \"user,system\"
32
+ /// </summary>
33
+ public OperationOrigin Origin {get; internal set;}
34
+
35
+ /// <summary>
36
+ /// Indicates the action type. \"Internal\" refers to actions that are for internal only APIs.
37
+ /// </summary>
38
+ public OperationAction ActionType {get; internal set;}
39
+ }
40
+ }
@@ -0,0 +1,31 @@
1
+ // <auto-generated />
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Threading.Tasks;
7
+
8
+ namespace Microsoft.{{serviceName}}.Service.Models
9
+ {
10
+ /// <summary>
11
+ /// Indicates the action type. \"Internal\" refers to actions that are for internal only APIs.
12
+ /// </summary>
13
+ public struct OperationAction
14
+ {
15
+ string _value;
16
+
17
+ public static readonly OperationAction Internal = "internal";
18
+ public OperationAction( string value)
19
+ {
20
+ _value = value;
21
+ }
22
+
23
+ public override string ToString()
24
+ {
25
+ return _value;
26
+ }
27
+
28
+ public static implicit operator string( OperationAction objValue) => objValue.ToString();
29
+ public static implicit operator OperationAction( string other) => new OperationAction(other);
30
+ }
31
+ }
@@ -0,0 +1,38 @@
1
+ // <auto-generated />
2
+
3
+ using Microsoft.AspNetCore.Http;
4
+ using Microsoft.AspNetCore.Mvc;
5
+ using Microsoft.Extensions.Logging;
6
+ using System.Threading.Tasks;
7
+ using {{nameSpace}}.Service.Models;
8
+ using {{nameSpace}}.Service.Controllers;
9
+ using System.Net;
10
+
11
+ namespace {{nameSpace}}.Service
12
+ {
13
+ public abstract class OperationControllerBase : Controller
14
+ {
15
+ internal readonly ILogger<OperationControllerBase> _logger;
16
+
17
+ public OperationControllerBase(ILogger<OperationControllerBase> logger)
18
+ {
19
+ _logger = logger;
20
+ }
21
+
22
+ /// <summary>
23
+ /// List all operations provided by {{nameSpace}}.
24
+ /// </summary>
25
+ /// <returns> The list of {{nameSpace}} operations.</returns>
26
+ [HttpGet]
27
+ [Route({{serviceName}}ServiceRoutes.ListOperations)]
28
+ [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(OperationListResult))]
29
+ public async Task<OperationListResult> ListOperationsAsync()
30
+ {
31
+ _logger.LogInformation("ListOperationsAsync()");
32
+ return await OnOperationListAsync(Request);
33
+ }
34
+
35
+ internal abstract Task<OperationListResult> OnOperationListAsync(HttpRequest request);
36
+
37
+ }
38
+ }
@@ -0,0 +1,35 @@
1
+ // <auto-generated />
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Threading.Tasks;
7
+
8
+ namespace Microsoft.{{serviceName}}.Service.Models
9
+ {
10
+ /// <summary>
11
+ /// Localized display information for this particular operation.
12
+ /// </summary>
13
+ public class OperationDisplay
14
+ {
15
+ /// <summary>
16
+ /// The localized friendly form of the resource provider name, e.g. \"Microsoft Monitoring Insights\" or \"Microsoft Compute\".
17
+ /// </summary>
18
+ public string Provider { get; internal set; }
19
+
20
+ /// <summary>
21
+ /// The localized friendly name of the resource type related to this operation. E.g. \"Virtual Machines\" or \"Job Schedule Collections\".
22
+ /// </summary>
23
+ public string Resource {get; internal set;}
24
+
25
+ /// <summary>
26
+ /// The concise, localized friendly name for the operation; suitable for dropdowns. E.g. \"Create or Update Virtual Machine\", \"Restart Virtual Machine\".
27
+ /// </summary>
28
+ public string Operation {get; internal set;}
29
+
30
+ /// <summary>
31
+ /// The short, localized friendly description of the operation; suitable for tool tips and detailed views.
32
+ /// </summary>
33
+ public string Description {get; internal set;}
34
+ }
35
+ }
@@ -0,0 +1,17 @@
1
+ // <auto-generated />
2
+
3
+ using Microsoft.TypeSpec.ProviderHub;
4
+ using System;
5
+ using System.Collections.Generic;
6
+ using System.Linq;
7
+ using System.Threading.Tasks;
8
+
9
+ namespace Microsoft.{{serviceName}}.Service.Models
10
+ {
11
+ /// <summary>
12
+ /// Paged list of RP operations.
13
+ /// </summary>
14
+ public class OperationListResult : Pageable<Operation>
15
+ {
16
+ }
17
+ }
@@ -0,0 +1,31 @@
1
+ // <auto-generated />
2
+
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Threading.Tasks;
7
+
8
+ namespace Microsoft.{{serviceName}}.Service.Models
9
+ {
10
+ /// <summary>
11
+ /// The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is \"user,system\".
12
+ /// </summary>
13
+ public struct OperationOrigin
14
+ {
15
+ string _value;
16
+
17
+ public static readonly OperationOrigin User = "user", System = "system", UserAndSystem = "user,system";
18
+ public OperationOrigin( string value)
19
+ {
20
+ _value = value;
21
+ }
22
+
23
+ public override string ToString()
24
+ {
25
+ return _value;
26
+ }
27
+
28
+ public static implicit operator string( OperationOrigin objValue) => objValue.ToString();
29
+ public static implicit operator OperationOrigin( string other) => new OperationOrigin(other);
30
+ }
31
+ }
@@ -0,0 +1,24 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ // <auto-generated />
5
+
6
+ namespace {{nameSpace}}.Service.Models
7
+ {
8
+ {{#if isDefined(description)}}
9
+ /// <summary>
10
+ {{> renderComment content=description}}
11
+ /// </summary>
12
+ {{/if}}
13
+ public enum {{name}}
14
+ {
15
+ {{#each values}}
16
+ {{#if isDefined(description)}}
17
+ /// <summary>
18
+ {{> renderComment content=description}}
19
+ /// </summary>
20
+ {{/if}}
21
+ {{name}} = "{{#if isDefined(value)}}{{value}}{{else}}{{name}}"{{#unless @last }},{{/unless}}
22
+ {{/each}}
23
+ }
24
+ }
@@ -0,0 +1,103 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ // <auto-generated />
5
+
6
+ using System;
7
+ using System.Collections.Generic;
8
+ using Newtonsoft.Json;
9
+ using Microsoft.TypeSpec.ProviderHub.Controller;
10
+ {{#if (and discriminatorInfo (ne discriminatorBaseType.namespace namespace))}}
11
+ using {{discriminatorBaseType.namespace}};
12
+ {{/if}}
13
+
14
+ namespace {{nameSpace}}.Service.Models
15
+ {
16
+ {{#if discriminatorInfo}}
17
+ [Discriminator(DiscriminatorPropertyName, DiscriminatorValue)]
18
+ [JsonConverter(typeof(DiscriminatorJsonConverter<{{discriminatorInfo.baseType.name}}>))]
19
+ {{/if}}
20
+ {{#if description}}
21
+ /// <summary>
22
+ {{> renderComment content=description}}
23
+ /// </summary>
24
+ {{/if}}
25
+ public {{#if discriminatorInfo}}{{#if (eq discriminatorInfo.value "")}}abstract {{/if}}{{/if}}partial class {{name}}{{#if (or isDerivedType isImplementer)}} : {{#if baseClass}}{{baseClass.name}}{{#if baseClass.typeParameters}}<{{typeParamList baseClass}}>{{/if}}{{/if}}{{#if implements}}{{#if isDerivedType}}, {{/if}}{{joinByName implements ", "}}{{/if}}{{/if}}
26
+ {{curly true}}{{#if discriminatorInfo}}
27
+ // Discriminator value
28
+ private const string DiscriminatorValue = "{{discriminatorInfo.value}}";{{#if (eq discriminatorInfo.value "")}}
29
+
30
+ // Discriminator property name
31
+ protected const string DiscriminatorPropertyName = "{{discriminatorInfo.propertyName}}";{{/if}}{{/if}}
32
+
33
+ /// <summary>
34
+ /// Extensibility point - allows changing class properties during construction.
35
+ /// </summary>
36
+ partial void OnBeforeInitialize();
37
+
38
+ /// <summary>
39
+ /// Extensibility point - allows changing class properties during construction.
40
+ /// </summary>
41
+ partial void OnAfterInitialize();
42
+
43
+ /// <summary>
44
+ /// Initializes a new instance of the {{name}} class.
45
+ /// </summary>
46
+ public {{name}}()
47
+ {
48
+ OnBeforeInitialize();
49
+ {{#if (and discriminatorInfo discriminatorInfo.value)}}
50
+ {{csharpname discriminatorInfo.propertyName}} = DiscriminatorValue;
51
+ {{/if}}
52
+ {{#if (and isVersioned (not hasVersionedAncestor))}}
53
+ VersionInfo = new {{name}}VersionInfo(this);
54
+ {{/if}}
55
+ {{#if (and isVersioned hasVersionedAncestor)}}
56
+ VersionInfo = new {{name}}VersionInfo(this, VersionInfo);
57
+ {{/if}}
58
+ OnAfterInitialize();
59
+ }
60
+
61
+ {{#each properties}}
62
+ {{#if description}}
63
+ /// <summary>
64
+ {{> renderComment content=description}}
65
+ /// </summary>
66
+ {{/if}}
67
+ {{#if versions}}
68
+ {{#each versions}}
69
+ [{{name}}("{{onVersion}}")]
70
+ {{/each}}
71
+ {{/if}}
72
+ {{#if validations}}
73
+ {{#each validations}}
74
+ [{{name}}({{#each parameters}}{{#if (eq type "string")}}@"{{/if}}{{value}}{{#if (eq type "string")}}"{{/if}}{{#unless @last}}, {{/unless}}{{/each}})]
75
+ {{/each}}
76
+ {{/if}}
77
+ {{#if converters}}
78
+ {{#each converters}}
79
+ [JsonConverter(typeof({{name}}))]
80
+ {{/each}}
81
+ {{/if}}
82
+ [JsonProperty("{{serializedName}}")]
83
+ public {{type.name}}{{#if type.typeParameters}}<{{typeParamList type}}>{{/if}} {{name}} { get; set; }{{#if default}} = {{default}};{{/if}}
84
+ {{#unless @last}}
85
+
86
+ {{/unless}}{{/each}}
87
+ {{#if (and isVersioned (not hasVersionedAncestor))}}
88
+ /// <summary>
89
+ /// The version information for this class.
90
+ /// </summary>
91
+ [JsonIgnore]
92
+ public ResourceVersionInfo VersionInfo { get; set; }{{/if}}
93
+ {{#if isSerialized}}
94
+ {{#if isVersioned}}
95
+
96
+ {{/if}}
97
+ /// <summary>
98
+ /// Tracks deserialization of the resource.
99
+ /// </summary>
100
+ [JsonIgnore]
101
+ public ResourceSerializationInfo SerializationInfo { get; set; } = new DefaultSerializationInfo();{{/if}}
102
+ }
103
+ }