@autorest/powershell 4.0.0-dev.1 → 4.0.0-dev.11
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/.rush/temp/package-deps_build.json +94 -60
- package/.rush/temp/shrinkwrap-deps.json +22 -22
- package/autorest-configuration-for-sdk.md +122 -0
- package/autorest-configuration.md +4 -2
- package/dist/cmdlets/class.d.ts +1 -0
- package/dist/cmdlets/class.d.ts.map +1 -1
- package/dist/cmdlets/class.js +218 -82
- package/dist/cmdlets/class.js.map +1 -1
- package/dist/cmdlets/namespace.d.ts.map +1 -1
- package/dist/cmdlets/namespace.js +3 -1
- package/dist/cmdlets/namespace.js.map +1 -1
- package/dist/cmdlets/parameter.js +1 -0
- package/dist/cmdlets/parameter.js.map +1 -1
- package/dist/enums/namespace.js +2 -1
- package/dist/enums/namespace.js.map +1 -1
- package/dist/file-formats/md-file.js +1 -0
- package/dist/file-formats/md-file.js.map +1 -1
- package/dist/file-formats/psd-file.js +1 -0
- package/dist/file-formats/psd-file.js.map +1 -1
- package/dist/file-formats/psscript-file.js +1 -0
- package/dist/file-formats/psscript-file.js.map +1 -1
- package/dist/generators/csproj.js +1 -0
- package/dist/generators/csproj.js.map +1 -1
- package/dist/generators/gitattributes.js +1 -0
- package/dist/generators/gitattributes.js.map +1 -1
- package/dist/generators/gitignore.js +1 -0
- package/dist/generators/gitignore.js.map +1 -1
- package/dist/generators/inputhandler.custom.d.ts +3 -0
- package/dist/generators/inputhandler.custom.d.ts.map +1 -0
- package/dist/generators/inputhandler.custom.js +33 -0
- package/dist/generators/inputhandler.custom.js.map +1 -0
- package/dist/generators/nuspec.js +1 -0
- package/dist/generators/nuspec.js.map +1 -1
- package/dist/generators/psm1.custom.js +1 -0
- package/dist/generators/psm1.custom.js.map +1 -1
- package/dist/generators/psm1.internal.js +1 -0
- package/dist/generators/psm1.internal.js.map +1 -1
- package/dist/generators/psm1.js +3 -2
- package/dist/generators/psm1.js.map +1 -1
- package/dist/generators/readme.js +1 -0
- package/dist/generators/readme.js.map +1 -1
- package/dist/generators/script-cmdlet.js +2 -1
- package/dist/generators/script-cmdlet.js.map +1 -1
- package/dist/internal/name-inferrer.js +1 -0
- package/dist/internal/name-inferrer.js.map +1 -1
- package/dist/internal/powershell-declarations.d.ts +3 -0
- package/dist/internal/powershell-declarations.d.ts.map +1 -1
- package/dist/internal/powershell-declarations.js +3 -0
- package/dist/internal/powershell-declarations.js.map +1 -1
- package/dist/internal/project.d.ts +14 -9
- package/dist/internal/project.d.ts.map +1 -1
- package/dist/internal/project.js +34 -12
- package/dist/internal/project.js.map +1 -1
- package/dist/internal/state.js +1 -0
- package/dist/internal/state.js.map +1 -1
- package/dist/internal/verbs.js +1 -0
- package/dist/internal/verbs.js.map +1 -1
- package/dist/llcsharp/clientruntime.d.ts +3 -0
- package/dist/llcsharp/clientruntime.d.ts.map +1 -1
- package/dist/llcsharp/clientruntime.js +4 -0
- package/dist/llcsharp/clientruntime.js.map +1 -1
- package/dist/llcsharp/code-model.d.ts +1 -0
- package/dist/llcsharp/code-model.d.ts.map +1 -1
- package/dist/llcsharp/csharp-declarations.js +1 -0
- package/dist/llcsharp/csharp-declarations.js.map +1 -1
- package/dist/llcsharp/enums/enum.js +2 -1
- package/dist/llcsharp/enums/enum.js.map +1 -1
- package/dist/llcsharp/enums/namespace.js +1 -0
- package/dist/llcsharp/enums/namespace.js.map +1 -1
- package/dist/llcsharp/exports.js +23 -13
- package/dist/llcsharp/exports.js.map +1 -1
- package/dist/llcsharp/generator.js +1 -0
- package/dist/llcsharp/generator.js.map +1 -1
- package/dist/llcsharp/messages.js +1 -0
- package/dist/llcsharp/messages.js.map +1 -1
- package/dist/llcsharp/model/idictionary.js +1 -0
- package/dist/llcsharp/model/idictionary.js.map +1 -1
- package/dist/llcsharp/model/interface.d.ts.map +1 -1
- package/dist/llcsharp/model/interface.js +2 -1
- package/dist/llcsharp/model/interface.js.map +1 -1
- package/dist/llcsharp/model/model-class-dictionary.js +1 -0
- package/dist/llcsharp/model/model-class-dictionary.js.map +1 -1
- package/dist/llcsharp/model/model-class-json.d.ts.map +1 -1
- package/dist/llcsharp/model/model-class-json.js +12 -2
- package/dist/llcsharp/model/model-class-json.js.map +1 -1
- package/dist/llcsharp/model/model-class-serializer.js +1 -0
- package/dist/llcsharp/model/model-class-serializer.js.map +1 -1
- package/dist/llcsharp/model/model-class.js +11 -10
- package/dist/llcsharp/model/model-class.js.map +1 -1
- package/dist/llcsharp/model/namespace.js +1 -0
- package/dist/llcsharp/model/namespace.js.map +1 -1
- package/dist/llcsharp/model/property.js +1 -0
- package/dist/llcsharp/model/property.js.map +1 -1
- package/dist/llcsharp/operation/api-class.js +1 -0
- package/dist/llcsharp/operation/api-class.js.map +1 -1
- package/dist/llcsharp/operation/method.d.ts.map +1 -1
- package/dist/llcsharp/operation/method.js +21 -27
- package/dist/llcsharp/operation/method.js.map +1 -1
- package/dist/llcsharp/operation/namespace.js +1 -0
- package/dist/llcsharp/operation/namespace.js.map +1 -1
- package/dist/llcsharp/operation/parameter.js +1 -0
- package/dist/llcsharp/operation/parameter.js.map +1 -1
- package/dist/llcsharp/project.d.ts.map +1 -1
- package/dist/llcsharp/project.js +3 -1
- package/dist/llcsharp/project.js.map +1 -1
- package/dist/llcsharp/schema/Uuid.js +1 -0
- package/dist/llcsharp/schema/Uuid.js.map +1 -1
- package/dist/llcsharp/schema/array.js +1 -0
- package/dist/llcsharp/schema/array.js.map +1 -1
- package/dist/llcsharp/schema/binary.js +1 -0
- package/dist/llcsharp/schema/binary.js.map +1 -1
- package/dist/llcsharp/schema/boolean.js +1 -0
- package/dist/llcsharp/schema/boolean.js.map +1 -1
- package/dist/llcsharp/schema/byte-array.js +1 -0
- package/dist/llcsharp/schema/byte-array.js.map +1 -1
- package/dist/llcsharp/schema/char.js +1 -0
- package/dist/llcsharp/schema/char.js.map +1 -1
- package/dist/llcsharp/schema/date-time.d.ts.map +1 -1
- package/dist/llcsharp/schema/date-time.js +1 -0
- package/dist/llcsharp/schema/date-time.js.map +1 -1
- package/dist/llcsharp/schema/date.js +1 -0
- package/dist/llcsharp/schema/date.js.map +1 -1
- package/dist/llcsharp/schema/duration.js +1 -0
- package/dist/llcsharp/schema/duration.js.map +1 -1
- package/dist/llcsharp/schema/enum.js +1 -0
- package/dist/llcsharp/schema/enum.js.map +1 -1
- package/dist/llcsharp/schema/integer.js +1 -0
- package/dist/llcsharp/schema/integer.js.map +1 -1
- package/dist/llcsharp/schema/object.js +1 -0
- package/dist/llcsharp/schema/object.js.map +1 -1
- package/dist/llcsharp/schema/password.js +2 -1
- package/dist/llcsharp/schema/password.js.map +1 -1
- package/dist/llcsharp/schema/primitive.js +1 -0
- package/dist/llcsharp/schema/primitive.js.map +1 -1
- package/dist/llcsharp/schema/schema-resolver.d.ts +2 -3
- package/dist/llcsharp/schema/schema-resolver.d.ts.map +1 -1
- package/dist/llcsharp/schema/schema-resolver.js +4 -0
- package/dist/llcsharp/schema/schema-resolver.js.map +1 -1
- package/dist/llcsharp/schema/string.d.ts.map +1 -1
- package/dist/llcsharp/schema/string.js +1 -0
- package/dist/llcsharp/schema/string.js.map +1 -1
- package/dist/llcsharp/schema/uri.d.ts +10 -0
- package/dist/llcsharp/schema/uri.d.ts.map +1 -0
- package/dist/llcsharp/schema/uri.js +25 -0
- package/dist/llcsharp/schema/uri.js.map +1 -0
- package/dist/llcsharp/validations.js +1 -0
- package/dist/llcsharp/validations.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -0
- package/dist/main.js.map +1 -1
- package/dist/models/model-extensions.js +7 -6
- package/dist/models/model-extensions.js.map +1 -1
- package/dist/module/module-class.js +2 -1
- package/dist/module/module-class.js.map +1 -1
- package/dist/module/module-namespace.js +1 -0
- package/dist/module/module-namespace.js.map +1 -1
- package/dist/plugins/add-azure-completers-v2.js +1 -0
- package/dist/plugins/add-azure-completers-v2.js.map +1 -1
- package/dist/plugins/create-commands-v2.d.ts.map +1 -1
- package/dist/plugins/create-commands-v2.js +6 -4
- package/dist/plugins/create-commands-v2.js.map +1 -1
- package/dist/plugins/cs-namer-v2.js +4 -3
- package/dist/plugins/cs-namer-v2.js.map +1 -1
- package/dist/plugins/llcsharp-v2.js +1 -0
- package/dist/plugins/llcsharp-v2.js.map +1 -1
- package/dist/plugins/modifiers-v2.d.ts +4 -0
- package/dist/plugins/modifiers-v2.d.ts.map +1 -1
- package/dist/plugins/modifiers-v2.js +69 -13
- package/dist/plugins/modifiers-v2.js.map +1 -1
- package/dist/plugins/plugin-create-inline-properties.d.ts.map +1 -1
- package/dist/plugins/plugin-create-inline-properties.js +16 -1
- package/dist/plugins/plugin-create-inline-properties.js.map +1 -1
- package/dist/plugins/plugin-tweak-m4-model.js +4 -3
- package/dist/plugins/plugin-tweak-m4-model.js.map +1 -1
- package/dist/plugins/plugin-tweak-model-azure-v2.js +4 -3
- package/dist/plugins/plugin-tweak-model-azure-v2.js.map +1 -1
- package/dist/plugins/plugin-tweak-model.js +15 -14
- package/dist/plugins/plugin-tweak-model.js.map +1 -1
- package/dist/plugins/powershell-v2.d.ts.map +1 -1
- package/dist/plugins/powershell-v2.js +8 -2
- package/dist/plugins/powershell-v2.js.map +1 -1
- package/dist/plugins/ps-namer-v2.js +1 -0
- package/dist/plugins/ps-namer-v2.js.map +1 -1
- package/dist/plugins/sdk-create-inline-properties.d.ts +4 -0
- package/dist/plugins/sdk-create-inline-properties.d.ts.map +1 -0
- package/dist/plugins/sdk-create-inline-properties.js +552 -0
- package/dist/plugins/sdk-create-inline-properties.js.map +1 -0
- package/dist/plugins/sdk-cs-namer.d.ts +3 -0
- package/dist/plugins/sdk-cs-namer.d.ts.map +1 -0
- package/dist/plugins/sdk-cs-namer.js +385 -0
- package/dist/plugins/sdk-cs-namer.js.map +1 -0
- package/dist/plugins/sdk-cs-simplifier.d.ts +3 -0
- package/dist/plugins/sdk-cs-simplifier.d.ts.map +1 -0
- package/dist/plugins/sdk-cs-simplifier.js +154 -0
- package/dist/plugins/sdk-cs-simplifier.js.map +1 -0
- package/dist/plugins/sdk-generate.d.ts +3 -0
- package/dist/plugins/sdk-generate.d.ts.map +1 -0
- package/dist/plugins/sdk-generate.js +106 -0
- package/dist/plugins/sdk-generate.js.map +1 -0
- package/dist/plugins/sdk-tweak-model.d.ts +3 -0
- package/dist/plugins/sdk-tweak-model.d.ts.map +1 -0
- package/dist/plugins/sdk-tweak-model.js +357 -0
- package/dist/plugins/sdk-tweak-model.js.map +1 -0
- package/dist/sdk/project.d.ts +45 -0
- package/dist/sdk/project.d.ts.map +1 -0
- package/dist/sdk/project.js +56 -0
- package/dist/sdk/project.js.map +1 -0
- package/dist/sdk/state.d.ts +23 -0
- package/dist/sdk/state.d.ts.map +1 -0
- package/dist/sdk/state.js +28 -0
- package/dist/sdk/state.js.map +1 -0
- package/dist/sdk/utility.d.ts +32 -0
- package/dist/sdk/utility.d.ts.map +1 -0
- package/dist/sdk/utility.js +414 -0
- package/dist/sdk/utility.js.map +1 -0
- package/dist/utils/PwshModel.js +1 -0
- package/dist/utils/PwshModel.js.map +1 -1
- package/dist/utils/SdkModel.d.ts +7 -0
- package/dist/utils/SdkModel.d.ts.map +1 -0
- package/dist/utils/SdkModel.js +17 -0
- package/dist/utils/SdkModel.js.map +1 -0
- package/dist/utils/TrieNode.d.ts +10 -0
- package/dist/utils/TrieNode.d.ts.map +1 -0
- package/dist/utils/TrieNode.js +45 -0
- package/dist/utils/TrieNode.js.map +1 -0
- package/dist/utils/WrapComments.d.ts +2 -0
- package/dist/utils/WrapComments.d.ts.map +1 -0
- package/dist/utils/WrapComments.js +46 -0
- package/dist/utils/WrapComments.js.map +1 -0
- package/dist/utils/code-namer.d.ts +3 -0
- package/dist/utils/code-namer.d.ts.map +1 -0
- package/dist/utils/code-namer.js +38 -0
- package/dist/utils/code-namer.js.map +1 -0
- package/dist/utils/command-operation.d.ts +1 -0
- package/dist/utils/command-operation.d.ts.map +1 -1
- package/dist/utils/command-operation.js +2 -2
- package/dist/utils/command-operation.js.map +1 -1
- package/dist/utils/components.d.ts +2 -0
- package/dist/utils/components.d.ts.map +1 -1
- package/dist/utils/components.js +1 -0
- package/dist/utils/components.js.map +1 -1
- package/dist/utils/extensions.js +1 -0
- package/dist/utils/extensions.js.map +1 -1
- package/dist/utils/http-definitions.js +1 -0
- package/dist/utils/http-definitions.js.map +1 -1
- package/dist/utils/http-operation.js +1 -0
- package/dist/utils/http-operation.js.map +1 -1
- package/dist/utils/info.js +1 -0
- package/dist/utils/info.js.map +1 -1
- package/dist/utils/model-state.js +1 -0
- package/dist/utils/model-state.js.map +1 -1
- package/dist/utils/powershell-comment.js +11 -10
- package/dist/utils/powershell-comment.js.map +1 -1
- package/dist/utils/programatic-operation.js +2 -2
- package/dist/utils/programatic-operation.js.map +1 -1
- package/dist/utils/resolve-conflicts.js +1 -0
- package/dist/utils/resolve-conflicts.js.map +1 -1
- package/dist/utils/schema.d.ts +4 -0
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +28 -0
- package/dist/utils/schema.js.map +1 -1
- package/dist/utils/security-scheme.js +1 -0
- package/dist/utils/security-scheme.js.map +1 -1
- package/dist/utils/uid.js +1 -0
- package/dist/utils/uid.js.map +1 -1
- package/package.json +6 -5
- package/readme.md +5 -1
- package/resources/assets/build-module.ps1 +26 -2
- package/resources/assets/create-model-cmdlets.ps1 +8 -5
- package/resources/assets/custom/README.md +1 -1
- package/resources/assets/docs/README.md +1 -1
- package/resources/assets/exports/README.md +1 -1
- package/resources/assets/generate-portal-ux.ps1 +379 -0
- package/resources/assets/how-to.md +1 -1
- package/resources/assets/internal/README.md +1 -1
- package/resources/assets/tools/Resources/docs/README.md +1 -1
- package/resources/assets/tools/Resources/how-to.md +1 -1
- package/resources/modules/Az.Accounts/2.7.5/Az.Accounts.nuspec +1 -1
- package/resources/modules/Az.Accounts/2.7.5/Az.Accounts.psd1 +1 -1
- package/resources/modules/Az.Accounts/2.7.5/Microsoft.Azure.PowerShell.Cmdlets.Accounts.dll-Help.xml +34 -34
- package/resources/modules/Az.Accounts/2.7.5/en-US/about_az.help.txt +1 -1
- package/resources/modules/Az.Accounts/2.7.5/package/services/metadata/core-properties/1aa0749a068a4238881858013f1a5b7f.psmdcp +1 -1
- package/resources/psruntime/Attributes/ExternalDocsAttribute.cs +30 -0
- package/resources/psruntime/BuildTime/Models/PsMarkdownTypes.cs +39 -4
- package/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs +8 -2
- package/resources/psruntime/BuildTime/Models/PsProxyTypes.cs +6 -0
- package/resources/psruntime/BuildTime/PsAttributes.cs +7 -0
- package/resources/runtime/csharp/client/Context.cs +33 -0
- package/resources/runtime/csharp/client/InfoAttribute.cs +1 -0
- package/resources/runtime/csharp/client/InputHandler.cs +22 -0
- package/resources/runtime/csharp/pipeline/Events.cs +2 -2
- package/resources/templates/azureMethod.ejs +5 -0
- package/resources/templates/azureMethodGroup.ejs +46 -0
- package/resources/templates/azureServiceClient.ejs +80 -0
- package/resources/templates/enum.ejs +73 -0
- package/resources/templates/exception.ejs +52 -0
- package/resources/templates/extensionMethod.ejs +68 -0
- package/resources/templates/extensions.ejs +19 -0
- package/resources/templates/longRunningOperationMethod.ejs +43 -0
- package/resources/templates/method.ejs +65 -0
- package/resources/templates/methodBodyRestCall.ejs +317 -0
- package/resources/templates/methodGroupInterface.ejs +77 -0
- package/resources/templates/model.ejs +184 -0
- package/resources/templates/page.ejs +40 -0
- package/resources/templates/serviceClientBody.ejs +303 -0
- package/resources/templates/serviceClientInterface.ejs +55 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
<%- project.helper.HandleConstParameters(method)%>
|
|
2
|
+
<%# handle x-ms-client-request-id -%>
|
|
3
|
+
<% var clientRequestId = 'x-ms-client-request-id';
|
|
4
|
+
var requestId = 'x-ms-request-id';
|
|
5
|
+
(method.parameters||[]).filter(p => p.protocol.http.in == 'header').forEach(function (parameter) {
|
|
6
|
+
if (parameter.extensions && parameter.extensions['x-ms-client-request-id']) {
|
|
7
|
+
clientRequestId = parameter.language.default.serializedName;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
if (method.extensions && method.extensions['x-ms-request-id']) {
|
|
11
|
+
requestId = method.extensions['x-ms-request-id'];
|
|
12
|
+
}
|
|
13
|
+
-%>
|
|
14
|
+
<%# end of handling x-ms-client-request-id -%>
|
|
15
|
+
<% if(method.language.default.pageable?.nextPageOperation) {-%>
|
|
16
|
+
if (nextPageLink == null)
|
|
17
|
+
{
|
|
18
|
+
throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.CannotBeNull, "nextPageLink");
|
|
19
|
+
}
|
|
20
|
+
<% }else{-%>
|
|
21
|
+
<% (method.requests[0].parameters || []).filter(p=>p.protocol.http.in == 'body').forEach(function(parameter){-%>
|
|
22
|
+
<%if(!(parameter.extensions && parameter.extensions['x-ms-client-flatten'])) {-%>
|
|
23
|
+
<% if (!project.helper.IsValueType(parameter.schema.type) && parameter.required && !project.helper.IsConstantParameter(parameter)) { -%>
|
|
24
|
+
if (<%-parameter.language.default.name%> == null)
|
|
25
|
+
{
|
|
26
|
+
throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.CannotBeNull, "<%-parameter.language.default.name%>");
|
|
27
|
+
}
|
|
28
|
+
<% } -%>
|
|
29
|
+
<%if(method.requests[0].protocol.http.method != 'patch') {-%>
|
|
30
|
+
<%-project.helper.ValidateType(parameter.schema, method, parameter.language.default.name, parameter.nullable)%>
|
|
31
|
+
<%}-%>
|
|
32
|
+
<%}-%>
|
|
33
|
+
<% });-%>
|
|
34
|
+
<% if(method.parameters) { method.parameters.filter(p => (p.schema.type != 'constant' && p.language.default.name != '$host') || p.language.default.name == 'ApiVersion').forEach(function (parameter) {-%>
|
|
35
|
+
<%# ToDo: add check IsNullable with required -%>
|
|
36
|
+
<% var prefix = parameter.implementation == 'Client' ? 'this.Client.' : ''-%>
|
|
37
|
+
<% if ( !(parameter.extensions && parameter.extensions['x-ms-parameter-grouping']) && parameter.required && !project.helper.IsValueType(parameter.schema.type) && !project.helper.IsConstantParameter(parameter)) {-%>
|
|
38
|
+
if (<%-prefix%><%-parameter.language.default.name%> == null)
|
|
39
|
+
{
|
|
40
|
+
throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.CannotBeNull, "<%-prefix%><%-parameter.language.default.name%>");
|
|
41
|
+
}
|
|
42
|
+
<% } -%>
|
|
43
|
+
<%-project.helper.ValidateType(parameter.schema, method, prefix + parameter.language.default.name, parameter.nullable)%>
|
|
44
|
+
<%});}-%>
|
|
45
|
+
<%(method.parameters || []).filter(p => p.protocol.http.in == 'complex').forEach(function(parameter) {-%>
|
|
46
|
+
<%-project.helper.PopulateGroupParameters(parameter)%>
|
|
47
|
+
<%});-%>
|
|
48
|
+
<%# support for p => p.IsConstant && !p.IsClientProperty -%>
|
|
49
|
+
<%(method.parameters || []).filter(p => p.implementation !== 'Client' && p.schema.type === 'constant' && p.required).forEach(function(parameter) {-%>
|
|
50
|
+
<%-project.helper.GetCsharpType(parameter.schema.valueType)%> <%-parameter.language.default.name%> = <%-parameter.schema.valueType.type === 'string' ? '"' + parameter.schema.value.value + '"' : parameter.schema.value.value%>;
|
|
51
|
+
<%});-%>
|
|
52
|
+
<%# ToDo: add support for BuildInputMappings -%>
|
|
53
|
+
<% (method.requests[0].parameters || []).filter(p=>p.protocol.http.in == 'body').forEach(function(parameter){-%>
|
|
54
|
+
<%if(parameter.extensions && parameter.extensions['x-ms-client-flatten']) {-%>
|
|
55
|
+
<%-parameter.schema.language.default.name%> <%-parameter.language.default.name%> = new <%-parameter.schema.language.default.name%>();
|
|
56
|
+
<% var vps = project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties)-%>
|
|
57
|
+
if(<%-vps.map(vp=>`${vp.property.language.default.name} != null`).join('||')%>)
|
|
58
|
+
{
|
|
59
|
+
<%vps.forEach(function(vp) {-%>
|
|
60
|
+
<%-parameter.language.default.name%>.<%-vp.property.language.csharp.name%> = <%-vp.property.language.default.name%>;
|
|
61
|
+
<%});-%>
|
|
62
|
+
}
|
|
63
|
+
<%}-%>
|
|
64
|
+
<% });-%>
|
|
65
|
+
<%}-%>
|
|
66
|
+
// Tracing
|
|
67
|
+
bool _shouldTrace = Microsoft.Rest.ServiceClientTracing.IsEnabled;
|
|
68
|
+
string _invocationId = null;
|
|
69
|
+
if (_shouldTrace)
|
|
70
|
+
{
|
|
71
|
+
_invocationId = Microsoft.Rest.ServiceClientTracing.NextInvocationId.ToString();
|
|
72
|
+
System.Collections.Generic.Dictionary<string, object> tracingParameters = new System.Collections.Generic.Dictionary<string, object>();
|
|
73
|
+
<% if(method.language.default.pageable?.nextPageOperation) {-%>
|
|
74
|
+
tracingParameters.Add("nextPageLink", nextPageLink);
|
|
75
|
+
<% }else{-%>
|
|
76
|
+
<%# ToDo: add support for Model.LogicalParameters.Where(p => !p.IsClientProperty)-%>
|
|
77
|
+
<%method.parameters.filter(p => p.implementation != 'Client' && p.protocol.http.in != 'complex').forEach(function(p) {-%>
|
|
78
|
+
tracingParameters.Add("<%-p.language.default.name%>", <%-p.language.default.name%>);
|
|
79
|
+
<%});-%>
|
|
80
|
+
<%# ToDo: currently we just add the unexpanded body parameter, and need to be fixed in the future %>
|
|
81
|
+
<% (method.requests[0].parameters || []).filter(p =>p.protocol.http.in == 'body').forEach(function (parameter) {-%>
|
|
82
|
+
tracingParameters.Add("<%-parameter.language.default.name%>", <%-parameter.language.default.name%>);
|
|
83
|
+
<% });-%>
|
|
84
|
+
<% }%>
|
|
85
|
+
tracingParameters.Add("cancellationToken", cancellationToken);
|
|
86
|
+
Microsoft.Rest.ServiceClientTracing.Enter(_invocationId, this, "<%-method.language.default.name%>", tracingParameters);
|
|
87
|
+
}
|
|
88
|
+
// Construct URL
|
|
89
|
+
<% if(method.language.default.pageable?.nextPageOperation) {-%>
|
|
90
|
+
string _url = "{nextLink}";
|
|
91
|
+
_url = _url.Replace("{nextLink}", nextPageLink);
|
|
92
|
+
<% }else{%>
|
|
93
|
+
<%# ToDo: may need to support AbsoluteUrl -%>
|
|
94
|
+
var _baseUrl = this.Client.BaseUri.AbsoluteUri;
|
|
95
|
+
<%# ToDo: buildurl, currently only added simple cases, besides we need to handle skip url encoding -%>
|
|
96
|
+
var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "<%-method.requests[0].protocol.http.path.substring(1)%>").ToString();
|
|
97
|
+
<%if (method.parameters) { method.parameters.filter(p => p.protocol.http.in == 'path').forEach(function (pathParameter) {
|
|
98
|
+
var prefix = pathParameter.implementation == 'Client' ? 'this.Client.' : '';
|
|
99
|
+
-%>
|
|
100
|
+
_url = _url.Replace("{<%-pathParameter.language.default.serializedName%>}", <%-project.helper.PathParameterString(pathParameter)%>);
|
|
101
|
+
<% });}-%>
|
|
102
|
+
<% }%>
|
|
103
|
+
System.Collections.Generic.List<string> _queryParameters = new System.Collections.Generic.List<string>();
|
|
104
|
+
<%if (method.parameters && !method.language.default.pageable?.nextPageOperation) { method.parameters.filter(p => p.protocol.http.in == 'query').forEach(function (queryParameter) { -%>
|
|
105
|
+
<% var prefix = queryParameter.implementation == 'Client' ? 'this.Client.' : ''-%>
|
|
106
|
+
<% if (queryParameter.extensions && queryParameter.extensions['x-ms-odata']) {-%>
|
|
107
|
+
if (<%-queryParameter.language.default.name%> != null)
|
|
108
|
+
{
|
|
109
|
+
var _<%-project.helper.CamelCase(queryParameter.schema.language.default.name)%> = <%-queryParameter.language.default.name%>.ToString();
|
|
110
|
+
if (!string.IsNullOrEmpty(_<%-project.helper.CamelCase(queryParameter.schema.language.default.name)%>))
|
|
111
|
+
{
|
|
112
|
+
_queryParameters.Add(_<%-project.helper.CamelCase(queryParameter.schema.language.default.name)%>);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
<% } else {-%>
|
|
116
|
+
if (<%-prefix%><%-queryParameter.language.default.name%> != null)
|
|
117
|
+
{
|
|
118
|
+
_queryParameters.Add(string.Format("<%-queryParameter.language.default.serializedName%>={0}", <%-project.helper.PathParameterString(queryParameter)%>));
|
|
119
|
+
}
|
|
120
|
+
<% }-%>
|
|
121
|
+
<% });}-%>
|
|
122
|
+
if (_queryParameters.Count > 0)
|
|
123
|
+
{
|
|
124
|
+
_url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
|
|
125
|
+
}
|
|
126
|
+
// Create HTTP transport objects
|
|
127
|
+
var _httpRequest = new System.Net.Http.HttpRequestMessage();
|
|
128
|
+
System.Net.Http.HttpResponseMessage _httpResponse = null;
|
|
129
|
+
_httpRequest.Method = new System.Net.Http.HttpMethod("<%-method.requests[0].protocol.http.method.toUpperCase()%>");
|
|
130
|
+
_httpRequest.RequestUri = new System.Uri(_url);
|
|
131
|
+
// Set Headers
|
|
132
|
+
<%# ToDo: Add headers except for following default ones -%>
|
|
133
|
+
if (this.Client.GenerateClientRequestId != null && this.Client.GenerateClientRequestId.Value)
|
|
134
|
+
{
|
|
135
|
+
_httpRequest.Headers.TryAddWithoutValidation("<%-clientRequestId%>", System.Guid.NewGuid().ToString());
|
|
136
|
+
}
|
|
137
|
+
if (this.Client.AcceptLanguage != null)
|
|
138
|
+
{
|
|
139
|
+
if (_httpRequest.Headers.Contains("accept-language"))
|
|
140
|
+
{
|
|
141
|
+
_httpRequest.Headers.Remove("accept-language");
|
|
142
|
+
}
|
|
143
|
+
_httpRequest.Headers.TryAddWithoutValidation("accept-language", this.Client.AcceptLanguage);
|
|
144
|
+
}
|
|
145
|
+
<% (method.parameters || []).filter(p => p.protocol.http.in == 'header').forEach(function(parameter) {
|
|
146
|
+
var prefix = parameter.implementation == 'Client' ? 'this.Client.' : ''-%>
|
|
147
|
+
if (<%-prefix%><%-parameter.language.default.name%> != null)
|
|
148
|
+
{
|
|
149
|
+
if (_httpRequest.Headers.Contains("<%-parameter.language.default.serializedName%>"))
|
|
150
|
+
{
|
|
151
|
+
_httpRequest.Headers.Remove("<%-parameter.language.default.serializedName%>");
|
|
152
|
+
}
|
|
153
|
+
_httpRequest.Headers.TryAddWithoutValidation("<%-parameter.language.default.serializedName%>", <%-prefix%><%-parameter.language.default.name%>);
|
|
154
|
+
}
|
|
155
|
+
<% });-%>
|
|
156
|
+
|
|
157
|
+
if (customHeaders != null)
|
|
158
|
+
{
|
|
159
|
+
foreach(var _header in customHeaders)
|
|
160
|
+
{
|
|
161
|
+
if (_httpRequest.Headers.Contains(_header.Key))
|
|
162
|
+
{
|
|
163
|
+
_httpRequest.Headers.Remove(_header.Key);
|
|
164
|
+
}
|
|
165
|
+
_httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Serialize Request
|
|
169
|
+
string _requestContent = null;
|
|
170
|
+
<%# ToDo: add RequestBody, formdata support-%>
|
|
171
|
+
<% (method.requests[0].parameters || []).filter(p =>p.protocol.http.in == 'body').forEach(function (parameter) {-%>
|
|
172
|
+
<%# ToDo: currently only support for an unexpanded nullable body, need other support in the future -%>
|
|
173
|
+
<% if (!project.helper.IsValueType(parameter.schema.type) && !project.helper.IsConstantParameter(parameter)) {-%>
|
|
174
|
+
if(<%-parameter.language.default.name%> != null)
|
|
175
|
+
{
|
|
176
|
+
_requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(<%-parameter.language.default.name%>, <%-project.helper.GetSerializationSettings(parameter.schema, 'this.Client')%>);
|
|
177
|
+
_httpRequest.Content = new System.Net.Http.StringContent(_requestContent, System.Text.Encoding.UTF8);
|
|
178
|
+
_httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
|
|
179
|
+
}
|
|
180
|
+
<% } else { -%>
|
|
181
|
+
_requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(<%-parameter.language.default.name%>, <%-project.helper.GetSerializationSettings(parameter.schema, 'this.Client')%>);
|
|
182
|
+
_httpRequest.Content = new System.Net.Http.StringContent(_requestContent, System.Text.Encoding.UTF8);
|
|
183
|
+
_httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
|
|
184
|
+
<% } -%>
|
|
185
|
+
<% });-%>
|
|
186
|
+
<%# ToDo: Need to confirm in which case Settings.AddCredentials is false -%>
|
|
187
|
+
// Set Credentials
|
|
188
|
+
if (this.Client.Credentials != null)
|
|
189
|
+
{
|
|
190
|
+
cancellationToken.ThrowIfCancellationRequested();
|
|
191
|
+
await this.Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
|
|
192
|
+
}
|
|
193
|
+
// Send Request
|
|
194
|
+
if (_shouldTrace)
|
|
195
|
+
{
|
|
196
|
+
Microsoft.Rest.ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
|
|
197
|
+
}
|
|
198
|
+
cancellationToken.ThrowIfCancellationRequested();
|
|
199
|
+
<%# ToDo: Add support for primary type return -%>
|
|
200
|
+
<% var responseHeadersRead = method.requests[0].protocol.http.method === 'head' ? 'System.Net.Http.HttpCompletionOption.ResponseHeadersRead, ': '' -%>
|
|
201
|
+
_httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, <%-responseHeadersRead%>cancellationToken).ConfigureAwait(false);
|
|
202
|
+
if (_shouldTrace)
|
|
203
|
+
{
|
|
204
|
+
Microsoft.Rest.ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
System.Net.HttpStatusCode _statusCode = _httpResponse.StatusCode;
|
|
208
|
+
cancellationToken.ThrowIfCancellationRequested();
|
|
209
|
+
string _responseContent = null;
|
|
210
|
+
|
|
211
|
+
if (<%-method.language.default.failureStatusCodePredicate%>)
|
|
212
|
+
{
|
|
213
|
+
var ex = new <%-project.helper.IsCloudErrorException(method) ? 'Microsoft.Rest.Azure.CloudException' : `${method.exceptions[0].schema.language.default.name}Exception`%>(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
|
|
214
|
+
<%# ToDo: not sure whether there is the case that there is no default response(error). If so, we will need to add support for it -%>
|
|
215
|
+
try
|
|
216
|
+
{
|
|
217
|
+
<%# ToDo: Need to add support for primary type -%>
|
|
218
|
+
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
|
|
219
|
+
<%var errorClass = !project.helper.IsCloudErrorException(method) ? method.exceptions[0].schema.language.default.name : 'CloudError'-%>
|
|
220
|
+
<%-errorClass%> _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject<<%-errorClass%>>(_responseContent, this.Client.DeserializationSettings);
|
|
221
|
+
if (_errorBody != null)
|
|
222
|
+
{
|
|
223
|
+
<% if(project.helper.IsCloudErrorException(method)) { -%>
|
|
224
|
+
ex = new Microsoft.Rest.Azure.CloudException(_errorBody.Message);
|
|
225
|
+
<% } -%>
|
|
226
|
+
ex.Body = _errorBody;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (Newtonsoft.Json.JsonException)
|
|
230
|
+
{
|
|
231
|
+
// Ignore the exception
|
|
232
|
+
}
|
|
233
|
+
ex.Request = new Microsoft.Rest.HttpRequestMessageWrapper(_httpRequest, _requestContent);
|
|
234
|
+
ex.Response = new Microsoft.Rest.HttpResponseMessageWrapper(_httpResponse, _responseContent);
|
|
235
|
+
<% if (project.helper.IsCloudErrorException(method)) {-%>
|
|
236
|
+
if (_httpResponse.Headers.Contains("<%-(method.extensions && method.extensions[requestId]) ?? requestId%>"))
|
|
237
|
+
{
|
|
238
|
+
ex.RequestId = _httpResponse.Headers.GetValues("<%-(method.extensions && method.extensions[requestId]) ?? requestId%>").FirstOrDefault();
|
|
239
|
+
}
|
|
240
|
+
<% } -%>
|
|
241
|
+
if (_shouldTrace)
|
|
242
|
+
{
|
|
243
|
+
Microsoft.Rest.ServiceClientTracing.Error(_invocationId, ex);
|
|
244
|
+
}
|
|
245
|
+
_httpRequest.Dispose();
|
|
246
|
+
if (_httpResponse != null)
|
|
247
|
+
{
|
|
248
|
+
_httpResponse.Dispose();
|
|
249
|
+
}
|
|
250
|
+
throw ex;
|
|
251
|
+
}
|
|
252
|
+
// Create Result
|
|
253
|
+
var _result = new <%-method.language.default.responseType%>();
|
|
254
|
+
_result.Request = _httpRequest;
|
|
255
|
+
_result.Response = _httpResponse;
|
|
256
|
+
<%- method.language.default.initializeResponseBody %>
|
|
257
|
+
if (_httpResponse.Headers.Contains("<%-requestId%>"))
|
|
258
|
+
{
|
|
259
|
+
_result.RequestId = _httpResponse.Headers.GetValues("<%-requestId%>").FirstOrDefault();
|
|
260
|
+
}
|
|
261
|
+
<%(method.responses || []).filter(r => r.schema).forEach(function(resp) {-%>
|
|
262
|
+
// Deserialize Response
|
|
263
|
+
if ((int)_statusCode == <%-resp.protocol.http.statusCodes[0]%>)
|
|
264
|
+
{
|
|
265
|
+
<%# ToDo: Need to add support for primary type -%>
|
|
266
|
+
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
|
|
267
|
+
<%# ToDo: support for XmlSerialization, guess we do not need it actually -%>
|
|
268
|
+
try
|
|
269
|
+
{
|
|
270
|
+
<%# ToDo: we assume the return is object, need to add support for other types including support nullable -%>
|
|
271
|
+
<% var respSchema = resp.schema;
|
|
272
|
+
if(resp.schema.type === 'choice' || (resp.schema.type === 'sealed-choice' && (respSchema.schema.choiceType.type != 'string' || (resp.schema.extensions && resp.schema.extensions['x-ms-model-as-string'])))){
|
|
273
|
+
respSchema = resp.schema.choiceType;
|
|
274
|
+
}
|
|
275
|
+
var deserializeType = method.language.default.deserializeType ? method.language.default.deserializeType : respSchema.language.csharp.fullname;
|
|
276
|
+
const postfix = (project.helper.IsValueType(respSchema.type) || project.helper.IsEnum(resp.schema)) ? '?' : '';
|
|
277
|
+
-%>
|
|
278
|
+
_result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject<<%-deserializeType + postfix%>>(_responseContent, <%-project.helper.GetDeserializationSettings(respSchema, 'this.Client')%>);
|
|
279
|
+
}
|
|
280
|
+
catch (Newtonsoft.Json.JsonException ex)
|
|
281
|
+
{
|
|
282
|
+
_httpRequest.Dispose();
|
|
283
|
+
if (_httpResponse != null)
|
|
284
|
+
{
|
|
285
|
+
_httpResponse.Dispose();
|
|
286
|
+
}
|
|
287
|
+
throw new Microsoft.Rest.SerializationException("Unable to deserialize the response.", _responseContent, ex);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
<% });-%>
|
|
291
|
+
<%# ToDo: add support for case Model.ReturnType.Body != null && Model.DefaultResponse.Body != null && !Model.Responses.Any()-%>
|
|
292
|
+
<%# ToDo: add support for case there are return in headers-%>
|
|
293
|
+
<% if (method.language.default.returnTypeHeader.name !== '') { -%>
|
|
294
|
+
try
|
|
295
|
+
{
|
|
296
|
+
_result.Headers = _httpResponse.GetHeadersAsJson().ToObject<<%-method.language.default.returnTypeHeader.name%>>(Newtonsoft.Json.JsonSerializer.Create(this.Client.DeserializationSettings));
|
|
297
|
+
}
|
|
298
|
+
catch (Newtonsoft.Json.JsonException ex)
|
|
299
|
+
{
|
|
300
|
+
_httpRequest.Dispose();
|
|
301
|
+
if (_httpResponse != null)
|
|
302
|
+
{
|
|
303
|
+
_httpResponse.Dispose();
|
|
304
|
+
}
|
|
305
|
+
throw new Microsoft.Rest.SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex);
|
|
306
|
+
}
|
|
307
|
+
<% } -%>
|
|
308
|
+
if (_shouldTrace)
|
|
309
|
+
{
|
|
310
|
+
Microsoft.Rest.ServiceClientTracing.Exit(_invocationId, _result);
|
|
311
|
+
}
|
|
312
|
+
return _result;
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<%- project.commentHeader %>
|
|
2
|
+
<% var key = methodGroup.$key == 'Operations' ? '' : methodGroup.$key-%>
|
|
3
|
+
|
|
4
|
+
namespace <%- project.namespace %>
|
|
5
|
+
{
|
|
6
|
+
<% project.model.usings.forEach(function(using){ -%>
|
|
7
|
+
using <%- using %>;
|
|
8
|
+
<% }); -%>
|
|
9
|
+
|
|
10
|
+
<% var typeName = project.helper.PascalCase(key) + 'Operations' -%>
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// <%- typeName %> operations.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public partial interface I<%- typeName%>
|
|
15
|
+
{
|
|
16
|
+
<% methodGroup.operations.forEach(function(method){ -%>
|
|
17
|
+
<%# ToDo: support for ExcludeFromInterface -%>
|
|
18
|
+
<% if(method.language.default.description) {-%>
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// <%= method.language.default.description%>
|
|
21
|
+
<%# ToDo: support for ExternalDocsUrl -%>
|
|
22
|
+
/// </summary>
|
|
23
|
+
/// <remarks>
|
|
24
|
+
/// <%= method.language.default.description%>
|
|
25
|
+
/// </remarks>
|
|
26
|
+
<% };-%>
|
|
27
|
+
<% if(!method.language.default.pageable?.nextPageOperation) {-%>
|
|
28
|
+
<% method.parameters.filter(p=>p.implementation != 'Client' && !project.helper.IsConstantParameter(p)).forEach(function(parameter){-%>
|
|
29
|
+
/// <param name='<%-parameter.language.default.name%>'>
|
|
30
|
+
/// <%= parameter.language.default.description%>
|
|
31
|
+
/// </param>
|
|
32
|
+
<% }); -%>
|
|
33
|
+
<% (method.requests[0].parameters || []).filter(p=>p.protocol.http.in == 'body' && !project.helper.IsConstantParameter(p)).forEach(function(parameter){-%>
|
|
34
|
+
<%if(parameter.extensions && parameter.extensions['x-ms-client-flatten'] ) {-%>
|
|
35
|
+
<%project.helper.GetAllPublicVirtualProperties(parameter.schema.language.default.virtualProperties).filter(p => !project.helper.IsConstantProperty(p)).forEach(function(vp) {-%>
|
|
36
|
+
/// <param name='<%-vp.property.language.default.name%>'>
|
|
37
|
+
/// <%= vp.property.language.default.description%>
|
|
38
|
+
/// </param>
|
|
39
|
+
<%});-%>
|
|
40
|
+
<%} else {-%>
|
|
41
|
+
/// <param name='<%-parameter.language.default.name%>'>
|
|
42
|
+
/// <%= parameter.language.default.description%>
|
|
43
|
+
/// </param>
|
|
44
|
+
<%}-%>
|
|
45
|
+
<% });-%>
|
|
46
|
+
<% };-%>
|
|
47
|
+
<% if(method.language.default.pageable?.nextPageOperation) {-%>
|
|
48
|
+
/// <param name='nextPageLink'>
|
|
49
|
+
/// The NextLink from the previous successful call to List operation.
|
|
50
|
+
/// </param>
|
|
51
|
+
<% } -%>
|
|
52
|
+
/// <param name='customHeaders'>
|
|
53
|
+
/// The headers that will be added to request.
|
|
54
|
+
/// </param>
|
|
55
|
+
/// <param name='cancellationToken'>
|
|
56
|
+
/// The cancellation token.
|
|
57
|
+
/// </param>
|
|
58
|
+
<%# ToDo: Need to figure out whether we could hand code the exception here -%>
|
|
59
|
+
/// <exception cref="Microsoft.Rest.Azure.CloudException">
|
|
60
|
+
/// Thrown when the operation returned an invalid status code
|
|
61
|
+
/// </exception>
|
|
62
|
+
<% if ((method.responses || []).filter(r => r.schema).length > 0) {-%>
|
|
63
|
+
/// <exception cref="Microsoft.Rest.SerializationException">
|
|
64
|
+
/// Thrown when unable to deserialize the response
|
|
65
|
+
/// </exception>
|
|
66
|
+
<% }; -%>
|
|
67
|
+
<% if (method.parameters.filter(p => p.required && p.nullable).length > 0 || (method.requests[0].parameters || []).filter(p => p.required && p.nullable).length > 0) {-%>
|
|
68
|
+
/// <exception cref="Microsoft.Rest.ValidationException">
|
|
69
|
+
/// Thrown when a required parameter is null
|
|
70
|
+
/// </exception>
|
|
71
|
+
<% }; -%>
|
|
72
|
+
<%# ToDo: support GetObsoleteAttribute, deprecated message?-%>
|
|
73
|
+
System.Threading.Tasks.Task<<%-method.language.default.responseType %>> <%- method.language.default.name%>WithHttpMessagesAsync(<%-method.language.default.asyncMethodParameterDeclarationWithCustomHeader%>);
|
|
74
|
+
|
|
75
|
+
<% }); -%>
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<%- project.commentHeader %>
|
|
2
|
+
|
|
3
|
+
namespace <%- project.namespace %>.Models
|
|
4
|
+
{
|
|
5
|
+
using System.Linq;
|
|
6
|
+
|
|
7
|
+
<%# ToDo: need to populate effectiveDocumentation in the model-%>
|
|
8
|
+
<% if (model.language.default.description) {-%>
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// <%=wrapComments(' ', '/// ', model.language.default.description)%>
|
|
11
|
+
/// </summary>
|
|
12
|
+
<% }-%>
|
|
13
|
+
<% if (model.summary && model.language.default.description) { -%>
|
|
14
|
+
/// <remarks>
|
|
15
|
+
/// <%=wrapComments(' ', '/// ', model.language.default.description)%>
|
|
16
|
+
/// </remarks>
|
|
17
|
+
<% } -%>
|
|
18
|
+
<%# ToDo: support NeedsPolymorphicConverter-%>
|
|
19
|
+
<% if (model.discriminatorValue || model.discriminator) {-%>
|
|
20
|
+
[Newtonsoft.Json.JsonObject("<%-model.discriminatorValue || project.helper.PascalCase(model.language.default.name)%>")]
|
|
21
|
+
<% } -%>
|
|
22
|
+
<% if(project.helper.NeedsTransformationConverter(model)) {-%>
|
|
23
|
+
[Microsoft.Rest.Serialization.JsonTransformation]
|
|
24
|
+
<% }-%>
|
|
25
|
+
<%# ToDo: support ObsoleteAttribute-%>
|
|
26
|
+
public partial class <%-model.language.default.name%><%- (model.extensions && model.extensions["x-ms-azure-resource"]) ? " : Microsoft.Rest.Azure.IResource": (model.parents && model.parents.immediate.length == 1) ? " : " + model.parents.immediate[0].language.default.name: ""%>
|
|
27
|
+
{
|
|
28
|
+
/// <summary>
|
|
29
|
+
/// Initializes a new instance of the <%= model.language.default.name%> class.
|
|
30
|
+
/// </summary>
|
|
31
|
+
public <%- model.language.default.name%>()
|
|
32
|
+
{
|
|
33
|
+
<%#support for object model that contains ContainsConstantProperties-%>
|
|
34
|
+
<% if (model.properties || model.parents) {-%>
|
|
35
|
+
<%project.helper.GetAllPublicVirtualProperties(model.language.default.virtualProperties).filter(p => p.required && p.property.schema.type === 'object' && project.helper.HasConstantProperty(p.property.schema)).forEach(function(p) {-%>
|
|
36
|
+
this.<%-p.name%> = new <%-p.property.schema.language.csharp.fullname%>();
|
|
37
|
+
<%});-%>
|
|
38
|
+
<%}-%>
|
|
39
|
+
CustomInit();
|
|
40
|
+
}
|
|
41
|
+
<%#ToDo support for constructorParameters in the model, the constructorParameter is mapped to properties for the time being%>
|
|
42
|
+
<% if ((model.properties || []).filter(p => !p.isDiscriminator).length > 0 || model.parents) {-%>
|
|
43
|
+
/// <summary>
|
|
44
|
+
/// Initializes a new instance of the <%=model.language.default.name%> class.
|
|
45
|
+
/// </summary>
|
|
46
|
+
<%project.helper.GetAllPublicVirtualProperties(model.language.default.virtualProperties).filter(p => !project.helper.IsConstantProperty(p)).forEach(function(p) {-%>
|
|
47
|
+
<%
|
|
48
|
+
var additionInfo = '';
|
|
49
|
+
if (p.property.schema.type == 'sealed-choice' || p.property.schema.type == 'choice')
|
|
50
|
+
{
|
|
51
|
+
additionInfo = ' Possible values include: ';
|
|
52
|
+
choices = p.property.schema.choices.map(c => `'${c.value}'`);
|
|
53
|
+
additionInfo = additionInfo + choices.join(', ');
|
|
54
|
+
}
|
|
55
|
+
%>
|
|
56
|
+
/// <param name="<%-project.helper.CamelCase(p.name)%>"><%=wrapComments(' ', '/// ', p.property.language.default.description)%>
|
|
57
|
+
/// <%-wrapComments(' ', '/// ', additionInfo)%></param>
|
|
58
|
+
<%});-%>
|
|
59
|
+
public <%- model.language.default.name%>(<%-model.language.default.constructorParametersDeclaration%>)
|
|
60
|
+
<%# If there is only one direct parent, will implement it as parent%>
|
|
61
|
+
<% var publicVirtualProperties = project.helper.GetAllPublicVirtualProperties(model.language.default.virtualProperties);
|
|
62
|
+
if (model.language.default.baseConstructorCall) {
|
|
63
|
+
publicVirtualProperties = project.helper.GetAllPublicVirtualPropertiesWithoutInherited(model.language.default.virtualProperties);
|
|
64
|
+
-%>
|
|
65
|
+
: <%-model.language.default.baseConstructorCall%>
|
|
66
|
+
<%}-%>
|
|
67
|
+
{
|
|
68
|
+
<%#ToDo support for InstanceProperties in the model, non const properties, priority 0-%>
|
|
69
|
+
<%publicVirtualProperties.filter(p => !project.helper.IsConstantProperty(p)).forEach(function(p) {-%>
|
|
70
|
+
this.<%-p.name%> = <%-project.helper.CamelCase(p.name)%>;
|
|
71
|
+
<%});-%>
|
|
72
|
+
CustomInit();
|
|
73
|
+
}
|
|
74
|
+
<% };-%>
|
|
75
|
+
<%#Below is support for ClassProperties in the model, const properties-%>
|
|
76
|
+
<% const constantProperties = (publicVirtualProperties || []).filter(p => p.property.schema.type === 'constant' || project.helper.IsConstantProperty(p));
|
|
77
|
+
if (constantProperties.length > 0) {-%>
|
|
78
|
+
/// <summary>
|
|
79
|
+
/// Static constructor for <%-model.language.default.name%> class.
|
|
80
|
+
/// </summary>
|
|
81
|
+
static <%-model.language.default.name%>()
|
|
82
|
+
{
|
|
83
|
+
<% constantProperties.forEach(function(p) {
|
|
84
|
+
const quote = p.property.schema.choiceType.type !== 'string' ? '' : '"';
|
|
85
|
+
-%>
|
|
86
|
+
<%-p.name%> = <%-quote + p.property.schema.choices[0].value + quote%>;
|
|
87
|
+
<%});-%>
|
|
88
|
+
}
|
|
89
|
+
<% } -%>
|
|
90
|
+
|
|
91
|
+
/// <summary>
|
|
92
|
+
/// An initialization method that performs custom operations like setting defaults
|
|
93
|
+
/// </summary>
|
|
94
|
+
partial void CustomInit();
|
|
95
|
+
|
|
96
|
+
<%#ToDo support for InstanceProperties in the model, non const properties, priority 0, line 407-%>
|
|
97
|
+
<% (publicVirtualProperties || []).filter(p => p.property.schema.type != 'constant' && !project.helper.IsConstantProperty(p)).forEach(function(p){-%>
|
|
98
|
+
<%
|
|
99
|
+
var additionInfo = '';
|
|
100
|
+
if (p.property.schema.type == 'sealed-choice' || p.property.schema.type == 'choice')
|
|
101
|
+
{
|
|
102
|
+
additionInfo = ' Possible values include: ';
|
|
103
|
+
choices = p.property.schema.choices.map(c => `'${c.value}'`);
|
|
104
|
+
additionInfo = additionInfo + choices.join(', ');
|
|
105
|
+
}
|
|
106
|
+
%>
|
|
107
|
+
/// <summary>
|
|
108
|
+
/// <%=wrapComments(' ', '/// ', p.property.language.csharp.formattedPropertySummary)%><%=additionInfo%>
|
|
109
|
+
/// </summary>
|
|
110
|
+
<% (p.property.schema.language.csharp.jsonConverters || []).forEach(function(ct) {-%>
|
|
111
|
+
[Newtonsoft.Json.JsonConverter(typeof(<%-ct%>))]
|
|
112
|
+
<% });-%>
|
|
113
|
+
<% if (model.extensions && model.extensions['x-ms-parameter-grouping']) {-%>
|
|
114
|
+
[Newtonsoft.Json.JsonIgnore]
|
|
115
|
+
<%} else if (p.property.language.default.flavor) {-%>
|
|
116
|
+
<%
|
|
117
|
+
switch(p.property.language.default.flavor) {
|
|
118
|
+
case 'additionalProperties':-%>
|
|
119
|
+
[Newtonsoft.Json.JsonExtensionData]
|
|
120
|
+
<% break;
|
|
121
|
+
default:
|
|
122
|
+
break;
|
|
123
|
+
}-%>
|
|
124
|
+
<% } else {-%>
|
|
125
|
+
[Newtonsoft.Json.JsonProperty(PropertyName = "<%-p.serializedName%>")]
|
|
126
|
+
<% } -%>
|
|
127
|
+
<% var type = p.property.schema.language.csharp.fullname-%>
|
|
128
|
+
<%type = (!project.helper.IsValueType(p.property.schema.type) && !project.helper.IsEnum(p.property.schema) && !(p.property.schema.choiceType && project.helper.IsValueType(p.property.schema.choiceType.type))) || p.required ? type : type + '?'-%>
|
|
129
|
+
public <%-type %> <%-p.name%> {get; <%- p.readOnly ? "private " : ""-%>set; }
|
|
130
|
+
<% }); -%>
|
|
131
|
+
<%#Below is support for ClassProperties in the model, const properties -%>
|
|
132
|
+
<% (publicVirtualProperties || []).filter(p => p.property.schema.type === 'constant' || project.helper.IsConstantProperty(p)).forEach(function(p){-%>
|
|
133
|
+
/// <summary>
|
|
134
|
+
/// <%=p.property.language.csharp.formattedPropertySummary%>
|
|
135
|
+
/// </summary>
|
|
136
|
+
<% (p.property.schema.language.csharp.jsonConverters || []).forEach(function(ct) {-%>
|
|
137
|
+
[Newtonsoft.Json.JsonConverter(typeof(<%-ct%>))]
|
|
138
|
+
<% });-%>
|
|
139
|
+
<% if (model.extensions && model.extensions['x-ms-parameter-grouping']) {-%>
|
|
140
|
+
[Newtonsoft.Json.JsonIgnore]
|
|
141
|
+
<% } else {-%>
|
|
142
|
+
[Newtonsoft.Json.JsonProperty(PropertyName = "<%-p.serializedName%>")]
|
|
143
|
+
<% } -%>
|
|
144
|
+
<% var type = p.property.schema.type === 'constant' ? p.property.schema.language.csharp.fullname : project.helper.GetCsharpType(p.property.schema.choiceType)-%>
|
|
145
|
+
public static <%-type %> <%-p.name%> {get; private set; }
|
|
146
|
+
<%});-%>
|
|
147
|
+
<%#ToDo support for ShouldValidateChain-%>
|
|
148
|
+
<% if (project.helper.ShouldValidateChain(model)) {
|
|
149
|
+
var methodQualifier = model.parents && model.parents.immediate.length == 1 && project.helper.ShouldValidateChain(model.parents.immediate[0]) ? "override" : "virtual";
|
|
150
|
+
var anythingToValidate = false;-%>
|
|
151
|
+
/// <summary>
|
|
152
|
+
/// Validate the object.
|
|
153
|
+
/// </summary>
|
|
154
|
+
/// <exception cref="Microsoft.Rest.ValidationException">
|
|
155
|
+
/// Thrown if validation fails
|
|
156
|
+
/// </exception>
|
|
157
|
+
public <%-methodQualifier%> void Validate()
|
|
158
|
+
{
|
|
159
|
+
<% if (model.parents && model.parents.immediate.length == 1 && project.helper.ShouldValidateChain(model.parents.immediate[0])) {
|
|
160
|
+
anythingToValidate = true;
|
|
161
|
+
-%>
|
|
162
|
+
base.Validate();
|
|
163
|
+
<% } -%>
|
|
164
|
+
<%publicVirtualProperties.filter(p=> p.required && !p.readOnly && !project.helper.IsValueType(p.property.schema.type) && !project.helper.IsConstantProperty(p) && !project.helper.IsEnum(p.property.schema)).forEach(function(p) {
|
|
165
|
+
anythingToValidate = true;
|
|
166
|
+
-%>
|
|
167
|
+
if (this.<%-p.name%> == null)
|
|
168
|
+
{
|
|
169
|
+
throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.CannotBeNull, "<%-p.name%>");
|
|
170
|
+
}
|
|
171
|
+
<%});-%>
|
|
172
|
+
<%publicVirtualProperties.filter(p=> project.helper.HasConstrains(p.property.schema) || !project.helper.IsValueType(p.property.schema.type)).forEach(function(p) {
|
|
173
|
+
anythingToValidate = true;
|
|
174
|
+
-%>
|
|
175
|
+
<%-project.helper.ValidateType(p.property.schema, model, `this.${p.name}`, !project.helper.IsValueType(p.property.schema.type) || !p.required)%>
|
|
176
|
+
<% }); -%>
|
|
177
|
+
<% if(!anythingToValidate) { -%>
|
|
178
|
+
//Nothing to validate
|
|
179
|
+
<% } -%>
|
|
180
|
+
}
|
|
181
|
+
<% } -%>
|
|
182
|
+
<%#ToDo support for ShouldGenerateXmlSerialization, guess we do not need to support it-%>
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<%- project.commentHeader %>
|
|
2
|
+
|
|
3
|
+
namespace <%- project.namespace %>.Models
|
|
4
|
+
{
|
|
5
|
+
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Defines a page in Azure responses.
|
|
8
|
+
/// </summary>
|
|
9
|
+
/// <typeparam name="T">Type of the page content items</typeparam>
|
|
10
|
+
[Newtonsoft.Json.JsonObject]
|
|
11
|
+
public class <%-page.className%><T> : Microsoft.Rest.Azure.IPage<T>
|
|
12
|
+
{
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Gets the link to the next page.
|
|
15
|
+
/// </summary>
|
|
16
|
+
[Newtonsoft.Json.JsonProperty("<%-page.nextLinkName%>")]
|
|
17
|
+
public System.String NextPageLink { get; private set; }
|
|
18
|
+
|
|
19
|
+
[Newtonsoft.Json.JsonProperty("<%-page.itemName%>")]
|
|
20
|
+
private System.Collections.Generic.IList<T> Items{ get; set; }
|
|
21
|
+
|
|
22
|
+
/// <summary>
|
|
23
|
+
/// Returns an enumerator that iterates through the collection.
|
|
24
|
+
/// </summary>
|
|
25
|
+
/// <returns>A an enumerator that can be used to iterate through the collection.</returns>
|
|
26
|
+
public System.Collections.Generic.IEnumerator<T> GetEnumerator()
|
|
27
|
+
{
|
|
28
|
+
return (Items == null) ? System.Linq.Enumerable.Empty<T>().GetEnumerator() : Items.GetEnumerator();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// <summary>
|
|
32
|
+
/// Returns an enumerator that iterates through the collection.
|
|
33
|
+
/// </summary>
|
|
34
|
+
/// <returns>A an enumerator that can be used to iterate through the collection.</returns>
|
|
35
|
+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
36
|
+
{
|
|
37
|
+
return GetEnumerator();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|