@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.
- package/LICENSE +21 -0
- package/dist/src/generate.d.ts +13 -0
- package/dist/src/generate.d.ts.map +1 -0
- package/dist/src/generate.js +1592 -0
- package/dist/src/generate.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +202 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +143 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +29 -0
- package/dist/src/testing/index.js.map +1 -0
- package/package.json +74 -0
- package/readme.md +66 -0
- package/templates/liftr/closedEnum.sq +27 -0
- package/templates/liftr/model.sq +43 -0
- package/templates/liftr/openEnum.sq +34 -0
- package/templates/liftr/resourceControllerBase.sq +140 -0
- package/templates/liftr/serviceRoutingConstants.sq +35 -0
- package/templates/liftr/single/Operation.sq +40 -0
- package/templates/liftr/single/OperationAction.sq +31 -0
- package/templates/liftr/single/OperationControllerBase.sq +38 -0
- package/templates/liftr/single/OperationDisplay.sq +35 -0
- package/templates/liftr/single/OperationListResult.sq +17 -0
- package/templates/liftr/single/OperationOrigin.sq +31 -0
- package/templates/providerhub/closedEnum.sq +24 -0
- package/templates/providerhub/model.sq +103 -0
- package/templates/providerhub/modelCopy.sq +98 -0
- package/templates/providerhub/modelCopyExtension.sq +39 -0
- package/templates/providerhub/modelVersionComposite.sq +69 -0
- package/templates/providerhub/modelVersionStandard.sq +62 -0
- package/templates/providerhub/openEnum.sq +34 -0
- package/templates/providerhub/resourceController.sq +20 -0
- package/templates/providerhub/resourceControllerBase.Logger.sq +48 -0
- package/templates/providerhub/resourceControllerBase.sq +154 -0
- package/templates/providerhub/resourceProviderRegistration.sq +11 -0
- package/templates/providerhub/resourceRegistration.sq +27 -0
- package/templates/providerhub/serviceRoutingConstants.sq +38 -0
- package/templates/providerhub/single/OperationControllerBase.sq +52 -0
- package/templates/providerhub/versionCollection.sq +28 -0
- package/templates/providerhub/versionedContractResolver.sq +57 -0
- package/templates/providerhub/versionedSerializer.sq +38 -0
|
@@ -0,0 +1,98 @@
|
|
|
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.ComponentModel;
|
|
8
|
+
using System.Runtime.Serialization;
|
|
9
|
+
using Newtonsoft.Json;
|
|
10
|
+
using Microsoft.TypeSpec.ProviderHub.Controller;
|
|
11
|
+
|
|
12
|
+
namespace Microsoft.{{serviceName}}.Service.Models
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// Helper for merging canonical {{name}} models as part of a PUT or PATCH operation
|
|
16
|
+
/// </summary>
|
|
17
|
+
public partial class {{name}}CopyHelper
|
|
18
|
+
{
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Extensibility point: perform actions before data is copied
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <param name="source">The source {{name}}</param>
|
|
23
|
+
/// <param name="target">The target {{name}}</param>
|
|
24
|
+
partial void OnBeginCopyForPatch({{name}} source, {{name}} target);
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
/// Extensibility point: perform actions after data is copied
|
|
28
|
+
/// </summary>
|
|
29
|
+
/// <param name="source">The source {{name}}</param>
|
|
30
|
+
/// <param name="target">The target {{name}}</param>
|
|
31
|
+
partial void OnEndCopyForPatch({{name}} source, {{name}} target);
|
|
32
|
+
|
|
33
|
+
/// <summary>
|
|
34
|
+
/// Copy the properties of a source {{name}} to a target {{name}}, using PATCH semantics
|
|
35
|
+
/// </summary>
|
|
36
|
+
/// <param name="source">The source {{name}}</param>
|
|
37
|
+
/// <param name="target">The target {{name}}</param>
|
|
38
|
+
public void CopyForPatch({{name}} source, {{name}} target)
|
|
39
|
+
{
|
|
40
|
+
{{#if (or isVersioned hasVersionedAncestor)}}
|
|
41
|
+
var version = source.VersionInfo;
|
|
42
|
+
{{/if}}
|
|
43
|
+
var serialization = source.SerializationInfo;
|
|
44
|
+
OnBeginCopyForPatch(source, target);
|
|
45
|
+
{{#with this as | model |}}
|
|
46
|
+
{{#each properties}}
|
|
47
|
+
{{#if (or model.isVersioned model.hasVersionedAncestor)}}
|
|
48
|
+
if (version.IsContractProperty(nameof(source.{{name}})) && serialization.IsSerializedProperty(nameof(source.{{name}})))
|
|
49
|
+
target.{{name}} = source.{{name}};
|
|
50
|
+
{{else}}
|
|
51
|
+
if (serialization.IsSerializedProperty(nameof(source.{{name}})))
|
|
52
|
+
target.{{name}} = source.{{name}};
|
|
53
|
+
{{/if}}
|
|
54
|
+
{{/each}}
|
|
55
|
+
{{/with}}
|
|
56
|
+
OnEndCopyForPatch(source, target);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
/// Extensibility point: perform actions before data is copied
|
|
61
|
+
/// </summary>
|
|
62
|
+
/// <param name="source">The source {{name}}</param>
|
|
63
|
+
/// <param name="target">The target {{name}}</param>
|
|
64
|
+
partial void OnBeginCopyForPut({{name}} source, {{name}} target);
|
|
65
|
+
|
|
66
|
+
/// <summary>
|
|
67
|
+
/// Extensibility point: perform actions after data is copied
|
|
68
|
+
/// </summary>
|
|
69
|
+
/// <param name="source">The source {{name}}</param>
|
|
70
|
+
/// <param name="target">The target {{name}}</param>
|
|
71
|
+
partial void OnEndCopyForPut({{name}} source, {{name}} target);
|
|
72
|
+
|
|
73
|
+
/// <summary>
|
|
74
|
+
/// Copy the properties of a source {{name}} to a target {{name}}, using PUT semantics
|
|
75
|
+
/// </summary>
|
|
76
|
+
/// <param name="source">The source {{name}}</param>
|
|
77
|
+
/// <param name="target">The target {{name}}</param>
|
|
78
|
+
public void CopyForPut({{name}} source, {{name}} target)
|
|
79
|
+
{
|
|
80
|
+
{{#if (or isVersioned hasVersionedAncestor)}}
|
|
81
|
+
var version = source.VersionInfo;
|
|
82
|
+
{{/if}}
|
|
83
|
+
var serialization = source.SerializationInfo;
|
|
84
|
+
OnBeginCopyForPut(source, target);
|
|
85
|
+
{{#with this as | model |}}
|
|
86
|
+
{{#each properties}}
|
|
87
|
+
{{#if (or ../isVersioned ../hasVersionedAncestor)}}
|
|
88
|
+
if (version.IsContractProperty(nameof(source.{{name}})))
|
|
89
|
+
target.{{name}} = source.{{name}};
|
|
90
|
+
{{else}}
|
|
91
|
+
target.{{name}} = source.{{name}};
|
|
92
|
+
{{/if}}
|
|
93
|
+
{{/each}}
|
|
94
|
+
{{/with}}
|
|
95
|
+
OnEndCopyForPut(source, target);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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.ComponentModel;
|
|
8
|
+
using System.Runtime.Serialization;
|
|
9
|
+
using Newtonsoft.Json;
|
|
10
|
+
using Microsoft.TypeSpec.ProviderHub.Controller;
|
|
11
|
+
|
|
12
|
+
namespace Microsoft.{{serviceName}}.Service.Models
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// Extensions for easy PUT and PATCH copying of a resource
|
|
16
|
+
/// </summary>
|
|
17
|
+
public static class {{name}}Extensions
|
|
18
|
+
{
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Copy the properties of this {{name}} to another {{name}}
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <param name="source">The source {{name}}</param>
|
|
23
|
+
/// <param name="target">The target {{name}}</param>
|
|
24
|
+
/// <param name="copySettings">The kind of copy you would like to perform (using PUT or PATCH semantics)</param>
|
|
25
|
+
public static void CopyTo(this {{name}} source, {{name}} target, CopySettings copySettings = CopySettings.UsePutSemantics)
|
|
26
|
+
{
|
|
27
|
+
var helper = new {{name}}CopyHelper();
|
|
28
|
+
switch (copySettings)
|
|
29
|
+
{
|
|
30
|
+
case CopySettings.UsePatchSemantics:
|
|
31
|
+
helper.CopyForPatch(source, target);
|
|
32
|
+
break;
|
|
33
|
+
case CopySettings.UsePutSemantics:
|
|
34
|
+
helper.CopyForPut(source, target);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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.ComponentModel;
|
|
8
|
+
using System.Runtime.Serialization;
|
|
9
|
+
using Newtonsoft.Json;
|
|
10
|
+
using Microsoft.TypeSpec.ProviderHub.Controller;
|
|
11
|
+
|
|
12
|
+
namespace Microsoft.{{serviceName}}.Service.Models
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// The version information for a {{name}}.
|
|
16
|
+
/// </summary>
|
|
17
|
+
public partial class {{name}}VersionInfo : ResourceVersionInfo
|
|
18
|
+
{
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Create versioning info for a {{name}}
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <param name="wrapped">The version info of the ancestor versioned class</param>
|
|
23
|
+
public {{name}}VersionInfo({{name}} instance, ResourceVersionInfo wrapped)
|
|
24
|
+
{
|
|
25
|
+
OnBeforeInitialize(instance, wrapped);
|
|
26
|
+
ContractProperties = new ResourceContractProperties(Type, VersionComparer, wrapped?.ContractProperties, GetBaseModelVersion);
|
|
27
|
+
OnAfterInitialize(instance, wrapped);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// <summary>
|
|
31
|
+
/// Extensibility point - perform operations on the version info before it is initialized
|
|
32
|
+
/// </summary>
|
|
33
|
+
/// <param name="instance">The {{name}} being tracked</param>
|
|
34
|
+
/// <param name="wrappedVersionInfo">Since an ancestor class is also versioned, the version info for that class</param>
|
|
35
|
+
partial void OnBeforeInitialize({{name}} instance, ResourceVersionInfo wrappedVersionInfo);
|
|
36
|
+
|
|
37
|
+
/// <summary>
|
|
38
|
+
/// Extensibility point - perform operations on the version info after it is initialized
|
|
39
|
+
/// </summary>
|
|
40
|
+
/// <param name="instance">The {{name}} being tracked</param>
|
|
41
|
+
/// <param name="wrappedVersionInfo">Since an ancestor class is also versioned, the version info for that class</param>
|
|
42
|
+
partial void OnAfterInitialize({{name}} instance, ResourceVersionInfo wrappedVersionInfo);
|
|
43
|
+
|
|
44
|
+
/// <summary>
|
|
45
|
+
/// The version comparer for this type.
|
|
46
|
+
/// </summary>
|
|
47
|
+
public override VersionComparer VersionComparer => VersionedSerializer.Instance.ServiceVersionComparer;
|
|
48
|
+
|
|
49
|
+
/// <summary>
|
|
50
|
+
/// The target type for this version info
|
|
51
|
+
/// </summary>
|
|
52
|
+
public override Type Type => typeof({{name}});
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// The chain of resource contract properties that determine version info
|
|
56
|
+
/// </summary>
|
|
57
|
+
public override ResourceContractProperties ContractProperties { get; }
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
/// The last deserialized version of the tracked resource
|
|
61
|
+
/// </summary>
|
|
62
|
+
public override string LastDeserializedVersion { get; set; }
|
|
63
|
+
|
|
64
|
+
string GetBaseModelVersion(Type type, string version)
|
|
65
|
+
{
|
|
66
|
+
return VersionedSerializer.Instance.GetModelVersion(type, version);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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.ComponentModel;
|
|
8
|
+
using System.Runtime.Serialization;
|
|
9
|
+
using Newtonsoft.Json;
|
|
10
|
+
using Microsoft.TypeSpec.ProviderHub.Controller;
|
|
11
|
+
|
|
12
|
+
namespace Microsoft.{{serviceName}}.Service.Models
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// The version information for a {{name}}.
|
|
16
|
+
/// </summary>
|
|
17
|
+
public partial class {{name}}VersionInfo : ResourceVersionInfo
|
|
18
|
+
{
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Create versioning info for a {{name}}
|
|
21
|
+
/// </summary>
|
|
22
|
+
/// <param name="instance">The tracked object</param>
|
|
23
|
+
public {{name}}VersionInfo({{name}} instance)
|
|
24
|
+
{
|
|
25
|
+
OnBeforeInitialize(instance);
|
|
26
|
+
ContractProperties = new ResourceContractProperties(Type, VersionComparer);
|
|
27
|
+
OnAfterInitialize(instance);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// <summary>
|
|
31
|
+
/// Extensibility point - perform operations on the version info before it is initialized
|
|
32
|
+
/// </summary>
|
|
33
|
+
/// <param name="instance">The {{name}} being tracked</param>
|
|
34
|
+
partial void OnBeforeInitialize({{name}} instance);
|
|
35
|
+
|
|
36
|
+
/// <summary>
|
|
37
|
+
/// Extensibility point - perform operations on the version info after it is initialized
|
|
38
|
+
/// </summary>
|
|
39
|
+
/// <param name="instance">The {{name}} being tracked</param>
|
|
40
|
+
partial void OnAfterInitialize({{name}} instance);
|
|
41
|
+
|
|
42
|
+
/// <summary>
|
|
43
|
+
/// The version comparer for this type.
|
|
44
|
+
/// </summary>
|
|
45
|
+
public override VersionComparer VersionComparer => VersionedSerializer.Instance.ServiceVersionComparer;
|
|
46
|
+
|
|
47
|
+
/// <summary>
|
|
48
|
+
/// The last deserialized version of the tracked resource
|
|
49
|
+
/// </summary>
|
|
50
|
+
public override string LastDeserializedVersion { get; set; }
|
|
51
|
+
|
|
52
|
+
/// <summary>
|
|
53
|
+
/// The target type for this version info
|
|
54
|
+
/// </summary>
|
|
55
|
+
public override Type Type => typeof({{name}});
|
|
56
|
+
|
|
57
|
+
/// <summary>
|
|
58
|
+
/// The chain of resource contract properties that determine version info
|
|
59
|
+
/// </summary>
|
|
60
|
+
public override ResourceContractProperties ContractProperties { get; }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
// <auto-generated />
|
|
5
|
+
using Newtonsoft.Json;
|
|
6
|
+
using Microsoft.TypeSpec.ProviderHub.Controller;
|
|
7
|
+
|
|
8
|
+
namespace {{nameSpace}}.Service.Models
|
|
9
|
+
{
|
|
10
|
+
{{#if description}}
|
|
11
|
+
/// <summary>
|
|
12
|
+
{{> renderComment content=description}}
|
|
13
|
+
/// </summary>
|
|
14
|
+
{{/if}}
|
|
15
|
+
[JsonConverter(typeof(EnumJsonConverter<{{name}}>))]
|
|
16
|
+
public struct {{name}}
|
|
17
|
+
{
|
|
18
|
+
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}}
|
|
19
|
+
|
|
20
|
+
private readonly string _value;
|
|
21
|
+
|
|
22
|
+
public {{name}}(string value) =>
|
|
23
|
+
_value = value;
|
|
24
|
+
|
|
25
|
+
public override string ToString() =>
|
|
26
|
+
_value;
|
|
27
|
+
|
|
28
|
+
public static implicit operator string({{name}} obj) =>
|
|
29
|
+
obj.ToString();
|
|
30
|
+
|
|
31
|
+
public static implicit operator {{name}}(string str) =>
|
|
32
|
+
new {{name}}(str);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
// <auto-generated />
|
|
5
|
+
|
|
6
|
+
using Microsoft.Extensions.Logging;
|
|
7
|
+
|
|
8
|
+
namespace {{nameSpace}}.Service.Controllers
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// Controller for user RP operations on the {{name}} resource.
|
|
12
|
+
/// </summary>
|
|
13
|
+
public partial class {{name}}Controller : {{name}}ControllerBase
|
|
14
|
+
{
|
|
15
|
+
public {{name}}Controller(ILogger<{{name}}Controller> logger)
|
|
16
|
+
: base(logger)
|
|
17
|
+
{
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
// <auto-generated />
|
|
5
|
+
|
|
6
|
+
{{#with this as |res|}}
|
|
7
|
+
using System;
|
|
8
|
+
using Microsoft.Extensions.Logging;
|
|
9
|
+
|
|
10
|
+
namespace {{nameSpace}}.Service.Controllers
|
|
11
|
+
{
|
|
12
|
+
public abstract partial class {{res.name}}ControllerBase
|
|
13
|
+
{
|
|
14
|
+
private static Action<ILogger, Exception> _logRequestNull;
|
|
15
|
+
{{#each operations as |operation operationIndex|}}
|
|
16
|
+
private static Action<ILogger, Exception> _logValidate{{getOperationAction operation}};
|
|
17
|
+
private static Action<ILogger, Exception> _logBegin{{getOperationAction operation}};
|
|
18
|
+
{{#if (ne (getOperationAction operation) "Read")}}
|
|
19
|
+
private static Action<ILogger, Exception> _logEnd{{getOperationAction operation}};
|
|
20
|
+
{{/if}}
|
|
21
|
+
{{/each}}
|
|
22
|
+
|
|
23
|
+
private static void InitializeLogger()
|
|
24
|
+
{
|
|
25
|
+
_logRequestNull = LoggerMessage.Define(
|
|
26
|
+
LogLevel.Error,
|
|
27
|
+
new EventId(1, "RequestIsNull"),
|
|
28
|
+
"Request is null");
|
|
29
|
+
{{#each operations as |operation operationIndex|}}
|
|
30
|
+
_logValidate{{getOperationAction operation}} = LoggerMessage.Define(
|
|
31
|
+
LogLevel.Information,
|
|
32
|
+
new EventId({{increment operationIndex}}1, "ValidateOperation"),
|
|
33
|
+
"Validate{{getOperationAction operation}}Async()");
|
|
34
|
+
_logBegin{{getOperationAction operation}} = LoggerMessage.Define(
|
|
35
|
+
LogLevel.Information,
|
|
36
|
+
new EventId({{increment operationIndex}}2, "BeginOperation"),
|
|
37
|
+
"Begin{{getOperationAction operation}}Async()");
|
|
38
|
+
{{#if (ne (getOperationAction operation) "Read")}}
|
|
39
|
+
_logEnd{{getOperationAction operation}} = LoggerMessage.Define(
|
|
40
|
+
LogLevel.Information,
|
|
41
|
+
new EventId({{increment operationIndex}}3, "EndOperation"),
|
|
42
|
+
"End{{getOperationAction operation}}Async()");
|
|
43
|
+
{{/if}}
|
|
44
|
+
{{/each}}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
{{/with}}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
// <auto-generated />
|
|
5
|
+
|
|
6
|
+
{{#with this as |res|}}
|
|
7
|
+
using System;
|
|
8
|
+
using System.Net;
|
|
9
|
+
using System.Threading.Tasks;
|
|
10
|
+
using Microsoft.AspNetCore.Mvc;
|
|
11
|
+
using Microsoft.TypeSpec.ProviderHub;
|
|
12
|
+
using Microsoft.TypeSpec.ProviderHub.Controller;
|
|
13
|
+
using Microsoft.Extensions.Logging;
|
|
14
|
+
using {{nameSpace}}.Service.Models;
|
|
15
|
+
|
|
16
|
+
namespace {{nameSpace}}.Service.Controllers
|
|
17
|
+
{
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// Controller for user RP operations on the {{res.name}} resource.
|
|
20
|
+
/// </summary>
|
|
21
|
+
[ApiController]
|
|
22
|
+
public abstract partial class {{res.name}}ControllerBase : ControllerBase
|
|
23
|
+
{
|
|
24
|
+
protected readonly ILogger<{{res.name}}ControllerBase> _logger;
|
|
25
|
+
|
|
26
|
+
static {{res.name}}ControllerBase()
|
|
27
|
+
{
|
|
28
|
+
InitializeLogger();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected {{res.name}}ControllerBase(ILogger<{{res.name}}ControllerBase> logger)
|
|
32
|
+
{
|
|
33
|
+
_logger = logger;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
{{#each operations as |operation operationIndex|}}
|
|
37
|
+
{{#if (getOperationAction operation)}}
|
|
38
|
+
{{#if (notCustomOp operation)}}
|
|
39
|
+
/// <summary>
|
|
40
|
+
/// Validate the request to {{getOperationAction operation}} the {{res.name}} resource.
|
|
41
|
+
/// </summary>
|
|
42
|
+
{{#each operation.parameters as |parameter index |}}
|
|
43
|
+
/// <param name="{{parameter.name}}">
|
|
44
|
+
{{> renderComment content=parameter.description}}
|
|
45
|
+
/// </param>
|
|
46
|
+
{{/each}}
|
|
47
|
+
/// <returns> A ValidationResponse indicating the validity of the {{getOperationAction operation}} request.</returns>
|
|
48
|
+
[HttpPost]
|
|
49
|
+
[Route({{res.serviceName}}ServiceRoutes.{{res.name}}Validate{{getOperationAction operation}})]
|
|
50
|
+
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ValidationResponse))]
|
|
51
|
+
public async Task<IActionResult> Validate{{getOperationAction operation}}Async({{decl operation}})
|
|
52
|
+
{
|
|
53
|
+
_logValidate{{getOperationAction operation}}(_logger, null);
|
|
54
|
+
|
|
55
|
+
{{#if (isDefined operation.requestParameter)}}
|
|
56
|
+
var modelValidation = ValidationHelpers.ValidateModel({{operation.requestParameter.name}});
|
|
57
|
+
if (modelValidation.IsValid)
|
|
58
|
+
{
|
|
59
|
+
modelValidation = await OnValidate{{getOperationAction operation}}({{call operation}});
|
|
60
|
+
}
|
|
61
|
+
{{else}}
|
|
62
|
+
var modelValidation = await OnValidate{{getOperationAction operation}}({{call operation}});
|
|
63
|
+
{{/if}}
|
|
64
|
+
return Ok(modelValidation);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected virtual Task<ValidationResponse> OnValidate{{getOperationAction operation}}({{decl operation}})
|
|
68
|
+
{
|
|
69
|
+
return Task.FromResult(ValidationResponse.Valid);
|
|
70
|
+
}
|
|
71
|
+
{{#unless @first}}
|
|
72
|
+
|
|
73
|
+
{{/unless}}
|
|
74
|
+
{{#if (ne (getOperationAction operation) "Read")}}
|
|
75
|
+
/// <summary>
|
|
76
|
+
/// Called after the end of the request to {{getOperationAction operation}} the {{res.name}} resource.
|
|
77
|
+
/// </summary>
|
|
78
|
+
{{#each operation.parameters as |parameter index|}}
|
|
79
|
+
/// <param name="{{parameter.name}}">
|
|
80
|
+
{{> renderComment content=parameter.description}}
|
|
81
|
+
/// </param>
|
|
82
|
+
{{/each}}
|
|
83
|
+
[HttpPost]
|
|
84
|
+
[Route({{res.serviceName}}ServiceRoutes.{{res.name}}End{{getOperationAction operation}})]
|
|
85
|
+
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(void))]
|
|
86
|
+
public async Task<IActionResult> End{{getOperationAction operation}}Async({{decl operation}})
|
|
87
|
+
{
|
|
88
|
+
_logEnd{{getOperationAction operation}}(_logger, null);
|
|
89
|
+
|
|
90
|
+
await OnEnd{{getOperationAction operation}}({{call operation}});
|
|
91
|
+
return Ok();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected virtual Task OnEnd{{getOperationAction operation}}({{decl operation}})
|
|
95
|
+
{
|
|
96
|
+
return Task.CompletedTask;
|
|
97
|
+
}
|
|
98
|
+
{{/if}}
|
|
99
|
+
{{/if}}
|
|
100
|
+
|
|
101
|
+
/// <summary>
|
|
102
|
+
/// {{getOperationAction operation}} the {{res.name}} resource.
|
|
103
|
+
/// </summary>
|
|
104
|
+
{{#each operation.parameters as |parameter index|}}
|
|
105
|
+
/// <param name="{{parameter.name}}">
|
|
106
|
+
{{> renderComment content=parameter.description}}
|
|
107
|
+
/// </param>
|
|
108
|
+
{{/each}}
|
|
109
|
+
/// <returns> The {{res.name}} resource.</returns>
|
|
110
|
+
[Http{{#if (eqi operation.verb "GET")}}Post{{else}}{{initialCaps operation.verb}}{{/if}}]
|
|
111
|
+
[Route({{res.serviceName}}ServiceRoutes.{{res.name}}{{#if (eqi operation.verb "GET")}}BeginRead{{else}}Item{{/if}}{{#unless (notCustomOp operation)}}{{operation.name}}{{/unless}})]
|
|
112
|
+
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof({{operation.returnType}}))]
|
|
113
|
+
{{#if (or (eq (getOperationAction operation) "Create") (eq (getOperationAction operation) "Patch"))}}
|
|
114
|
+
[ProducesResponseType((int)HttpStatusCode.Created, Type = typeof({{operation.returnType}}))]
|
|
115
|
+
{{/if}}
|
|
116
|
+
{{#if (eqi operation.verb "POST")}}
|
|
117
|
+
[ProducesResponseType((int)HttpStatusCode.Accepted, Type = typeof({{operation.returnType}}))]
|
|
118
|
+
{{/if}}
|
|
119
|
+
{{#if (eqi operation.verb "DELETE")}}
|
|
120
|
+
[ProducesResponseType((int)HttpStatusCode.NoContent, Type = typeof({{operation.returnType}}))]
|
|
121
|
+
{{/if}}
|
|
122
|
+
public async Task<IActionResult> Begin{{getOperationAction operation}}Async({{decl operation}})
|
|
123
|
+
{
|
|
124
|
+
_logBegin{{getOperationAction operation}}(_logger, null);
|
|
125
|
+
|
|
126
|
+
{{#if operation.requestParameter}}
|
|
127
|
+
{{operation.requestParameter.name}} = {{operation.requestParameter.name}} ?? throw new ArgumentNullException(nameof({{operation.requestParameter.name}}));
|
|
128
|
+
{{/if}}
|
|
129
|
+
if (Request is null)
|
|
130
|
+
{
|
|
131
|
+
_logRequestNull(_logger, null);
|
|
132
|
+
return BadRequest("Request is null");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var result = await On{{getOperationAction operation}}Async({{call operation }});
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
protected virtual Task<IActionResult> On{{getOperationAction operation}}Async({{decl operation}})
|
|
140
|
+
{
|
|
141
|
+
{{#if (eqi operation.verb "PATCH")}}
|
|
142
|
+
return Task.FromResult<IActionResult>(Ok({{ bodyParamName operation }}));
|
|
143
|
+
{{else}}
|
|
144
|
+
return Task.FromResult<IActionResult>(Ok());
|
|
145
|
+
{{/if}}
|
|
146
|
+
}
|
|
147
|
+
{{/if}}
|
|
148
|
+
{{#unless @last}}
|
|
149
|
+
|
|
150
|
+
{{/unless}}
|
|
151
|
+
{{/each}}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
{{/with}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"properties": {
|
|
3
|
+
"providerType": "Hidden",
|
|
4
|
+
"management": {
|
|
5
|
+
"incidentRoutingService": "{{serviceName}} Resource Provider",
|
|
6
|
+
"incidentRoutingTeam": "{{serviceName}} Triage",
|
|
7
|
+
"incidentContactEmail": "helpme@{{serviceName}}.com"
|
|
8
|
+
},
|
|
9
|
+
"enableTenantLinkedNotification": false
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"properties": {
|
|
3
|
+
"routingType": "Default",
|
|
4
|
+
"regionality": "Regional",
|
|
5
|
+
"management": {
|
|
6
|
+
"incidentRoutingService": "ICM ServiceName",
|
|
7
|
+
"incidentRoutingTeam": "ICM TeamName",
|
|
8
|
+
"incidentContactEmail": "incidentContactEmail@domain.com"
|
|
9
|
+
},
|
|
10
|
+
"endpoints": [
|
|
11
|
+
{
|
|
12
|
+
"apiVersions": ["{{join apiVersion "\", \""}}"],
|
|
13
|
+
"locations": ["West US"],
|
|
14
|
+
"extensions": [
|
|
15
|
+
{
|
|
16
|
+
"endpointUri": "http://host.docker.internal:6020/",
|
|
17
|
+
"extensionCategories": [
|
|
18
|
+
{{#each extensions as | value valueIndex|}}
|
|
19
|
+
"{{value}}"{{#unless @last}},{{/unless}}
|
|
20
|
+
{{/each}}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
// <auto-generated />
|
|
5
|
+
|
|
6
|
+
namespace {{nameSpace}}.Service.Controllers
|
|
7
|
+
{
|
|
8
|
+
public static class {{serviceName}}ServiceRoutes
|
|
9
|
+
{
|
|
10
|
+
{{#if includeOperationController}}
|
|
11
|
+
public const string ListOperations = "providers/{{nameSpace}}/operations";
|
|
12
|
+
{{/if}}
|
|
13
|
+
{{#each resources as |resource index |}}
|
|
14
|
+
public const string {{resource.name}}Item = "{{resource.itemPath}}";
|
|
15
|
+
{{#each resource.operations as | operation opIndex |}}
|
|
16
|
+
{{#if (eqi operation.verb "PUT")}}
|
|
17
|
+
public const string {{resource.name}}ValidateCreate = "{{resource.itemPath}}/resourceCreationValidate";
|
|
18
|
+
public const string {{resource.name}}EndCreate = "{{resource.itemPath}}/resourceCreationCompleted";
|
|
19
|
+
{{/if}}
|
|
20
|
+
{{#if (eqi operation.verb "GET")}}
|
|
21
|
+
public const string {{resource.name}}ValidateRead = "{{resource.itemPath}}/resourceReadValidate";
|
|
22
|
+
public const string {{resource.name}}BeginRead = "{{resource.itemPath}}/resourceReadBegin";
|
|
23
|
+
{{/if}}
|
|
24
|
+
{{#if (eqi operation.verb "PATCH")}}
|
|
25
|
+
public const string {{resource.name}}ValidatePatch = "{{resource.itemPath}}/resourcePatchValidate";
|
|
26
|
+
public const string {{resource.name}}EndPatch = "{{resource.itemPath}}/resourcePatchCompleted";
|
|
27
|
+
{{/if}}
|
|
28
|
+
{{#if (eqi operation.verb "DELETE")}}
|
|
29
|
+
public const string {{resource.name}}ValidateDelete = "{{resource.itemPath}}/resourceDeletionValidate";
|
|
30
|
+
public const string {{resource.name}}EndDelete = "{{resource.itemPath}}/resourceDeletionCompleted";
|
|
31
|
+
{{/if}}
|
|
32
|
+
{{#if (eqi operation.verb "POST")}}
|
|
33
|
+
public const string {{resource.name}}Item{{operation.name}} = "{{resource.itemPath}}/{{operation.subPath}}";
|
|
34
|
+
{{/if}}
|
|
35
|
+
{{/each}}
|
|
36
|
+
{{/each}}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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.Net;
|
|
8
|
+
using System.Threading.Tasks;
|
|
9
|
+
using Microsoft.AspNetCore.Http;
|
|
10
|
+
using Microsoft.AspNetCore.Mvc;
|
|
11
|
+
using Microsoft.TypeSpec.ProviderHub.Controller;
|
|
12
|
+
using Microsoft.Extensions.Logging;
|
|
13
|
+
|
|
14
|
+
using {{nameSpace}}.Service.Models;
|
|
15
|
+
|
|
16
|
+
namespace {{nameSpace}}.Service.Controllers
|
|
17
|
+
{
|
|
18
|
+
public abstract class OperationControllerBase : Controller
|
|
19
|
+
{
|
|
20
|
+
private static readonly Action<ILogger, Exception> _logListOperations;
|
|
21
|
+
|
|
22
|
+
protected readonly ILogger<OperationControllerBase> _logger;
|
|
23
|
+
|
|
24
|
+
static OperationControllerBase()
|
|
25
|
+
{
|
|
26
|
+
_logListOperations = LoggerMessage.Define(
|
|
27
|
+
LogLevel.Information,
|
|
28
|
+
new EventId(1, "ListOperations"),
|
|
29
|
+
"ListOperationsAsync()");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected OperationControllerBase(ILogger<OperationControllerBase> logger) =>
|
|
33
|
+
_logger = logger;
|
|
34
|
+
|
|
35
|
+
/// <summary>
|
|
36
|
+
/// List all operations provided by {{nameSpace}}.
|
|
37
|
+
/// </summary>
|
|
38
|
+
/// <returns> The list of {{nameSpace}} operations.</returns>
|
|
39
|
+
[HttpGet]
|
|
40
|
+
[Route({{serviceName}}ServiceRoutes.ListOperations)]
|
|
41
|
+
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(OperationListResult))]
|
|
42
|
+
public async Task<IActionResult> ListOperationsAsync()
|
|
43
|
+
{
|
|
44
|
+
_logListOperations(_logger, null);
|
|
45
|
+
|
|
46
|
+
var list = await OnOperationListAsync(Request);
|
|
47
|
+
return Ok(list);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected abstract Task<OperationListResult> OnOperationListAsync(HttpRequest request);
|
|
51
|
+
}
|
|
52
|
+
}
|