@azure-tools/typespec-go 0.8.6 → 0.8.8
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/dist/codegen.go/src/core/clientFactory.d.ts +12 -0
- package/dist/codegen.go/src/core/clientFactory.d.ts.map +1 -0
- package/dist/codegen.go/src/{clientFactory.js → core/clientFactory.js} +21 -13
- package/dist/codegen.go/src/core/clientFactory.js.map +1 -0
- package/dist/codegen.go/src/core/cloudConfig.d.ts +11 -0
- package/dist/codegen.go/src/core/cloudConfig.d.ts.map +1 -0
- package/dist/codegen.go/src/{cloudConfig.js → core/cloudConfig.js} +7 -15
- package/dist/codegen.go/src/core/cloudConfig.js.map +1 -0
- package/dist/codegen.go/src/core/constants.d.ts +9 -0
- package/dist/codegen.go/src/core/constants.d.ts.map +1 -0
- package/dist/codegen.go/src/{constants.js → core/constants.js} +10 -5
- package/dist/codegen.go/src/core/constants.js.map +1 -0
- package/dist/codegen.go/src/{errors.d.ts → core/errors.d.ts} +1 -1
- package/dist/codegen.go/src/core/errors.d.ts.map +1 -0
- package/dist/codegen.go/src/core/errors.js.map +1 -0
- package/dist/codegen.go/src/core/example.d.ts +16 -0
- package/dist/codegen.go/src/core/example.d.ts.map +1 -0
- package/dist/codegen.go/src/{example.js → core/example.js} +78 -47
- package/dist/codegen.go/src/core/example.js.map +1 -0
- package/dist/codegen.go/src/core/gomod.d.ts +12 -0
- package/dist/codegen.go/src/core/gomod.d.ts.map +1 -0
- package/dist/codegen.go/src/{gomod.js → core/gomod.js} +14 -11
- package/dist/codegen.go/src/core/gomod.js.map +1 -0
- package/dist/codegen.go/src/{helpers.d.ts → core/helpers.d.ts} +14 -10
- package/dist/codegen.go/src/core/helpers.d.ts.map +1 -0
- package/dist/codegen.go/src/{helpers.js → core/helpers.js} +40 -48
- package/dist/codegen.go/src/core/helpers.js.map +1 -0
- package/dist/codegen.go/src/core/imports.d.ts +53 -0
- package/dist/codegen.go/src/core/imports.d.ts.map +1 -0
- package/dist/codegen.go/src/core/imports.js +140 -0
- package/dist/codegen.go/src/core/imports.js.map +1 -0
- package/dist/codegen.go/src/core/interfaces.d.ts +9 -0
- package/dist/codegen.go/src/core/interfaces.d.ts.map +1 -0
- package/dist/codegen.go/src/{interfaces.js → core/interfaces.js} +10 -5
- package/dist/codegen.go/src/core/interfaces.js.map +1 -0
- package/dist/codegen.go/src/core/license.d.ts +9 -0
- package/dist/codegen.go/src/core/license.d.ts.map +1 -0
- package/dist/codegen.go/src/{license.js → core/license.js} +4 -13
- package/dist/codegen.go/src/core/license.js.map +1 -0
- package/dist/codegen.go/src/core/metadata.d.ts +3 -0
- package/dist/codegen.go/src/core/metadata.d.ts.map +1 -0
- package/dist/codegen.go/src/core/metadata.js.map +1 -0
- package/dist/codegen.go/src/core/models.d.ts +14 -0
- package/dist/codegen.go/src/core/models.d.ts.map +1 -0
- package/dist/codegen.go/src/{models.js → core/models.js} +177 -92
- package/dist/codegen.go/src/core/models.js.map +1 -0
- package/dist/codegen.go/src/core/operations.d.ts +17 -0
- package/dist/codegen.go/src/core/operations.d.ts.map +1 -0
- package/dist/codegen.go/src/{operations.js → core/operations.js} +51 -44
- package/dist/codegen.go/src/core/operations.js.map +1 -0
- package/dist/codegen.go/src/core/options.d.ts +9 -0
- package/dist/codegen.go/src/core/options.d.ts.map +1 -0
- package/dist/codegen.go/src/{options.js → core/options.js} +24 -11
- package/dist/codegen.go/src/core/options.js.map +1 -0
- package/dist/codegen.go/src/core/polymorphics.d.ts +9 -0
- package/dist/codegen.go/src/core/polymorphics.d.ts.map +1 -0
- package/dist/codegen.go/src/{polymorphics.js → core/polymorphics.js} +21 -14
- package/dist/codegen.go/src/core/polymorphics.js.map +1 -0
- package/dist/codegen.go/src/core/responses.d.ts +14 -0
- package/dist/codegen.go/src/core/responses.d.ts.map +1 -0
- package/dist/codegen.go/src/{responses.js → core/responses.js} +46 -17
- package/dist/codegen.go/src/core/responses.js.map +1 -0
- package/dist/codegen.go/src/core/time.d.ts +14 -0
- package/dist/codegen.go/src/core/time.d.ts.map +1 -0
- package/dist/codegen.go/src/{time.js → core/time.js} +65 -27
- package/dist/codegen.go/src/core/time.js.map +1 -0
- package/dist/codegen.go/src/core/version.d.ts +10 -0
- package/dist/codegen.go/src/core/version.d.ts.map +1 -0
- package/dist/codegen.go/src/{version.js → core/version.js} +4 -12
- package/dist/codegen.go/src/core/version.js.map +1 -0
- package/dist/codegen.go/src/core/xmlAdditionalProps.d.ts +9 -0
- package/dist/codegen.go/src/core/xmlAdditionalProps.d.ts.map +1 -0
- package/dist/codegen.go/src/{xmlAdditionalProps.js → core/xmlAdditionalProps.js} +12 -8
- package/dist/codegen.go/src/core/xmlAdditionalProps.js.map +1 -0
- package/dist/codegen.go/src/emitter.d.ts +42 -0
- package/dist/codegen.go/src/emitter.d.ts.map +1 -0
- package/dist/codegen.go/src/emitter.js +291 -0
- package/dist/codegen.go/src/emitter.js.map +1 -0
- package/dist/codegen.go/src/fake/factory.d.ts +8 -1
- package/dist/codegen.go/src/fake/factory.d.ts.map +1 -1
- package/dist/codegen.go/src/fake/factory.js +19 -10
- package/dist/codegen.go/src/fake/factory.js.map +1 -1
- package/dist/codegen.go/src/fake/internal.d.ts +8 -1
- package/dist/codegen.go/src/fake/internal.d.ts.map +1 -1
- package/dist/codegen.go/src/fake/internal.js +13 -6
- package/dist/codegen.go/src/fake/internal.js.map +1 -1
- package/dist/codegen.go/src/fake/servers.d.ts +7 -1
- package/dist/codegen.go/src/fake/servers.d.ts.map +1 -1
- package/dist/codegen.go/src/fake/servers.js +141 -84
- package/dist/codegen.go/src/fake/servers.js.map +1 -1
- package/dist/codegen.go/src/index.d.ts +4 -0
- package/dist/codegen.go/src/index.d.ts.map +1 -0
- package/dist/codegen.go/src/index.js +8 -0
- package/dist/codegen.go/src/index.js.map +1 -0
- package/dist/codemodel.go/src/client.d.ts +13 -5
- package/dist/codemodel.go/src/client.d.ts.map +1 -1
- package/dist/codemodel.go/src/client.js +9 -5
- package/dist/codemodel.go/src/client.js.map +1 -1
- package/dist/codemodel.go/src/{package.d.ts → codeModel.d.ts} +11 -35
- package/dist/codemodel.go/src/codeModel.d.ts.map +1 -0
- package/dist/codemodel.go/src/codeModel.js +29 -0
- package/dist/codemodel.go/src/codeModel.js.map +1 -0
- package/dist/codemodel.go/src/index.d.ts +3 -2
- package/dist/codemodel.go/src/index.d.ts.map +1 -1
- package/dist/codemodel.go/src/index.js +3 -2
- package/dist/codemodel.go/src/index.js.map +1 -1
- package/dist/codemodel.go/src/module.d.ts +99 -0
- package/dist/codemodel.go/src/module.d.ts.map +1 -0
- package/dist/codemodel.go/src/module.js +75 -0
- package/dist/codemodel.go/src/module.js.map +1 -0
- package/dist/codemodel.go/src/param.d.ts +4 -1
- package/dist/codemodel.go/src/param.d.ts.map +1 -1
- package/dist/codemodel.go/src/param.js +2 -1
- package/dist/codemodel.go/src/param.js.map +1 -1
- package/dist/codemodel.go/src/result.d.ts +1 -0
- package/dist/codemodel.go/src/result.d.ts.map +1 -1
- package/dist/codemodel.go/src/result.js +1 -0
- package/dist/codemodel.go/src/result.js.map +1 -1
- package/dist/codemodel.go/src/type.d.ts +23 -13
- package/dist/codemodel.go/src/type.d.ts.map +1 -1
- package/dist/codemodel.go/src/type.js +50 -28
- package/dist/codemodel.go/src/type.js.map +1 -1
- package/dist/typespec-go/src/emitter.d.ts.map +1 -1
- package/dist/typespec-go/src/emitter.js +39 -168
- package/dist/typespec-go/src/emitter.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/adapter.d.ts +23 -2
- package/dist/typespec-go/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/adapter.js +98 -68
- package/dist/typespec-go/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/clients.d.ts +18 -9
- package/dist/typespec-go/src/tcgcadapter/clients.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/clients.js +160 -110
- package/dist/typespec-go/src/tcgcadapter/clients.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/errors.d.ts +1 -1
- package/dist/typespec-go/src/tcgcadapter/errors.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/errors.js +2 -1
- package/dist/typespec-go/src/tcgcadapter/errors.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/types.d.ts +18 -4
- package/dist/typespec-go/src/tcgcadapter/types.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/types.js +50 -36
- package/dist/typespec-go/src/tcgcadapter/types.js.map +1 -1
- package/package.json +26 -26
- package/dist/codegen.go/src/clientFactory.d.ts +0 -3
- package/dist/codegen.go/src/clientFactory.d.ts.map +0 -1
- package/dist/codegen.go/src/clientFactory.js.map +0 -1
- package/dist/codegen.go/src/cloudConfig.d.ts +0 -10
- package/dist/codegen.go/src/cloudConfig.d.ts.map +0 -1
- package/dist/codegen.go/src/cloudConfig.js.map +0 -1
- package/dist/codegen.go/src/constants.d.ts +0 -3
- package/dist/codegen.go/src/constants.d.ts.map +0 -1
- package/dist/codegen.go/src/constants.js.map +0 -1
- package/dist/codegen.go/src/errors.d.ts.map +0 -1
- package/dist/codegen.go/src/errors.js.map +0 -1
- package/dist/codegen.go/src/example.d.ts +0 -8
- package/dist/codegen.go/src/example.d.ts.map +0 -1
- package/dist/codegen.go/src/example.js.map +0 -1
- package/dist/codegen.go/src/gomod.d.ts +0 -3
- package/dist/codegen.go/src/gomod.d.ts.map +0 -1
- package/dist/codegen.go/src/gomod.js.map +0 -1
- package/dist/codegen.go/src/helpers.d.ts.map +0 -1
- package/dist/codegen.go/src/helpers.js.map +0 -1
- package/dist/codegen.go/src/imports.d.ts +0 -11
- package/dist/codegen.go/src/imports.d.ts.map +0 -1
- package/dist/codegen.go/src/imports.js +0 -65
- package/dist/codegen.go/src/imports.js.map +0 -1
- package/dist/codegen.go/src/interfaces.d.ts +0 -3
- package/dist/codegen.go/src/interfaces.d.ts.map +0 -1
- package/dist/codegen.go/src/interfaces.js.map +0 -1
- package/dist/codegen.go/src/license.d.ts +0 -10
- package/dist/codegen.go/src/license.d.ts.map +0 -1
- package/dist/codegen.go/src/license.js.map +0 -1
- package/dist/codegen.go/src/metadata.d.ts +0 -3
- package/dist/codegen.go/src/metadata.d.ts.map +0 -1
- package/dist/codegen.go/src/metadata.js.map +0 -1
- package/dist/codegen.go/src/models.d.ts +0 -8
- package/dist/codegen.go/src/models.d.ts.map +0 -1
- package/dist/codegen.go/src/models.js.map +0 -1
- package/dist/codegen.go/src/operations.d.ts +0 -9
- package/dist/codegen.go/src/operations.d.ts.map +0 -1
- package/dist/codegen.go/src/operations.js.map +0 -1
- package/dist/codegen.go/src/options.d.ts +0 -3
- package/dist/codegen.go/src/options.d.ts.map +0 -1
- package/dist/codegen.go/src/options.js.map +0 -1
- package/dist/codegen.go/src/polymorphics.d.ts +0 -3
- package/dist/codegen.go/src/polymorphics.d.ts.map +0 -1
- package/dist/codegen.go/src/polymorphics.js.map +0 -1
- package/dist/codegen.go/src/responses.d.ts +0 -7
- package/dist/codegen.go/src/responses.d.ts.map +0 -1
- package/dist/codegen.go/src/responses.js.map +0 -1
- package/dist/codegen.go/src/time.d.ts +0 -8
- package/dist/codegen.go/src/time.d.ts.map +0 -1
- package/dist/codegen.go/src/time.js.map +0 -1
- package/dist/codegen.go/src/version.d.ts +0 -10
- package/dist/codegen.go/src/version.d.ts.map +0 -1
- package/dist/codegen.go/src/version.js.map +0 -1
- package/dist/codegen.go/src/xmlAdditionalProps.d.ts +0 -3
- package/dist/codegen.go/src/xmlAdditionalProps.d.ts.map +0 -1
- package/dist/codegen.go/src/xmlAdditionalProps.js.map +0 -1
- package/dist/codemodel.go/src/package.d.ts.map +0 -1
- package/dist/codemodel.go/src/package.js +0 -78
- package/dist/codemodel.go/src/package.js.map +0 -1
- /package/dist/codegen.go/src/{errors.js → core/errors.js} +0 -0
- /package/dist/codegen.go/src/{metadata.js → core/metadata.js} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as go from '../../../codemodel.go/src/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the content for client_factory.go file.
|
|
4
|
+
* For non-ARM targets, the empty string is returned.
|
|
5
|
+
*
|
|
6
|
+
* @param pkg contains the package content
|
|
7
|
+
* @param target the codegen target for the package
|
|
8
|
+
* @param options the emitter options
|
|
9
|
+
* @returns the text for the file or the empty string
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateClientFactory(pkg: go.PackageContent, target: go.CodeModelType, options: go.Options): string;
|
|
12
|
+
//# sourceMappingURL=clientFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientFactory.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/core/clientFactory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAIzD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,MAAM,CAiHnH"}
|
|
@@ -2,24 +2,32 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import * as go from '
|
|
5
|
+
import * as go from '../../../codemodel.go/src/index.js';
|
|
6
6
|
import * as helpers from './helpers.js';
|
|
7
7
|
import { ImportManager } from './imports.js';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Creates the content for client_factory.go file.
|
|
10
|
+
* For non-ARM targets, the empty string is returned.
|
|
11
|
+
*
|
|
12
|
+
* @param pkg contains the package content
|
|
13
|
+
* @param target the codegen target for the package
|
|
14
|
+
* @param options the emitter options
|
|
15
|
+
* @returns the text for the file or the empty string
|
|
16
|
+
*/
|
|
17
|
+
export function generateClientFactory(pkg, target, options) {
|
|
10
18
|
// generate client factory only for ARM
|
|
11
|
-
if (
|
|
19
|
+
if (target !== 'azure-arm' || pkg.clients.length === 0) {
|
|
12
20
|
return '';
|
|
13
21
|
}
|
|
14
22
|
let result = '';
|
|
15
23
|
// the list of packages to import
|
|
16
|
-
const imports = new ImportManager();
|
|
24
|
+
const imports = new ImportManager(pkg);
|
|
17
25
|
let clientFactoryParams;
|
|
18
|
-
if (
|
|
19
|
-
clientFactoryParams = helpers.getAllClientParameters(
|
|
26
|
+
if (options.factoryGatherAllParams) {
|
|
27
|
+
clientFactoryParams = helpers.getAllClientParameters(pkg, target);
|
|
20
28
|
}
|
|
21
29
|
else {
|
|
22
|
-
clientFactoryParams = helpers.getCommonClientParameters(
|
|
30
|
+
clientFactoryParams = helpers.getCommonClientParameters(pkg, target);
|
|
23
31
|
}
|
|
24
32
|
const clientFactoryParamsMap = new Map();
|
|
25
33
|
for (const param of clientFactoryParams) {
|
|
@@ -35,7 +43,7 @@ export async function generateClientFactory(codeModel) {
|
|
|
35
43
|
// credentials aren't persisted on the client
|
|
36
44
|
continue;
|
|
37
45
|
}
|
|
38
|
-
result += `\t${clientParam.name} ${helpers.formatParameterTypeName(clientParam)}\n`;
|
|
46
|
+
result += `\t${clientParam.name} ${helpers.formatParameterTypeName(pkg, clientParam)}\n`;
|
|
39
47
|
}
|
|
40
48
|
result += '\tinternal *arm.Client\n';
|
|
41
49
|
result += '}\n\n';
|
|
@@ -48,7 +56,7 @@ export async function generateClientFactory(codeModel) {
|
|
|
48
56
|
}
|
|
49
57
|
result += helpers.formatCommentAsBulletItem('credential', { summary: 'used to authorize requests. Usually a credential from azidentity.' });
|
|
50
58
|
result += helpers.formatCommentAsBulletItem('options', { summary: 'pass nil to accept the default values.' });
|
|
51
|
-
result += `func NewClientFactory(${clientFactoryParams.map(param => { return `${param.name} ${helpers.formatParameterTypeName(param)}`; }).join(', ')}${clientFactoryParams.length > 0 ? ',' : ''} options *arm.ClientOptions) (*ClientFactory, error) {\n`;
|
|
59
|
+
result += `func NewClientFactory(${clientFactoryParams.map(param => { return `${param.name} ${helpers.formatParameterTypeName(pkg, param)}`; }).join(', ')}${clientFactoryParams.length > 0 ? ',' : ''} options *arm.ClientOptions) (*ClientFactory, error) {\n`;
|
|
52
60
|
result += '\tinternal, err := arm.NewClient(moduleName, moduleVersion, credential, options)\n';
|
|
53
61
|
result += '\tif err != nil {\n';
|
|
54
62
|
result += '\t\treturn nil, err\n';
|
|
@@ -65,7 +73,7 @@ export async function generateClientFactory(codeModel) {
|
|
|
65
73
|
result += '\t}, nil\n';
|
|
66
74
|
result += '}\n\n';
|
|
67
75
|
// add new sub client method for all operation groups
|
|
68
|
-
for (const client of
|
|
76
|
+
for (const client of pkg.clients) {
|
|
69
77
|
const clientPrivateParams = new Array();
|
|
70
78
|
const clientCommonParams = new Array();
|
|
71
79
|
if (client.instance?.kind === 'constructable') {
|
|
@@ -88,7 +96,7 @@ export async function generateClientFactory(codeModel) {
|
|
|
88
96
|
result += `func (c *ClientFactory) ${ctorName}(`;
|
|
89
97
|
if (clientPrivateParams.length > 0) {
|
|
90
98
|
result += `${clientPrivateParams.map(param => {
|
|
91
|
-
return `${param.name} ${helpers.formatParameterTypeName(param)}`;
|
|
99
|
+
return `${param.name} ${helpers.formatParameterTypeName(pkg, param)}`;
|
|
92
100
|
}).join(', ')}`;
|
|
93
101
|
}
|
|
94
102
|
result += `) *${client.name} {\n`;
|
|
@@ -108,7 +116,7 @@ export async function generateClientFactory(codeModel) {
|
|
|
108
116
|
result += '\t}\n';
|
|
109
117
|
result += '}\n\n';
|
|
110
118
|
}
|
|
111
|
-
result = helpers.contentPreamble(
|
|
119
|
+
result = helpers.contentPreamble(pkg) + imports.text() + result;
|
|
112
120
|
return result;
|
|
113
121
|
}
|
|
114
122
|
//# sourceMappingURL=clientFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientFactory.js","sourceRoot":"","sources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ACjD,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;gBAC3C,OAAO,GAAG,KAAK,CAAC,IAAI,IAAI,OAAO,CAAC,uBAAuB,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;YACxE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,MAAM,MAAM,CAAC,IAAI,MAAM,CAAC;QAClC,MAAM,IAAI,aAAa,MAAM,CAAC,IAAI,KAAK,CAAC;QAExC,wEAAwE;QACxE,KAAK,MAAM,WAAW,IAAI,mBAAmB,EAAE,CAAC;YAC9C,MAAM,IAAI,OAAO,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,KAAK,CAAC;QAC9D,CAAC;QAED,KAAK,MAAM,WAAW,IAAI,kBAAkB,EAAE,CAAC;YAC7C,IAAI,WAAW,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;gBAC3C,6CAA6C;gBAC7C,SAAS;YACX,CAAC;YACD,MAAM,IAAI,OAAO,WAAW,CAAC,IAAI,OAAO,WAAW,CAAC,IAAI,KAAK,CAAC;QAChE,CAAC;QAED,MAAM,IAAI,6BAA6B,CAAC;QACxC,MAAM,IAAI,OAAO,CAAC;QAClB,MAAM,IAAI,OAAO,CAAC;IACpB,CAAC;IAED,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC;IAChE,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as go from '../../../codemodel.go/src/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* generates the contents for the cloud_config.go file.
|
|
4
|
+
* if cloud config info isn't required, the empty string is returned.
|
|
5
|
+
*
|
|
6
|
+
* @param module the module for which to generate the file
|
|
7
|
+
* @param target the codegen target for the module
|
|
8
|
+
* @returns the text for the file or the empty string
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateCloudConfig(module: go.Module, target: go.CodeModelType): string;
|
|
11
|
+
//# sourceMappingURL=cloudConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudConfig.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/core/cloudConfig.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,aAAa,GAAG,MAAM,CAsDvF"}
|
|
@@ -7,17 +7,18 @@ import * as helpers from './helpers.js';
|
|
|
7
7
|
* generates the contents for the cloud_config.go file.
|
|
8
8
|
* if cloud config info isn't required, the empty string is returned.
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
10
|
+
* @param module the module for which to generate the file
|
|
11
|
+
* @param target the codegen target for the module
|
|
11
12
|
* @returns the text for the file or the empty string
|
|
12
13
|
*/
|
|
13
|
-
export function generateCloudConfig(
|
|
14
|
-
if (
|
|
14
|
+
export function generateCloudConfig(module, target) {
|
|
15
|
+
if (target === 'azure-arm') {
|
|
15
16
|
// this is handled in azcore
|
|
16
17
|
return '';
|
|
17
18
|
}
|
|
18
19
|
// check if this SDK uses token auth
|
|
19
20
|
let tokenCred;
|
|
20
|
-
for (const client of
|
|
21
|
+
for (const client of module.clients) {
|
|
21
22
|
if (client.instance?.kind !== 'constructable') {
|
|
22
23
|
continue;
|
|
23
24
|
}
|
|
@@ -40,19 +41,10 @@ export function generateCloudConfig(codeModel) {
|
|
|
40
41
|
// cloud config is only required for token auth
|
|
41
42
|
return '';
|
|
42
43
|
}
|
|
43
|
-
let cloudConfig = helpers.contentPreamble(
|
|
44
|
+
let cloudConfig = helpers.contentPreamble(module);
|
|
44
45
|
cloudConfig += 'import "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"\n\n';
|
|
45
46
|
cloudConfig += '// ServiceName is the [cloud.ServiceName] for this module, used to identify the respective [cloud.ServiceConfiguration].\n';
|
|
46
|
-
let serviceName;
|
|
47
|
-
if (codeModel.options.module) {
|
|
48
|
-
serviceName = codeModel.options.module;
|
|
49
|
-
}
|
|
50
|
-
else if (codeModel.options.containingModule) {
|
|
51
|
-
serviceName = `${codeModel.options.containingModule}/${codeModel.packageName}`;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
throw new Error('unreachable');
|
|
55
|
-
}
|
|
47
|
+
let serviceName = module.identity;
|
|
56
48
|
const azureSdkPrefix = 'github.com/Azure/azure-sdk-for-go/sdk/';
|
|
57
49
|
if (serviceName.startsWith(azureSdkPrefix)) {
|
|
58
50
|
serviceName = serviceName.substring(azureSdkPrefix.length);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudConfig.js","sourceRoot":"","sources":["../../../../../codegen.go/src/core/cloudConfig.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAGxC;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,MAAwB;IAC7E,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;QAC3B,4BAA4B;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,oCAAoC;IACpC,IAAI,SAAyC,CAAC;IAC9C,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,IAAI,MAAM,CAAC,QAAQ,EAAE,IAAI,KAAK,eAAe,EAAE,CAAC;YAC9C,SAAS;QACX,CAAC;QACD,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;YACvD,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,UAAU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Creates the content for the constants.go file.
|
|
4
|
+
*
|
|
5
|
+
* @param pkg contains the package content
|
|
6
|
+
* @returns the text for the file or the empty string
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateConstants(pkg: go.PackageContent): string;
|
|
9
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/core/constants.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,GAAG,MAAM,CAgChE"}
|
|
@@ -4,13 +4,18 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { values } from '@azure-tools/linq';
|
|
6
6
|
import * as helpers from './helpers.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Creates the content for the constants.go file.
|
|
9
|
+
*
|
|
10
|
+
* @param pkg contains the package content
|
|
11
|
+
* @returns the text for the file or the empty string
|
|
12
|
+
*/
|
|
13
|
+
export function generateConstants(pkg) {
|
|
14
|
+
if (pkg.constants.length === 0) {
|
|
10
15
|
return '';
|
|
11
16
|
}
|
|
12
|
-
let text = helpers.contentPreamble(
|
|
13
|
-
for (const enm of values(
|
|
17
|
+
let text = helpers.contentPreamble(pkg);
|
|
18
|
+
for (const enm of values(pkg.constants)) {
|
|
14
19
|
text += helpers.formatDocCommentWithPrefix(enm.name, enm.docs);
|
|
15
20
|
text += `type ${enm.name} ${enm.type}\n\n`;
|
|
16
21
|
const vals = new Array();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../codegen.go/src/core/constants.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,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,gBAAgB,CAAC;QACjG,IAAI,IAAI,QAAQ,GAAG,CAAC,cAAc,QAAQ,GAAG,CAAC,IAAI,MAAM,CAAC;QACzD,IAAI,IAAI,cAAc,GAAG,CAAC,IAAI,OAAO,CAAC;QACtC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,IAAI,IAAI,OAAO,GAAG,KAAK,CAAC;QAC1B,CAAC;QACD,IAAI,IAAI,OAAO,CAAC;QAChB,IAAI,IAAI,OAAO,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/core/errors.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAEhE;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;gBAEb,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;CAI7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../codegen.go/src/core/errors.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAI/F;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAY;IAEzB,YAAY,IAAe,EAAE,OAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as go from '../../../codemodel.go/src/index.js';
|
|
2
|
+
export declare class ExampleContent {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly content: string;
|
|
5
|
+
constructor(name: string, content: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates the content for all the *_example_test.go files.
|
|
9
|
+
*
|
|
10
|
+
* @param pkg contains the package content
|
|
11
|
+
* @param target the codegen target for the module
|
|
12
|
+
* @param options the emitter options
|
|
13
|
+
* @returns the text for the files or the empty string
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateExamples(pkg: go.TestPackage, target: go.CodeModelType, options: go.Options): Array<ExampleContent>;
|
|
16
|
+
//# sourceMappingURL=example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/core/example.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAOzD,qBAAa,cAAc;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI1C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,CAAC,cAAc,CAAC,CA6M1H"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { camelCase, capitalize } from '@azure-tools/codegen';
|
|
6
|
-
import * as go from '
|
|
6
|
+
import * as go from '../../../codemodel.go/src/index.js';
|
|
7
7
|
import * as helpers from './helpers.js';
|
|
8
8
|
import { ImportManager } from './imports.js';
|
|
9
9
|
import { fixUpMethodName } from './operations.js';
|
|
@@ -17,20 +17,27 @@ export class ExampleContent {
|
|
|
17
17
|
this.content = content;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Creates the content for all the *_example_test.go files.
|
|
22
|
+
*
|
|
23
|
+
* @param pkg contains the package content
|
|
24
|
+
* @param target the codegen target for the module
|
|
25
|
+
* @param options the emitter options
|
|
26
|
+
* @returns the text for the files or the empty string
|
|
27
|
+
*/
|
|
28
|
+
export function generateExamples(pkg, target, options) {
|
|
22
29
|
// generate examples
|
|
23
30
|
const examples = new Array();
|
|
24
|
-
if (
|
|
31
|
+
if (pkg.src.clients.length === 0) {
|
|
25
32
|
return examples;
|
|
26
33
|
}
|
|
27
|
-
const azureARM =
|
|
28
|
-
for (const client of
|
|
34
|
+
const azureARM = target === 'azure-arm';
|
|
35
|
+
for (const client of pkg.src.clients) {
|
|
29
36
|
// client must be constructable to create a sample
|
|
30
37
|
if (client.instance?.kind != 'constructable') {
|
|
31
38
|
continue;
|
|
32
39
|
}
|
|
33
|
-
const imports = new ImportManager();
|
|
40
|
+
const imports = new ImportManager(pkg);
|
|
34
41
|
// the list of packages to import
|
|
35
42
|
if (client.methods.length > 0) {
|
|
36
43
|
// add standard imports for clients with methods.
|
|
@@ -38,14 +45,14 @@ export async function generateExamples(codeModel) {
|
|
|
38
45
|
imports.add('context');
|
|
39
46
|
imports.add('log');
|
|
40
47
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azidentity');
|
|
41
|
-
imports.
|
|
48
|
+
imports.addForPkg(pkg.src);
|
|
42
49
|
}
|
|
43
50
|
let clientFactoryParams = new Array();
|
|
44
|
-
if (
|
|
45
|
-
clientFactoryParams = helpers.getAllClientParameters(
|
|
51
|
+
if (options.factoryGatherAllParams) {
|
|
52
|
+
clientFactoryParams = helpers.getAllClientParameters(pkg.src, target);
|
|
46
53
|
}
|
|
47
54
|
else {
|
|
48
|
-
clientFactoryParams = helpers.getCommonClientParameters(
|
|
55
|
+
clientFactoryParams = helpers.getCommonClientParameters(pkg.src, target);
|
|
49
56
|
}
|
|
50
57
|
const clientFactoryParamsMap = new Map();
|
|
51
58
|
for (const param of clientFactoryParams) {
|
|
@@ -91,7 +98,7 @@ export async function generateExamples(codeModel) {
|
|
|
91
98
|
clientFactoryParamsExample.push({ parameter: clientParam, value: generateFakeExample(clientParam.type, clientParam.name) });
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
|
-
exampleText += `\tclientFactory, err := ${
|
|
101
|
+
exampleText += `\tclientFactory, err := ${go.getPackageName(pkg.src)}.NewClientFactory(${clientFactoryParamsExample.map(p => getExampleValue(pkg, p.value, '\t', imports, p.parameter.byValue)).join(', ')}, nil)\n`;
|
|
95
102
|
exampleText += `\tif err != nil {\n`;
|
|
96
103
|
exampleText += `\t\tlog.Fatalf("failed to create client: %v", err)\n`;
|
|
97
104
|
exampleText += `\t}\n`;
|
|
@@ -103,12 +110,12 @@ export async function generateExamples(codeModel) {
|
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
112
|
if (clientPrivateParameters.length > 0) {
|
|
106
|
-
clientRef += `${clientPrivateParameters.map(p => getExampleValue(
|
|
113
|
+
clientRef += `${clientPrivateParameters.map(p => getExampleValue(pkg, p.value, '\t', imports, p.parameter.byValue).slice(1)).join(', ')}`;
|
|
107
114
|
}
|
|
108
115
|
clientRef += `)`;
|
|
109
116
|
}
|
|
110
117
|
else {
|
|
111
|
-
exampleText += `\tclient, err := ${
|
|
118
|
+
exampleText += `\tclient, err := ${go.getPackageName(client.instance.constructors[0].pkg)}.${client.instance.constructors[0].name}(${clientParameters.map(p => getExampleValue(pkg, p.value, '\t', imports, p.parameter.byValue).slice(1)).join(', ')}, cred, nil)\n`;
|
|
112
119
|
exampleText += `\tif err != nil {\n`;
|
|
113
120
|
exampleText += `\t\tlog.Fatalf("failed to create client: %v", err)\n`;
|
|
114
121
|
exampleText += `\t}\n`;
|
|
@@ -122,20 +129,24 @@ export async function generateExamples(codeModel) {
|
|
|
122
129
|
if (methodParam) {
|
|
123
130
|
methodParameters.push(methodParam);
|
|
124
131
|
}
|
|
132
|
+
else if (go.isRequiredParameter(param.style)) {
|
|
133
|
+
// if the parameter is required but lacks example value, generate a fake example
|
|
134
|
+
methodParameters.push({ parameter: param, value: generateFakeExample(param.type, param.name) });
|
|
135
|
+
}
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
138
|
const methodOptionalParameters = example.optionalParamsGroup.filter(p => p.parameter.location === 'method');
|
|
128
139
|
const checkResponse = example.responseEnvelope !== undefined;
|
|
129
140
|
let methodOptionalParametersText = 'nil';
|
|
130
141
|
if (methodOptionalParameters.length > 0) {
|
|
131
|
-
methodOptionalParametersText = `&${
|
|
132
|
-
methodOptionalParametersText += methodOptionalParameters.map(p => `${capitalize(p.parameter.name)}: ${getExampleValue(
|
|
142
|
+
methodOptionalParametersText = `&${go.getPackageName(method.optionalParamsGroup.pkg)}.${method.optionalParamsGroup.groupName}{\n`;
|
|
143
|
+
methodOptionalParametersText += methodOptionalParameters.map(p => `${capitalize(p.parameter.name)}: ${getExampleValue(pkg, p.value, '\t', imports, p.parameter.byValue).slice(1)}`).join(',\n');
|
|
133
144
|
methodOptionalParametersText += `}`;
|
|
134
145
|
}
|
|
135
146
|
switch (method.kind) {
|
|
136
147
|
case 'lroMethod':
|
|
137
148
|
case 'lroPageableMethod':
|
|
138
|
-
exampleText += `\tpoller, err := ${clientRef}.${fixUpMethodName(method)}(ctx, ${methodParameters.map(p => getExampleValue(
|
|
149
|
+
exampleText += `\tpoller, err := ${clientRef}.${fixUpMethodName(method)}(ctx, ${methodParameters.map(p => getExampleValue(pkg, p.value, '\t', imports, p.parameter.byValue).slice(1)).join(', ')}${methodParameters.length > 0 ? ', ' : ''}${methodOptionalParametersText.split('\n').join('\n\t')})\n`;
|
|
139
150
|
exampleText += `\tif err != nil {\n`;
|
|
140
151
|
exampleText += `\t\tlog.Fatalf("failed to finish the request: %v", err)\n`;
|
|
141
152
|
exampleText += `\t}\n`;
|
|
@@ -145,19 +156,19 @@ export async function generateExamples(codeModel) {
|
|
|
145
156
|
exampleText += `\t}\n`;
|
|
146
157
|
break;
|
|
147
158
|
case 'method':
|
|
148
|
-
exampleText += `\t${checkResponse ? 'res' : '_'}, err ${checkResponse ? ':=' : '='} ${clientRef}.${fixUpMethodName(method)}(ctx, ${methodParameters.map(p => getExampleValue(
|
|
159
|
+
exampleText += `\t${checkResponse ? 'res' : '_'}, err ${checkResponse ? ':=' : '='} ${clientRef}.${fixUpMethodName(method)}(ctx, ${methodParameters.map(p => getExampleValue(pkg, p.value, '\t', imports, p.parameter.byValue).slice(1)).join(', ')}${methodParameters.length > 0 ? ', ' : ''}${methodOptionalParametersText.split('\n').join('\n\t')})\n`;
|
|
149
160
|
exampleText += `\tif err != nil {\n`;
|
|
150
161
|
exampleText += `\t\tlog.Fatalf("failed to finish the request: %v", err)\n`;
|
|
151
162
|
exampleText += `\t}\n`;
|
|
152
163
|
break;
|
|
153
164
|
case 'pageableMethod':
|
|
154
|
-
exampleText += `\tpager := ${clientRef}.${fixUpMethodName(method)}(${methodParameters.map(p => getExampleValue(
|
|
165
|
+
exampleText += `\tpager := ${clientRef}.${fixUpMethodName(method)}(${methodParameters.map(p => getExampleValue(pkg, p.value, '\t', imports, p.parameter.byValue).slice(1)).join(', ')}${methodParameters.length > 0 ? ', ' : ''}${methodOptionalParametersText.split('\n').join('\n\t')})\n`;
|
|
155
166
|
break;
|
|
156
167
|
default:
|
|
157
168
|
method;
|
|
158
169
|
}
|
|
159
170
|
// check response
|
|
160
|
-
if (method.kind === 'lroPageableMethod' || method.kind === 'pageableMethod') {
|
|
171
|
+
if ((method.kind === 'lroPageableMethod' || method.kind === 'pageableMethod') && example.responseEnvelope) {
|
|
161
172
|
let resultName = 'pager';
|
|
162
173
|
if (method.kind === 'lroPageableMethod') {
|
|
163
174
|
resultName = 'res';
|
|
@@ -173,26 +184,26 @@ export async function generateExamples(codeModel) {
|
|
|
173
184
|
exampleText += `\t\t\t_ = v\n`;
|
|
174
185
|
exampleText += `\t\t}\n`;
|
|
175
186
|
exampleText += `\t\t// If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.\n`;
|
|
176
|
-
exampleText += `\t\t// page = ${
|
|
177
|
-
for (const header of example.responseEnvelope
|
|
178
|
-
exampleText += `\t\t// \t${header.header.fieldName}: ${getExampleValue(
|
|
187
|
+
exampleText += `\t\t// page = ${go.getPackageName(example.responseEnvelope.response.method.receiver.type.pkg)}.${example.responseEnvelope.response.name}{\n`;
|
|
188
|
+
for (const header of example.responseEnvelope.headers ?? []) {
|
|
189
|
+
exampleText += `\t\t// \t${header.header.fieldName}: ${getExampleValue(pkg, header.value, '', undefined, true).split('\n').join('\n\t\t// \t')}\n`;
|
|
179
190
|
}
|
|
180
|
-
exampleText += `\t\t// \t${
|
|
191
|
+
exampleText += `\t\t// \t${example.responseEnvelope.result.type.name}: ${getExampleValue(pkg, example.responseEnvelope.result, '', undefined, true).split('\n').join('\n\t\t// \t')},\n`;
|
|
181
192
|
exampleText += '\t\t// }\n';
|
|
182
193
|
exampleText += `\t}\n`;
|
|
183
194
|
}
|
|
184
|
-
else if (
|
|
195
|
+
else if (example.responseEnvelope) {
|
|
185
196
|
// if has fieldName, then the result is not a model type
|
|
186
197
|
const fieldName = method.returns.fieldName;
|
|
187
198
|
exampleText += `\t// You could use response here. We use blank identifier for just demo purposes.\n`;
|
|
188
199
|
exampleText += `\t_ = res\n`;
|
|
189
200
|
exampleText += `\t// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.\n`;
|
|
190
|
-
exampleText += `\t// res = ${
|
|
201
|
+
exampleText += `\t// res = ${go.getPackageName(example.responseEnvelope.response.method.receiver.type.pkg)}.${example.responseEnvelope.response.name}{\n`;
|
|
191
202
|
for (const header of example.responseEnvelope?.headers ?? []) {
|
|
192
|
-
exampleText += `\t// \t${header.header.fieldName}: ${getExampleValue(
|
|
203
|
+
exampleText += `\t// \t${header.header.fieldName}: ${getExampleValue(pkg, header.value, '', undefined, true).split('\n').join('\n\t// \t')}\n`;
|
|
193
204
|
}
|
|
194
205
|
if (example.responseEnvelope?.result) {
|
|
195
|
-
exampleText += `\t// \t${fieldName ? fieldName : (example.responseEnvelope?.result.type).name}: ${getExampleValue(
|
|
206
|
+
exampleText += `\t// \t${fieldName ? fieldName : (example.responseEnvelope?.result.type).name}: ${getExampleValue(pkg, example.responseEnvelope.result, '').split('\n').join('\n\t// \t')},\n`;
|
|
196
207
|
}
|
|
197
208
|
exampleText += '\t// }\n';
|
|
198
209
|
}
|
|
@@ -203,19 +214,19 @@ export async function generateExamples(codeModel) {
|
|
|
203
214
|
if (exampleText === '')
|
|
204
215
|
continue;
|
|
205
216
|
// stitch it all together
|
|
206
|
-
let text = helpers.contentPreamble(
|
|
217
|
+
let text = helpers.contentPreamble(pkg);
|
|
207
218
|
text += imports.text();
|
|
208
219
|
text += exampleText;
|
|
209
220
|
examples.push(new ExampleContent(client.name, text));
|
|
210
221
|
}
|
|
211
222
|
return examples;
|
|
212
223
|
}
|
|
213
|
-
function getExampleValue(
|
|
224
|
+
function getExampleValue(pkg, example, indent, imports, byValue = false, inArray = false) {
|
|
214
225
|
switch (example.kind) {
|
|
215
226
|
case 'string': {
|
|
216
227
|
let exampleText = `"${escapeString(example.value)}"`;
|
|
217
228
|
if (example.type.kind === 'constant') {
|
|
218
|
-
exampleText = getConstantValue(
|
|
229
|
+
exampleText = getConstantValue(pkg, example.type, example.value);
|
|
219
230
|
}
|
|
220
231
|
else if (example.type.kind === 'time') {
|
|
221
232
|
exampleText = getTimeValue(example.type, example.value, imports);
|
|
@@ -224,11 +235,11 @@ function getExampleValue(codeModel, example, indent, imports, byValue = false, i
|
|
|
224
235
|
exampleText = `[]byte("${escapeString(example.value)}")`;
|
|
225
236
|
}
|
|
226
237
|
else if (example.type.kind === 'literal' && example.type.type.kind === 'constant') {
|
|
227
|
-
exampleText = getConstantValue(
|
|
238
|
+
exampleText = getConstantValue(pkg, example.type.type, example.type.literal.value);
|
|
228
239
|
}
|
|
229
240
|
else if (example.type.kind === 'etag') {
|
|
230
241
|
imports?.add(example.type.module);
|
|
231
|
-
exampleText = `${go.getTypeDeclaration(example.type,
|
|
242
|
+
exampleText = `${go.getTypeDeclaration(example.type, pkg)}("${escapeString(example.value)}")`;
|
|
232
243
|
}
|
|
233
244
|
return `${indent}${getPointerValue(example.type, exampleText, byValue, imports)}`;
|
|
234
245
|
}
|
|
@@ -236,7 +247,7 @@ function getExampleValue(codeModel, example, indent, imports, byValue = false, i
|
|
|
236
247
|
let exampleText = `${example.value}`;
|
|
237
248
|
switch (example.type.kind) {
|
|
238
249
|
case 'constant':
|
|
239
|
-
exampleText = `${indent}${getConstantValue(
|
|
250
|
+
exampleText = `${indent}${getConstantValue(pkg, example.type, example.value)}`;
|
|
240
251
|
break;
|
|
241
252
|
case 'time':
|
|
242
253
|
exampleText = getTimeValue(example.type, example.value, imports);
|
|
@@ -247,7 +258,7 @@ function getExampleValue(codeModel, example, indent, imports, byValue = false, i
|
|
|
247
258
|
case 'boolean': {
|
|
248
259
|
let exampleText = `${example.value}`;
|
|
249
260
|
if (example.type.kind === 'constant') {
|
|
250
|
-
exampleText = `${indent}${getConstantValue(
|
|
261
|
+
exampleText = `${indent}${getConstantValue(pkg, example.type, example.value)}`;
|
|
251
262
|
}
|
|
252
263
|
return `${indent}${getPointerValue(example.type, exampleText, byValue, imports)}`;
|
|
253
264
|
}
|
|
@@ -260,26 +271,26 @@ function getExampleValue(codeModel, example, indent, imports, byValue = false, i
|
|
|
260
271
|
// if polymorphic, need to add type name in array, so inArray will be set to false
|
|
261
272
|
// if other case, no need to add type name in array, so inArray will be set to true
|
|
262
273
|
const isElementPolymorphic = example.type.elementType.kind === 'interface';
|
|
263
|
-
let exampleText = `${indent}${getRef(byValue)}${go.getTypeDeclaration(example.type,
|
|
274
|
+
let exampleText = `${indent}${getRef(byValue)}${go.getTypeDeclaration(example.type, pkg)}{\n`;
|
|
264
275
|
for (const element of example.value) {
|
|
265
|
-
exampleText += `${getExampleValue(
|
|
276
|
+
exampleText += `${getExampleValue(pkg, element, indent + '\t', imports, isElementByValue && !isElementPolymorphic, !isElementPolymorphic)},\n`;
|
|
266
277
|
}
|
|
267
278
|
exampleText += `${indent}}`;
|
|
268
279
|
return exampleText;
|
|
269
280
|
}
|
|
270
281
|
case 'dictionary': {
|
|
271
|
-
let exampleText = `${indent}${getRef(byValue)}${go.getTypeDeclaration(example.type,
|
|
282
|
+
let exampleText = `${indent}${getRef(byValue)}${go.getTypeDeclaration(example.type, pkg)}{\n`;
|
|
272
283
|
const isValueByValue = example.type.valueTypeByValue;
|
|
273
284
|
const isValuePolymorphic = example.type.valueType.kind === 'interface';
|
|
274
285
|
for (const key in example.value) {
|
|
275
|
-
exampleText += `${indent}\t"${key}": ${getExampleValue(
|
|
286
|
+
exampleText += `${indent}\t"${key}": ${getExampleValue(pkg, example.value[key], indent + '\t', imports, isValueByValue && !isValuePolymorphic).slice(indent.length + 1)},\n`;
|
|
276
287
|
}
|
|
277
288
|
exampleText += `${indent}}`;
|
|
278
289
|
return exampleText;
|
|
279
290
|
}
|
|
280
291
|
case 'model': {
|
|
281
292
|
const isModelPolymorphic = example.type.kind === 'polymorphicModel';
|
|
282
|
-
let exampleText = `${indent}${getRef(byValue && !isModelPolymorphic)}${go.getTypeDeclaration(example.type,
|
|
293
|
+
let exampleText = `${indent}${getRef(byValue && !isModelPolymorphic)}${go.getTypeDeclaration(example.type, pkg)}{\n`;
|
|
283
294
|
if (inArray) {
|
|
284
295
|
exampleText = `${indent}{\n`;
|
|
285
296
|
}
|
|
@@ -287,7 +298,7 @@ function getExampleValue(codeModel, example, indent, imports, byValue = false, i
|
|
|
287
298
|
const goField = example.type.fields.find(f => f.name === field);
|
|
288
299
|
const isFieldByValue = goField.byValue ?? false;
|
|
289
300
|
const isFieldPolymorphic = goField.type.kind === 'interface';
|
|
290
|
-
exampleText += `${indent}\t${field}: ${getExampleValue(
|
|
301
|
+
exampleText += `${indent}\t${field}: ${getExampleValue(pkg, example.value[field], indent + '\t', imports, isFieldByValue && !isFieldPolymorphic).slice(indent.length + 1)},\n`;
|
|
291
302
|
}
|
|
292
303
|
if (example.additionalProperties) {
|
|
293
304
|
const additionalPropertiesField = example.type.fields.find(f => f.annotations.isAdditionalProperties);
|
|
@@ -296,9 +307,9 @@ function getExampleValue(codeModel, example, indent, imports, byValue = false, i
|
|
|
296
307
|
}
|
|
297
308
|
const isAdditionalPropertiesFieldByValue = additionalPropertiesField.type.valueTypeByValue ?? false;
|
|
298
309
|
const isAdditionalPropertiesPolymorphic = additionalPropertiesField.type.valueType.kind === 'interface';
|
|
299
|
-
exampleText += `${indent}\t${additionalPropertiesField.name}: ${getRef(additionalPropertiesField.byValue)}${go.getTypeDeclaration(additionalPropertiesField.type,
|
|
310
|
+
exampleText += `${indent}\t${additionalPropertiesField.name}: ${getRef(additionalPropertiesField.byValue)}${go.getTypeDeclaration(additionalPropertiesField.type, pkg)}{\n`;
|
|
300
311
|
for (const key in example.additionalProperties) {
|
|
301
|
-
exampleText += `${indent}\t"${key}": ${getExampleValue(
|
|
312
|
+
exampleText += `${indent}\t"${key}": ${getExampleValue(pkg, example.additionalProperties[key], indent + '\t', imports, isAdditionalPropertiesFieldByValue && !isAdditionalPropertiesPolymorphic).slice(indent.length + 1)},\n`;
|
|
302
313
|
}
|
|
303
314
|
exampleText += `${indent}},\n`;
|
|
304
315
|
}
|
|
@@ -312,17 +323,17 @@ function getExampleValue(codeModel, example, indent, imports, byValue = false, i
|
|
|
312
323
|
function getRef(byValue) {
|
|
313
324
|
return byValue ? '' : '&';
|
|
314
325
|
}
|
|
315
|
-
function getConstantValue(
|
|
326
|
+
function getConstantValue(pkg, type, value) {
|
|
316
327
|
for (const constantValue of type.values) {
|
|
317
328
|
if (constantValue.value === value) {
|
|
318
|
-
return
|
|
329
|
+
return go.getTypeDeclaration(constantValue, pkg);
|
|
319
330
|
}
|
|
320
331
|
}
|
|
321
332
|
switch (type.type) {
|
|
322
333
|
case 'string':
|
|
323
|
-
return `${
|
|
334
|
+
return `${go.getTypeDeclaration(type, pkg)}("${value}")`;
|
|
324
335
|
default:
|
|
325
|
-
return `${
|
|
336
|
+
return `${go.getTypeDeclaration(type, pkg)}(${value})`;
|
|
326
337
|
}
|
|
327
338
|
}
|
|
328
339
|
function getTimeValue(type, value, imports) {
|
|
@@ -451,6 +462,26 @@ function generateFakeExample(goType, name) {
|
|
|
451
462
|
case 'tokenCredential':
|
|
452
463
|
// we hard code the credential var name to cred
|
|
453
464
|
return new go.TokenCredentialExample('cred');
|
|
465
|
+
case 'encodedBytes':
|
|
466
|
+
return new go.StringExample(`<${name ?? 'test'}>`, goType);
|
|
467
|
+
case 'time':
|
|
468
|
+
// use a placeholder date value for time types
|
|
469
|
+
return new go.StringExample('2006-01-02T15:04:05Z', goType);
|
|
470
|
+
case 'etag':
|
|
471
|
+
return new go.StringExample(`<${name ?? 'etag'}>`, goType);
|
|
472
|
+
case 'model':
|
|
473
|
+
case 'polymorphicModel':
|
|
474
|
+
// return an empty struct example for model types
|
|
475
|
+
return new go.StructExample(goType);
|
|
476
|
+
case 'slice':
|
|
477
|
+
// return an empty array example for slice types
|
|
478
|
+
return new go.ArrayExample(goType);
|
|
479
|
+
case 'map':
|
|
480
|
+
// return an empty map example for map types
|
|
481
|
+
return new go.DictionaryExample(goType);
|
|
482
|
+
case 'interface':
|
|
483
|
+
// for interface types, use the root type (which is a PolymorphicModel) to create an example
|
|
484
|
+
return new go.StructExample(goType.rootType);
|
|
454
485
|
default:
|
|
455
486
|
throw new CodegenError('InternalError', `unhandled fake example kind ${goType.kind}`);
|
|
456
487
|
}
|