@azure-tools/rlc-common 1.0.0-beta.1 → 1.0.0-beta.10
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/.eslintrc.json +23 -0
- package/.prettierignore +1 -0
- package/.prettierrc +7 -0
- package/.rush/temp/package-deps_build.json +33 -25
- package/.rush/temp/shrinkwrap-deps.json +84 -9
- package/CHANGELOG.md +52 -1
- package/CONTRIBUTING.md +29 -0
- package/README.md +3 -0
- package/dist/buildClient.js +89 -19
- package/dist/buildClient.js.map +1 -1
- package/dist/buildClientDefinitions.js.map +1 -1
- package/dist/buildIndexFile.js +18 -0
- package/dist/buildIndexFile.js.map +1 -1
- package/dist/buildIsUnexpectedHelper.js +52 -51
- package/dist/buildIsUnexpectedHelper.js.map +1 -1
- package/dist/buildMethodShortcuts.js +1 -1
- package/dist/buildMethodShortcuts.js.map +1 -1
- package/dist/buildObjectTypes.js +47 -11
- package/dist/buildObjectTypes.js.map +1 -1
- package/dist/buildParameterTypes.js +31 -3
- package/dist/buildParameterTypes.js.map +1 -1
- package/dist/buildResponseTypes.js +19 -6
- package/dist/buildResponseTypes.js.map +1 -1
- package/dist/buildSchemaType.js +22 -1
- package/dist/buildSchemaType.js.map +1 -1
- package/dist/buildSerializeHelper.js +35 -0
- package/dist/buildSerializeHelper.js.map +1 -0
- package/dist/buildTopLevelIndexFile.js +6 -3
- package/dist/buildTopLevelIndexFile.js.map +1 -1
- package/dist/helpers/nameConstructors.js +2 -2
- package/dist/helpers/nameConstructors.js.map +1 -1
- package/dist/helpers/nameUtils.js +1 -1
- package/dist/helpers/nameUtils.js.map +1 -1
- package/dist/helpers/operationHelpers.js +23 -3
- package/dist/helpers/operationHelpers.js.map +1 -1
- package/dist/helpers/pathUtils.js +13 -0
- package/dist/helpers/pathUtils.js.map +1 -0
- package/dist/helpers/shortcutMethods.js +1 -1
- package/dist/helpers/shortcutMethods.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/metadata/buildPackageFile.js +70 -28
- package/dist/metadata/buildPackageFile.js.map +1 -1
- package/dist/metadata/buildReadmeFile.js +3 -3
- package/dist/package.json +1 -1
- package/dist/static/paginateContent.js +1 -1
- package/dist/static/pollingContent.js +26 -6
- package/dist/static/pollingContent.js.map +1 -1
- package/dist/static/serializeHelper.js +30 -0
- package/dist/static/serializeHelper.js.map +1 -0
- package/dist/test/template.js +1 -2
- package/dist/test/template.js.map +1 -1
- package/dist-esm/buildClient.js +88 -18
- package/dist-esm/buildClient.js.map +1 -1
- package/dist-esm/buildClientDefinitions.js +1 -1
- package/dist-esm/buildClientDefinitions.js.map +1 -1
- package/dist-esm/buildIndexFile.js +19 -1
- package/dist-esm/buildIndexFile.js.map +1 -1
- package/dist-esm/buildIsUnexpectedHelper.js +52 -51
- package/dist-esm/buildIsUnexpectedHelper.js.map +1 -1
- package/dist-esm/buildMethodShortcuts.js +1 -1
- package/dist-esm/buildMethodShortcuts.js.map +1 -1
- package/dist-esm/buildObjectTypes.js +47 -8
- package/dist-esm/buildObjectTypes.js.map +1 -1
- package/dist-esm/buildParameterTypes.js +35 -2
- package/dist-esm/buildParameterTypes.js.map +1 -1
- package/dist-esm/buildResponseTypes.js +19 -6
- package/dist-esm/buildResponseTypes.js.map +1 -1
- package/dist-esm/buildSchemaType.js +23 -2
- package/dist-esm/buildSchemaType.js.map +1 -1
- package/dist-esm/buildSerializeHelper.js +31 -0
- package/dist-esm/buildSerializeHelper.js.map +1 -0
- package/dist-esm/buildTopLevelIndexFile.js +6 -3
- package/dist-esm/buildTopLevelIndexFile.js.map +1 -1
- package/dist-esm/helpers/nameConstructors.js +2 -2
- package/dist-esm/helpers/nameConstructors.js.map +1 -1
- package/dist-esm/helpers/nameUtils.js +1 -1
- package/dist-esm/helpers/nameUtils.js.map +1 -1
- package/dist-esm/helpers/operationHelpers.js +15 -3
- package/dist-esm/helpers/operationHelpers.js.map +1 -1
- package/dist-esm/helpers/pathUtils.js +9 -0
- package/dist-esm/helpers/pathUtils.js.map +1 -0
- package/dist-esm/helpers/shortcutMethods.js +1 -1
- package/dist-esm/helpers/shortcutMethods.js.map +1 -1
- package/dist-esm/index.js +1 -0
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/interfaces.js.map +1 -1
- package/dist-esm/metadata/buildPackageFile.js +70 -28
- package/dist-esm/metadata/buildPackageFile.js.map +1 -1
- package/dist-esm/metadata/buildReadmeFile.js +3 -3
- package/dist-esm/package.json +1 -1
- package/dist-esm/static/paginateContent.js +1 -1
- package/dist-esm/static/pollingContent.js +26 -6
- package/dist-esm/static/pollingContent.js.map +1 -1
- package/dist-esm/static/serializeHelper.js +27 -0
- package/dist-esm/static/serializeHelper.js.map +1 -0
- package/dist-esm/test/template.js +1 -2
- package/dist-esm/test/template.js.map +1 -1
- package/package.json +10 -4
- package/src/buildClient.ts +121 -19
- package/src/buildClientDefinitions.ts +6 -2
- package/src/buildIndexFile.ts +28 -0
- package/src/buildIsUnexpectedHelper.ts +52 -52
- package/src/buildMethodShortcuts.ts +1 -1
- package/src/buildObjectTypes.ts +66 -10
- package/src/buildParameterTypes.ts +45 -3
- package/src/buildResponseTypes.ts +23 -6
- package/src/buildSchemaType.ts +24 -1
- package/src/buildSerializeHelper.ts +42 -0
- package/src/buildTopLevelIndexFile.ts +9 -3
- package/src/helpers/nameConstructors.ts +2 -2
- package/src/helpers/nameUtils.ts +1 -1
- package/src/helpers/operationHelpers.ts +19 -3
- package/src/helpers/pathUtils.ts +9 -0
- package/src/helpers/schemaHelpers.ts +1 -1
- package/src/helpers/shortcutMethods.ts +1 -1
- package/src/index.ts +1 -0
- package/src/interfaces.ts +16 -1
- package/src/metadata/buildPackageFile.ts +94 -31
- package/src/metadata/buildReadmeFile.ts +3 -3
- package/src/static/paginateContent.ts +1 -1
- package/src/static/pollingContent.ts +26 -6
- package/src/static/serializeHelper.ts +29 -0
- package/src/test/template.ts +1 -2
- package/types/buildObjectTypes.d.ts +2 -1
- package/types/buildParameterTypes.d.ts +9 -1
- package/types/buildSerializeHelper.d.ts +5 -0
- package/types/helpers/operationHelpers.d.ts +4 -0
- package/types/helpers/pathUtils.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/interfaces.d.ts +15 -1
- package/types/static/pollingContent.d.ts +1 -1
- package/types/static/serializeHelper.d.ts +4 -0
- package/types/test/template.d.ts +1 -1
|
@@ -20,10 +20,12 @@ import {
|
|
|
20
20
|
getResponseTypeName
|
|
21
21
|
} from "./helpers/nameConstructors.js";
|
|
22
22
|
|
|
23
|
+
let hasErrorResponse = false;
|
|
23
24
|
export function buildResponseTypes(model: RLCModel) {
|
|
24
25
|
const project = new Project();
|
|
25
26
|
const srcPath = model.srcPath;
|
|
26
27
|
const filePath = path.join(srcPath, `responses.ts`);
|
|
28
|
+
hasErrorResponse = false;
|
|
27
29
|
const responsesFile = project.createSourceFile(filePath, undefined, {
|
|
28
30
|
overwrite: true
|
|
29
31
|
});
|
|
@@ -86,19 +88,26 @@ export function buildResponseTypes(model: RLCModel) {
|
|
|
86
88
|
}
|
|
87
89
|
]);
|
|
88
90
|
}
|
|
91
|
+
const namedImports = ["HttpResponse"];
|
|
92
|
+
if (hasErrorResponse) {
|
|
93
|
+
namedImports.push("ErrorResponse");
|
|
94
|
+
}
|
|
89
95
|
responsesFile.addImportDeclarations([
|
|
90
96
|
{
|
|
91
|
-
namedImports
|
|
97
|
+
namedImports,
|
|
92
98
|
moduleSpecifier: "@azure-rest/core-client"
|
|
93
99
|
}
|
|
94
100
|
]);
|
|
95
101
|
|
|
96
102
|
if (model.importSet?.has(ImportKind.ResponseOutput)) {
|
|
103
|
+
const modelNamedImports = Array.from(
|
|
104
|
+
model.importSet.get(ImportKind.ResponseOutput) || []
|
|
105
|
+
).filter((modelName) => {
|
|
106
|
+
return !(modelName === "ErrorResponseOutput" && hasErrorResponse);
|
|
107
|
+
});
|
|
97
108
|
responsesFile.addImportDeclarations([
|
|
98
109
|
{
|
|
99
|
-
namedImports:
|
|
100
|
-
...Array.from(model.importSet.get(ImportKind.ResponseOutput) || [])
|
|
101
|
-
],
|
|
110
|
+
namedImports: modelNamedImports,
|
|
102
111
|
moduleSpecifier: "./outputModels"
|
|
103
112
|
}
|
|
104
113
|
]);
|
|
@@ -125,7 +134,7 @@ function getResponseHeaderInterfaceDefinition(
|
|
|
125
134
|
name: h.name,
|
|
126
135
|
...(description && { docs: [{ description }] }),
|
|
127
136
|
type: h.type,
|
|
128
|
-
hasQuestionToken: !
|
|
137
|
+
hasQuestionToken: !h.required
|
|
129
138
|
};
|
|
130
139
|
})
|
|
131
140
|
};
|
|
@@ -149,9 +158,17 @@ function getResponseInterfaceProperties(
|
|
|
149
158
|
|
|
150
159
|
if (response.body) {
|
|
151
160
|
const description = response.body.description;
|
|
161
|
+
let type = response.body.type;
|
|
162
|
+
if (
|
|
163
|
+
response.body.type === "ErrorResponseOutput" &&
|
|
164
|
+
response.body.fromCore
|
|
165
|
+
) {
|
|
166
|
+
type = "ErrorResponse";
|
|
167
|
+
hasErrorResponse = true;
|
|
168
|
+
}
|
|
152
169
|
responseProperties.push({
|
|
153
170
|
name: "body",
|
|
154
|
-
type
|
|
171
|
+
type,
|
|
155
172
|
kind: StructureKind.PropertySignature,
|
|
156
173
|
...(description && { docs: [{ description }] })
|
|
157
174
|
});
|
package/src/buildSchemaType.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Project } from "ts-morph";
|
|
5
5
|
import * as path from "path";
|
|
6
6
|
import {
|
|
7
|
+
buildObjectAliases,
|
|
7
8
|
buildObjectInterfaces,
|
|
8
9
|
buildPolymorphicAliases
|
|
9
10
|
} from "./buildObjectTypes.js";
|
|
@@ -41,15 +42,37 @@ export function generateModelFiles(
|
|
|
41
42
|
importedModels,
|
|
42
43
|
schemaContext
|
|
43
44
|
);
|
|
45
|
+
|
|
44
46
|
const objectTypeAliases = buildPolymorphicAliases(model, schemaContext);
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
const objectAliases = buildObjectAliases(model, importedModels, schemaContext);
|
|
49
|
+
if (objectTypeAliases.length || objectsDefinitions.length || objectAliases.length) {
|
|
47
50
|
const modelsFile = project.createSourceFile(filePath, undefined, {
|
|
48
51
|
overwrite: true
|
|
49
52
|
});
|
|
50
53
|
|
|
51
54
|
modelsFile.addInterfaces(objectsDefinitions);
|
|
52
55
|
modelsFile.addTypeAliases(objectTypeAliases);
|
|
56
|
+
modelsFile.addTypeAliases(objectAliases);
|
|
57
|
+
if (importedModels.has("Paged")) {
|
|
58
|
+
modelsFile.addImportDeclarations([
|
|
59
|
+
{
|
|
60
|
+
namedImports: ["Paged"],
|
|
61
|
+
moduleSpecifier: "@azure/core-paging"
|
|
62
|
+
}
|
|
63
|
+
]);
|
|
64
|
+
importedModels.delete("Paged");
|
|
65
|
+
}
|
|
66
|
+
if (importedModels.size > 0) {
|
|
67
|
+
modelsFile.addImportDeclarations([
|
|
68
|
+
{
|
|
69
|
+
namedImports: [
|
|
70
|
+
...Array.from(importedModels || [])
|
|
71
|
+
],
|
|
72
|
+
moduleSpecifier: "@azure-rest/core-client"
|
|
73
|
+
}
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
53
76
|
return { path: filePath, content: modelsFile.getFullText() };
|
|
54
77
|
}
|
|
55
78
|
return undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { RLCModel } from "./interfaces.js";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
// @ts-ignore: to fix the handlebars issue
|
|
4
|
+
import hbs from "handlebars";
|
|
5
|
+
import {
|
|
6
|
+
hasMultiCollection,
|
|
7
|
+
hasPipeCollection,
|
|
8
|
+
hasSsvCollection,
|
|
9
|
+
hasTsvCollection
|
|
10
|
+
} from "./helpers/operationHelpers.js";
|
|
11
|
+
import {
|
|
12
|
+
buildMultiCollectionContent,
|
|
13
|
+
buildPipeCollectionContent,
|
|
14
|
+
buildSsvCollectionContent,
|
|
15
|
+
buildTsvCollectionContent
|
|
16
|
+
} from "./static/serializeHelper.js";
|
|
17
|
+
|
|
18
|
+
export function buildSerializeHelper(model: RLCModel) {
|
|
19
|
+
let serializeHelperContent = "";
|
|
20
|
+
if (hasMultiCollection(model)) {
|
|
21
|
+
serializeHelperContent += "\n" + buildMultiCollectionContent;
|
|
22
|
+
}
|
|
23
|
+
if (hasPipeCollection(model)) {
|
|
24
|
+
serializeHelperContent += "\n" + buildPipeCollectionContent;
|
|
25
|
+
}
|
|
26
|
+
if (hasSsvCollection(model)) {
|
|
27
|
+
serializeHelperContent += "\n" + buildSsvCollectionContent;
|
|
28
|
+
}
|
|
29
|
+
if (hasTsvCollection(model)) {
|
|
30
|
+
serializeHelperContent += "\n" + buildTsvCollectionContent;
|
|
31
|
+
}
|
|
32
|
+
if (serializeHelperContent !== "") {
|
|
33
|
+
const readmeFileContents = hbs.compile(serializeHelperContent, {
|
|
34
|
+
noEscape: true
|
|
35
|
+
});
|
|
36
|
+
const { srcPath } = model;
|
|
37
|
+
return {
|
|
38
|
+
path: path.join(srcPath, "serializeHelper.ts"),
|
|
39
|
+
content: readmeFileContents({})
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { NameType, normalizeName } from "./helpers/nameUtils.js";
|
|
5
5
|
import { RLCModel } from "./interfaces.js";
|
|
6
6
|
import { Project } from "ts-morph";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import { getRelativePartFromSrcPath } from "./helpers/pathUtils.js";
|
|
7
9
|
|
|
8
10
|
const batchOutputFolder: [string, string, string][] = [];
|
|
9
11
|
|
|
@@ -17,7 +19,7 @@ export function buildTopLevelIndex(model: RLCModel) {
|
|
|
17
19
|
if (srcPath) {
|
|
18
20
|
const clientName = model.libraryName;
|
|
19
21
|
const moduleName = normalizeName(clientName, NameType.File);
|
|
20
|
-
const relativePath =
|
|
22
|
+
const relativePath = "./" + getRelativePartFromSrcPath(srcPath);
|
|
21
23
|
batchOutputFolder.push([relativePath, clientName, moduleName]);
|
|
22
24
|
}
|
|
23
25
|
if (
|
|
@@ -40,7 +42,11 @@ export function buildTopLevelIndex(model: RLCModel) {
|
|
|
40
42
|
indexFile.addExportDeclaration({
|
|
41
43
|
namedExports: [...allModules]
|
|
42
44
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const content = indexFile.getFullText();
|
|
46
|
+
const filePath = path.join(
|
|
47
|
+
srcPath.substring(0, srcPath.indexOf(path.sep + "src") + 4),
|
|
48
|
+
`index.ts`
|
|
49
|
+
);
|
|
50
|
+
return { path: filePath, content };
|
|
45
51
|
}
|
|
46
52
|
}
|
|
@@ -18,7 +18,7 @@ export function getResponseTypeName(
|
|
|
18
18
|
operationName?: string,
|
|
19
19
|
statusCode?: string
|
|
20
20
|
): string {
|
|
21
|
-
if (
|
|
21
|
+
if (operationName) {
|
|
22
22
|
baseNameOrOperationGroup = getResponseBaseName(
|
|
23
23
|
baseNameOrOperationGroup,
|
|
24
24
|
operationName!,
|
|
@@ -79,7 +79,7 @@ export function getParameterTypeName(
|
|
|
79
79
|
baseNameOrOperationGroup: string,
|
|
80
80
|
operationName?: string
|
|
81
81
|
) {
|
|
82
|
-
if (
|
|
82
|
+
if (operationName) {
|
|
83
83
|
baseNameOrOperationGroup = getParameterBaseName(
|
|
84
84
|
baseNameOrOperationGroup,
|
|
85
85
|
operationName!
|
package/src/helpers/nameUtils.ts
CHANGED
|
@@ -202,7 +202,7 @@ function toCasing(str: string, casing: CasingConvention): string {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
function getNameParts(name: string) {
|
|
205
|
-
|
|
205
|
+
const parts = name.split(/[-._ ]+/);
|
|
206
206
|
|
|
207
207
|
return parts.length > 0 ? parts : [name];
|
|
208
208
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
RLCModel,
|
|
14
14
|
SchemaContext
|
|
15
15
|
} from "../interfaces.js";
|
|
16
|
-
import { pascalCase } from "./nameUtils.js";
|
|
16
|
+
import { NameType, normalizeName, pascalCase } from "./nameUtils.js";
|
|
17
17
|
import { isObjectSchema } from "./schemaHelpers.js";
|
|
18
18
|
|
|
19
19
|
export function buildMethodDefinitions(
|
|
@@ -26,7 +26,7 @@ export function buildMethodDefinitions(
|
|
|
26
26
|
|
|
27
27
|
for (const method of verbMethods) {
|
|
28
28
|
const description = method.description;
|
|
29
|
-
|
|
29
|
+
const areAllOptional = method.hasOptionalOptions;
|
|
30
30
|
|
|
31
31
|
methodDefinitions.push({
|
|
32
32
|
name: key,
|
|
@@ -52,7 +52,7 @@ export function getPathParamDefinitions(
|
|
|
52
52
|
): OptionalKind<ParameterDeclarationStructure>[] {
|
|
53
53
|
return pathParams.map(({ name, type, description }) => {
|
|
54
54
|
return {
|
|
55
|
-
name,
|
|
55
|
+
name: normalizeName(name, NameType.Parameter),
|
|
56
56
|
type,
|
|
57
57
|
description
|
|
58
58
|
};
|
|
@@ -67,6 +67,22 @@ export function hasPollingOperations(model: RLCModel) {
|
|
|
67
67
|
return Boolean(model.annotations?.hasLongRunning);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
export function hasMultiCollection(model: RLCModel) {
|
|
71
|
+
return Boolean(model.annotations?.hasMultiCollection);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function hasPipeCollection(model: RLCModel) {
|
|
75
|
+
return Boolean(model.annotations?.hasPipeCollection);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function hasSsvCollection(model: RLCModel) {
|
|
79
|
+
return Boolean(model.annotations?.hasSsvCollection);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function hasTsvCollection(model: RLCModel) {
|
|
83
|
+
return Boolean(model.annotations?.hasTsvCollection);
|
|
84
|
+
}
|
|
85
|
+
|
|
70
86
|
export function hasUnexpectedHelper(model: RLCModel) {
|
|
71
87
|
const pathDictionary = model.paths;
|
|
72
88
|
for (const details of Object.values(pathDictionary)) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
|
|
3
|
+
export function getRelativePartFromSrcPath(srcPath: string) {
|
|
4
|
+
const sep = srcPath.includes(path.sep + "src") ? path.sep : "/";
|
|
5
|
+
const relativePart = srcPath.substring(srcPath.indexOf(sep + "src") + 4);
|
|
6
|
+
return relativePart.startsWith(sep)
|
|
7
|
+
? relativePart.substring(1)
|
|
8
|
+
: relativePart;
|
|
9
|
+
}
|
|
@@ -13,7 +13,7 @@ import { NameType, normalizeName } from "./nameUtils.js";
|
|
|
13
13
|
export function generateMethodShortcuts(
|
|
14
14
|
paths: Paths
|
|
15
15
|
): OptionalKind<InterfaceDeclarationStructure>[] {
|
|
16
|
-
|
|
16
|
+
const keys: Record<string, OptionalKind<MethodSignatureStructure>[]> = {};
|
|
17
17
|
for (const path in paths) {
|
|
18
18
|
const groupName = paths[path].operationGroupName;
|
|
19
19
|
const definitions = buildOperationDefinitions(paths[path]);
|
package/src/index.ts
CHANGED
package/src/interfaces.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface RLCModel {
|
|
|
6
6
|
paths: Paths;
|
|
7
7
|
options?: RLCOptions;
|
|
8
8
|
schemas: Schema[];
|
|
9
|
-
|
|
9
|
+
apiVersionInQueryParam?: Parameter;
|
|
10
10
|
parameters?: OperationParameter[];
|
|
11
11
|
responses?: OperationResponse[];
|
|
12
12
|
importSet?: Map<ImportKind, Set<string>>;
|
|
@@ -14,14 +14,24 @@ export interface RLCModel {
|
|
|
14
14
|
urlInfo?: UrlInfo;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export interface PathTemplateApiVersion {
|
|
18
|
+
value: string;
|
|
19
|
+
templateName: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
export interface UrlInfo {
|
|
18
23
|
endpoint?: string;
|
|
19
24
|
urlParameters?: PathParameter[];
|
|
25
|
+
pathTemplateApiVersion?: PathTemplateApiVersion;
|
|
20
26
|
}
|
|
21
27
|
export interface AnnotationDetails {
|
|
22
28
|
hasPaging?: boolean;
|
|
23
29
|
hasLongRunning?: boolean;
|
|
24
30
|
pageDetails?: PagingDetails;
|
|
31
|
+
hasMultiCollection?: boolean;
|
|
32
|
+
hasPipeCollection?: boolean;
|
|
33
|
+
hasSsvCollection?: boolean;
|
|
34
|
+
hasTsvCollection?: boolean;
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
export interface PagingDetails {
|
|
@@ -63,6 +73,7 @@ export type PathParameter = {
|
|
|
63
73
|
name: string;
|
|
64
74
|
type: string;
|
|
65
75
|
description?: string;
|
|
76
|
+
value?: string | number | boolean;
|
|
66
77
|
};
|
|
67
78
|
|
|
68
79
|
export interface OperationAnnotations {
|
|
@@ -89,6 +100,7 @@ export interface RLCOptions {
|
|
|
89
100
|
productDocLink?: string;
|
|
90
101
|
serviceInfo?: ServiceInfo;
|
|
91
102
|
azureArm?: boolean;
|
|
103
|
+
sourceFrom?: "Cadl" | "Swagger";
|
|
92
104
|
}
|
|
93
105
|
|
|
94
106
|
export interface ServiceInfo {
|
|
@@ -129,6 +141,9 @@ export interface Schema {
|
|
|
129
141
|
default?: any;
|
|
130
142
|
readOnly?: boolean;
|
|
131
143
|
usage?: SchemaContext[];
|
|
144
|
+
alias?: string;
|
|
145
|
+
outputAlias?: string;
|
|
146
|
+
fromCore?: boolean;
|
|
132
147
|
}
|
|
133
148
|
|
|
134
149
|
export interface ObjectSchema extends Schema {
|
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
import { Project } from "ts-morph";
|
|
5
|
+
import { NameType, normalizeName } from "../helpers/nameUtils.js";
|
|
5
6
|
import {
|
|
6
7
|
hasPagingOperations,
|
|
7
8
|
hasPollingOperations
|
|
8
9
|
} from "../helpers/operationHelpers.js";
|
|
10
|
+
import { getRelativePartFromSrcPath } from "../helpers/pathUtils.js";
|
|
9
11
|
import { RLCModel } from "../interfaces.js";
|
|
10
12
|
|
|
13
|
+
let hasPaging = false;
|
|
14
|
+
let hasLRO = false;
|
|
15
|
+
let clientFilePaths: string[] = [];
|
|
16
|
+
|
|
11
17
|
export function buildPackageFile(model: RLCModel, hasSamplesGenerated = false) {
|
|
12
18
|
const generateMetadata = Boolean(model.options?.generateMetadata);
|
|
13
19
|
if (!generateMetadata) {
|
|
@@ -43,23 +49,36 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
43
49
|
return;
|
|
44
50
|
}
|
|
45
51
|
|
|
52
|
+
clientFilePaths.push(getClientFilePath(model));
|
|
53
|
+
hasPaging = hasPaging || hasPagingOperations(model);
|
|
54
|
+
hasLRO = hasLRO || hasPollingOperations(model);
|
|
55
|
+
|
|
46
56
|
const {
|
|
47
57
|
packageDetails,
|
|
48
58
|
generateTest,
|
|
49
59
|
generateSample,
|
|
50
60
|
azureOutputDirectory,
|
|
51
61
|
azureSdkForJs,
|
|
52
|
-
isCadlTest
|
|
62
|
+
isCadlTest,
|
|
63
|
+
sourceFrom,
|
|
64
|
+
multiClient,
|
|
65
|
+
batch
|
|
53
66
|
} = model.options;
|
|
67
|
+
if (
|
|
68
|
+
multiClient &&
|
|
69
|
+
batch &&
|
|
70
|
+
batch.length > 1 &&
|
|
71
|
+
clientFilePaths.length < batch.length
|
|
72
|
+
) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
54
75
|
|
|
55
76
|
const clientPackageName = packageDetails.name;
|
|
56
77
|
let apiRefUrlQueryParameter: string = "";
|
|
57
78
|
if (packageDetails.version.includes("beta")) {
|
|
58
79
|
apiRefUrlQueryParameter = "?view=azure-node-preview";
|
|
59
80
|
}
|
|
60
|
-
|
|
61
|
-
const hasPaging = hasPagingOperations(model);
|
|
62
|
-
const hasLRO = hasPollingOperations(model);
|
|
81
|
+
|
|
63
82
|
const packageInfo: Record<string, any> = {
|
|
64
83
|
name: `${packageDetails.name}`,
|
|
65
84
|
"sdk-type": "client",
|
|
@@ -96,23 +115,32 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
96
115
|
"build:samples": "echo skipped.",
|
|
97
116
|
"build:test": "echo skipped.",
|
|
98
117
|
"build:debug": "echo skipped.",
|
|
99
|
-
"check-format":
|
|
100
|
-
|
|
118
|
+
"check-format": `prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore "src/**/*.ts" "*.{js,json}" ${appendPathWhenFormat(
|
|
119
|
+
generateTest,
|
|
120
|
+
generateSample
|
|
121
|
+
)}`,
|
|
101
122
|
clean:
|
|
102
123
|
"rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log",
|
|
103
124
|
"execute:samples": "echo skipped",
|
|
104
125
|
"extract-api":
|
|
105
126
|
"rimraf review && mkdirp ./review && api-extractor run --local",
|
|
106
|
-
format:
|
|
107
|
-
|
|
127
|
+
format: `prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore "src/**/*.ts" "*.{js,json}" ${appendPathWhenFormat(
|
|
128
|
+
generateTest,
|
|
129
|
+
generateSample
|
|
130
|
+
)}`,
|
|
108
131
|
"generate:client":
|
|
109
|
-
|
|
132
|
+
sourceFrom === "Swagger"
|
|
133
|
+
? "autorest --typescript swagger/README.md && npm run format"
|
|
134
|
+
: "echo skipped",
|
|
110
135
|
"integration-test:browser": "echo skipped",
|
|
111
136
|
"integration-test:node": "echo skipped",
|
|
112
137
|
"integration-test": "echo skipped",
|
|
113
|
-
"lint:fix":
|
|
114
|
-
|
|
115
|
-
|
|
138
|
+
"lint:fix": `eslint package.json api-extractor.json src ${appednPathWhenLint(
|
|
139
|
+
generateTest
|
|
140
|
+
)} --ext .ts --fix --fix-type [problem,suggestion]`,
|
|
141
|
+
lint: `eslint package.json api-extractor.json src ${appednPathWhenLint(
|
|
142
|
+
generateTest
|
|
143
|
+
)} --ext .ts`,
|
|
116
144
|
pack: "npm pack 2>&1",
|
|
117
145
|
"test:browser": "echo skipped",
|
|
118
146
|
"test:node": "echo skipped",
|
|
@@ -125,28 +153,29 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
125
153
|
autoPublish: false,
|
|
126
154
|
dependencies: {
|
|
127
155
|
"@azure/core-auth": "^1.3.0",
|
|
128
|
-
"@azure-rest/core-client": "1.
|
|
156
|
+
"@azure-rest/core-client": "^1.1.0",
|
|
129
157
|
"@azure/core-rest-pipeline": "^1.8.0",
|
|
130
158
|
"@azure/logger": "^1.0.0",
|
|
131
159
|
tslib: "^2.2.0",
|
|
132
160
|
...(hasPaging && {
|
|
133
|
-
"@azure/core-paging": "^1.
|
|
161
|
+
"@azure/core-paging": "^1.5.0"
|
|
134
162
|
}),
|
|
135
163
|
...(hasLRO && {
|
|
136
|
-
"@azure/core-lro": "^2.
|
|
164
|
+
"@azure/core-lro": "^2.5.0",
|
|
165
|
+
"@azure/abort-controller": "^1.0.0"
|
|
137
166
|
})
|
|
138
167
|
},
|
|
139
168
|
devDependencies: {
|
|
140
169
|
"@microsoft/api-extractor": "^7.31.1",
|
|
141
170
|
autorest: "latest",
|
|
142
171
|
"@types/node": "^14.0.0",
|
|
143
|
-
dotenv: "^
|
|
172
|
+
dotenv: "^16.0.0",
|
|
144
173
|
eslint: "^8.0.0",
|
|
145
|
-
mkdirp: "^1.
|
|
146
|
-
prettier: "2.
|
|
174
|
+
mkdirp: "^2.1.2",
|
|
175
|
+
prettier: "^2.5.1",
|
|
147
176
|
rimraf: "^3.0.0",
|
|
148
177
|
"source-map-support": "^0.5.9",
|
|
149
|
-
typescript: "~4.
|
|
178
|
+
typescript: "~4.8.0"
|
|
150
179
|
}
|
|
151
180
|
};
|
|
152
181
|
|
|
@@ -156,13 +185,21 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
156
185
|
|
|
157
186
|
if (azureSdkForJs) {
|
|
158
187
|
packageInfo["//metadata"] = {
|
|
159
|
-
constantPaths: [
|
|
160
|
-
{
|
|
161
|
-
path: "swagger/README.md",
|
|
162
|
-
prefix: "package-version"
|
|
163
|
-
}
|
|
164
|
-
]
|
|
188
|
+
constantPaths: []
|
|
165
189
|
};
|
|
190
|
+
clientFilePaths.forEach((path) => {
|
|
191
|
+
packageInfo["//metadata"].constantPaths.push({
|
|
192
|
+
path,
|
|
193
|
+
prefix: "userAgentInfo"
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
// Only generate this from Swagger spec
|
|
197
|
+
if (sourceFrom === "Swagger") {
|
|
198
|
+
packageInfo["//metadata"].constantPaths.push({
|
|
199
|
+
path: "swagger/README.md",
|
|
200
|
+
prefix: "package-version"
|
|
201
|
+
});
|
|
202
|
+
}
|
|
166
203
|
packageInfo.scripts["build"] =
|
|
167
204
|
"npm run clean && tsc -p . && dev-tool run bundle && mkdirp ./review && api-extractor run --local";
|
|
168
205
|
packageInfo.scripts["build:debug"] =
|
|
@@ -177,9 +214,9 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
177
214
|
packageInfo.scripts[
|
|
178
215
|
"minify"
|
|
179
216
|
] = `uglifyjs -c -m --comments --source-map "content='./dist/index.js.map'" -o ./dist/index.min.js ./dist/index.js`;
|
|
180
|
-
packageInfo.devDependencies["@rollup/plugin-commonjs"] = "^
|
|
181
|
-
packageInfo.devDependencies["@rollup/plugin-json"] = "^
|
|
182
|
-
packageInfo.devDependencies["@rollup/plugin-multi-entry"] = "^
|
|
217
|
+
packageInfo.devDependencies["@rollup/plugin-commonjs"] = "^24.0.0";
|
|
218
|
+
packageInfo.devDependencies["@rollup/plugin-json"] = "^6.0.0";
|
|
219
|
+
packageInfo.devDependencies["@rollup/plugin-multi-entry"] = "^6.0.0";
|
|
183
220
|
packageInfo.devDependencies["@rollup/plugin-node-resolve"] = "^13.1.3";
|
|
184
221
|
packageInfo.devDependencies["rollup"] = "^2.66.1";
|
|
185
222
|
packageInfo.devDependencies["rollup-plugin-sourcemaps"] = "^0.6.3";
|
|
@@ -196,6 +233,7 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
196
233
|
packageInfo.devDependencies["@azure/identity"] = "^2.0.1";
|
|
197
234
|
packageInfo.devDependencies["@azure-tools/test-recorder"] = "^2.0.0";
|
|
198
235
|
packageInfo.devDependencies["mocha"] = "^7.1.1";
|
|
236
|
+
packageInfo.devDependencies["@types/mocha"] = "^7.0.2";
|
|
199
237
|
packageInfo.devDependencies["mocha-junit-reporter"] = "^1.18.0";
|
|
200
238
|
packageInfo.devDependencies["cross-env"] = "^7.0.2";
|
|
201
239
|
packageInfo.devDependencies["@types/chai"] = "^4.2.8";
|
|
@@ -203,17 +241,15 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
203
241
|
packageInfo.devDependencies["cross-env"] = "^7.0.2";
|
|
204
242
|
packageInfo.devDependencies["karma-chrome-launcher"] = "^3.0.0";
|
|
205
243
|
packageInfo.devDependencies["karma-coverage"] = "^2.0.0";
|
|
206
|
-
packageInfo.devDependencies["karma-edge-launcher"] = "^0.4.2";
|
|
207
244
|
packageInfo.devDependencies["karma-env-preprocessor"] = "^0.1.1";
|
|
208
245
|
packageInfo.devDependencies["karma-firefox-launcher"] = "^1.1.0";
|
|
209
|
-
packageInfo.devDependencies["karma-ie-launcher"] = "^1.0.0";
|
|
210
246
|
packageInfo.devDependencies["karma-junit-reporter"] = "^2.0.1";
|
|
211
247
|
packageInfo.devDependencies["karma-mocha-reporter"] = "^2.2.5";
|
|
212
248
|
packageInfo.devDependencies["karma-mocha"] = "^2.0.1";
|
|
213
249
|
packageInfo.devDependencies["karma-source-map-support"] = "~1.4.0";
|
|
214
250
|
packageInfo.devDependencies["karma-sourcemap-loader"] = "^0.3.8";
|
|
215
251
|
packageInfo.devDependencies["karma"] = "^6.2.0";
|
|
216
|
-
packageInfo.devDependencies["nyc"] = "^
|
|
252
|
+
packageInfo.devDependencies["nyc"] = "^15.0.0";
|
|
217
253
|
packageInfo.devDependencies["source-map-support"] = "^0.5.9";
|
|
218
254
|
packageInfo.scripts["test"] =
|
|
219
255
|
"npm run clean && npm run build:test && npm run unit-test";
|
|
@@ -269,3 +305,30 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) {
|
|
|
269
305
|
|
|
270
306
|
return packageInfo;
|
|
271
307
|
}
|
|
308
|
+
|
|
309
|
+
function appendPathWhenFormat(
|
|
310
|
+
generateTest?: boolean,
|
|
311
|
+
generateSample?: boolean
|
|
312
|
+
) {
|
|
313
|
+
let path = "";
|
|
314
|
+
if (generateTest) {
|
|
315
|
+
path = path + ` "test/**/*.ts"`;
|
|
316
|
+
}
|
|
317
|
+
if (generateSample) {
|
|
318
|
+
path = path + ` "samples-dev/**/*.ts"`;
|
|
319
|
+
}
|
|
320
|
+
return path;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function appednPathWhenLint(generateTest?: boolean) {
|
|
324
|
+
return generateTest ? "test" : "";
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function getClientFilePath(model: RLCModel) {
|
|
328
|
+
const { srcPath } = model;
|
|
329
|
+
const sdkReletivePart = getRelativePartFromSrcPath(srcPath);
|
|
330
|
+
const clientFilename = normalizeName(model.libraryName, NameType.File);
|
|
331
|
+
return sdkReletivePart
|
|
332
|
+
? `src/${sdkReletivePart}/${clientFilename}.ts`
|
|
333
|
+
: `src/${clientFilename}.ts`;
|
|
334
|
+
}
|
|
@@ -35,7 +35,7 @@ Key links:
|
|
|
35
35
|
|
|
36
36
|
### Currently supported environments
|
|
37
37
|
|
|
38
|
-
- Node.js
|
|
38
|
+
- LTS versions of Node.js
|
|
39
39
|
|
|
40
40
|
### Prerequisites
|
|
41
41
|
|
|
@@ -72,7 +72,7 @@ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
|
|
|
72
72
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the \`AZURE_LOG_LEVEL\` environment variable to \`info\`. Alternatively, logging can be enabled at runtime by calling \`setLogLevel\` in the \`@azure/logger\`:
|
|
73
73
|
|
|
74
74
|
\`\`\`javascript
|
|
75
|
-
|
|
75
|
+
const { setLogLevel } = require("@azure/logger");
|
|
76
76
|
|
|
77
77
|
setLogLevel("info");
|
|
78
78
|
\`\`\`
|
|
@@ -168,7 +168,7 @@ function createMetadata(model: RLCModel): Metadata | undefined {
|
|
|
168
168
|
const clientPackageName = packageDetails?.name;
|
|
169
169
|
const clientClassName = getClientName(model);
|
|
170
170
|
const serviceName = getServiceName(model);
|
|
171
|
-
|
|
171
|
+
let apiRefUrlQueryParameter: string = "";
|
|
172
172
|
if (packageDetails?.version.includes("beta")) {
|
|
173
173
|
apiRefUrlQueryParameter = "?view=azure-node-preview";
|
|
174
174
|
}
|
|
@@ -156,7 +156,7 @@ function checkPagingRequest(response: PathUncheckedResponse): void {
|
|
|
156
156
|
];
|
|
157
157
|
if (!Http2xxStatusCodes.includes(response.status)) {
|
|
158
158
|
throw createRestError(
|
|
159
|
-
\`Pagination failed with unexpected statusCode \${response.status
|
|
159
|
+
\`Pagination failed with unexpected statusCode \${response.status}\`,
|
|
160
160
|
response
|
|
161
161
|
);
|
|
162
162
|
}
|