@azure-tools/rlc-common 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +23 -0
- package/.prettierignore +1 -0
- package/.prettierrc +7 -0
- package/.rush/temp/package-deps_build.json +53 -0
- package/.rush/temp/shrinkwrap-deps.json +147 -0
- package/CHANGELOG.md +61 -0
- package/CONTRIBUTING.md +30 -0
- package/README.md +3 -0
- package/dist/buildClient.js +268 -0
- package/dist/buildClient.js.map +1 -0
- package/dist/buildClientDefinitions.js +160 -0
- package/dist/buildClientDefinitions.js.map +1 -0
- package/dist/buildIndexFile.js +170 -0
- package/dist/buildIndexFile.js.map +1 -0
- package/dist/buildIsUnexpectedHelper.js +220 -0
- package/dist/buildIsUnexpectedHelper.js.map +1 -0
- package/dist/buildMethodShortcuts.js +50 -0
- package/dist/buildMethodShortcuts.js.map +1 -0
- package/dist/buildObjectTypes.js +286 -0
- package/dist/buildObjectTypes.js.map +1 -0
- package/dist/buildPaginateHelper.js +30 -0
- package/dist/buildPaginateHelper.js.map +1 -0
- package/dist/buildParameterTypes.js +315 -0
- package/dist/buildParameterTypes.js.map +1 -0
- package/dist/buildPollingHelper.js +21 -0
- package/dist/buildPollingHelper.js.map +1 -0
- package/dist/buildResponseTypes.js +135 -0
- package/dist/buildResponseTypes.js.map +1 -0
- package/dist/buildSchemaType.js +65 -0
- package/dist/buildSchemaType.js.map +1 -0
- package/dist/buildSerializeHelper.js +35 -0
- package/dist/buildSerializeHelper.js.map +1 -0
- package/dist/buildTopLevelIndexFile.js +48 -0
- package/dist/buildTopLevelIndexFile.js.map +1 -0
- package/dist/helpers/nameConstructors.js +41 -0
- package/dist/helpers/nameConstructors.js.map +1 -0
- package/dist/helpers/nameUtils.js +196 -0
- package/dist/helpers/nameUtils.js.map +1 -0
- package/dist/helpers/operationHelpers.js +103 -0
- package/dist/helpers/operationHelpers.js.map +1 -0
- package/dist/helpers/pathUtils.js +13 -0
- package/dist/helpers/pathUtils.js.map +1 -0
- package/dist/helpers/schemaHelpers.js +27 -0
- package/dist/helpers/schemaHelpers.js.map +1 -0
- package/dist/helpers/shortcutMethods.js +46 -0
- package/dist/helpers/shortcutMethods.js.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.js +18 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/metadata/buildApiExtractorConfig.js +56 -0
- package/dist/metadata/buildApiExtractorConfig.js.map +1 -0
- package/dist/metadata/buildESLintConfig.js +33 -0
- package/dist/metadata/buildESLintConfig.js.map +1 -0
- package/dist/metadata/buildLicenseFile.js +41 -0
- package/dist/metadata/buildLicenseFile.js.map +1 -0
- package/dist/metadata/buildPackageFile.js +274 -0
- package/dist/metadata/buildPackageFile.js.map +1 -0
- package/dist/metadata/buildReadmeFile.js +170 -0
- package/dist/metadata/buildReadmeFile.js.map +1 -0
- package/dist/metadata/buildRollupConfig.js +144 -0
- package/dist/metadata/buildRollupConfig.js.map +1 -0
- package/dist/metadata/buildTsConfig.js +72 -0
- package/dist/metadata/buildTsConfig.js.map +1 -0
- package/dist/package.json +1 -0
- package/dist/static/paginateContent.js +214 -0
- package/dist/static/paginateContent.js.map +1 -0
- package/dist/static/pollingContent.js +98 -0
- package/dist/static/pollingContent.js.map +1 -0
- package/dist/static/serializeHelper.js +30 -0
- package/dist/static/serializeHelper.js.map +1 -0
- package/dist/test/buildEnvFile.js +31 -0
- package/dist/test/buildEnvFile.js.map +1 -0
- package/dist/test/buildKarmaConfig.js +19 -0
- package/dist/test/buildKarmaConfig.js.map +1 -0
- package/dist/test/buildRecordedClient.js +22 -0
- package/dist/test/buildRecordedClient.js.map +1 -0
- package/dist/test/buildSampleTest.js +19 -0
- package/dist/test/buildSampleTest.js.map +1 -0
- package/dist/test/template.js +191 -0
- package/dist/test/template.js.map +1 -0
- package/dist-esm/buildClient.js +261 -0
- package/dist-esm/buildClient.js.map +1 -0
- package/dist-esm/buildClientDefinitions.js +155 -0
- package/dist-esm/buildClientDefinitions.js.map +1 -0
- package/dist-esm/buildIndexFile.js +165 -0
- package/dist-esm/buildIndexFile.js.map +1 -0
- package/dist-esm/buildIsUnexpectedHelper.js +216 -0
- package/dist-esm/buildIsUnexpectedHelper.js.map +1 -0
- package/dist-esm/buildMethodShortcuts.js +46 -0
- package/dist-esm/buildMethodShortcuts.js.map +1 -0
- package/dist-esm/buildObjectTypes.js +288 -0
- package/dist-esm/buildObjectTypes.js.map +1 -0
- package/dist-esm/buildPaginateHelper.js +26 -0
- package/dist-esm/buildPaginateHelper.js.map +1 -0
- package/dist-esm/buildParameterTypes.js +321 -0
- package/dist-esm/buildParameterTypes.js.map +1 -0
- package/dist-esm/buildPollingHelper.js +17 -0
- package/dist-esm/buildPollingHelper.js.map +1 -0
- package/dist-esm/buildResponseTypes.js +140 -0
- package/dist-esm/buildResponseTypes.js.map +1 -0
- package/dist-esm/buildSchemaType.js +60 -0
- package/dist-esm/buildSchemaType.js.map +1 -0
- package/dist-esm/buildSerializeHelper.js +31 -0
- package/dist-esm/buildSerializeHelper.js.map +1 -0
- package/dist-esm/buildTopLevelIndexFile.js +44 -0
- package/dist-esm/buildTopLevelIndexFile.js.map +1 -0
- package/dist-esm/helpers/nameConstructors.js +34 -0
- package/dist-esm/helpers/nameConstructors.js.map +1 -0
- package/dist-esm/helpers/nameUtils.js +187 -0
- package/dist-esm/helpers/nameUtils.js.map +1 -0
- package/dist-esm/helpers/operationHelpers.js +84 -0
- package/dist-esm/helpers/operationHelpers.js.map +1 -0
- package/dist-esm/helpers/pathUtils.js +9 -0
- package/dist-esm/helpers/pathUtils.js.map +1 -0
- package/dist-esm/helpers/schemaHelpers.js +21 -0
- package/dist-esm/helpers/schemaHelpers.js.map +1 -0
- package/dist-esm/helpers/shortcutMethods.js +42 -0
- package/dist-esm/helpers/shortcutMethods.js.map +1 -0
- package/dist-esm/index.js +29 -0
- package/dist-esm/index.js.map +1 -0
- package/dist-esm/interfaces.js +15 -0
- package/dist-esm/interfaces.js.map +1 -0
- package/dist-esm/metadata/buildApiExtractorConfig.js +51 -0
- package/dist-esm/metadata/buildApiExtractorConfig.js.map +1 -0
- package/dist-esm/metadata/buildESLintConfig.js +28 -0
- package/dist-esm/metadata/buildESLintConfig.js.map +1 -0
- package/dist-esm/metadata/buildLicenseFile.js +36 -0
- package/dist-esm/metadata/buildLicenseFile.js.map +1 -0
- package/dist-esm/metadata/buildPackageFile.js +276 -0
- package/dist-esm/metadata/buildPackageFile.js.map +1 -0
- package/dist-esm/metadata/buildReadmeFile.js +167 -0
- package/dist-esm/metadata/buildReadmeFile.js.map +1 -0
- package/dist-esm/metadata/buildRollupConfig.js +139 -0
- package/dist-esm/metadata/buildRollupConfig.js.map +1 -0
- package/dist-esm/metadata/buildTsConfig.js +67 -0
- package/dist-esm/metadata/buildTsConfig.js.map +1 -0
- package/dist-esm/package.json +1 -0
- package/dist-esm/static/paginateContent.js +211 -0
- package/dist-esm/static/paginateContent.js.map +1 -0
- package/dist-esm/static/pollingContent.js +95 -0
- package/dist-esm/static/pollingContent.js.map +1 -0
- package/dist-esm/static/serializeHelper.js +27 -0
- package/dist-esm/static/serializeHelper.js.map +1 -0
- package/dist-esm/test/buildEnvFile.js +24 -0
- package/dist-esm/test/buildEnvFile.js.map +1 -0
- package/dist-esm/test/buildKarmaConfig.js +14 -0
- package/dist-esm/test/buildKarmaConfig.js.map +1 -0
- package/dist-esm/test/buildRecordedClient.js +17 -0
- package/dist-esm/test/buildRecordedClient.js.map +1 -0
- package/dist-esm/test/buildSampleTest.js +14 -0
- package/dist-esm/test/buildSampleTest.js.map +1 -0
- package/dist-esm/test/template.js +188 -0
- package/dist-esm/test/template.js.map +1 -0
- package/package.json +46 -0
- package/publishPackage.js +11 -0
- package/rlc-common.build.log +2 -0
- package/src/buildClient.ts +353 -0
- package/src/buildClientDefinitions.ts +235 -0
- package/src/buildIndexFile.ts +202 -0
- package/src/buildIsUnexpectedHelper.ts +240 -0
- package/src/buildMethodShortcuts.ts +75 -0
- package/src/buildObjectTypes.ts +449 -0
- package/src/buildPaginateHelper.ts +33 -0
- package/src/buildParameterTypes.ts +477 -0
- package/src/buildPollingHelper.ts +18 -0
- package/src/buildResponseTypes.ts +186 -0
- package/src/buildSchemaType.ts +85 -0
- package/src/buildSerializeHelper.ts +42 -0
- package/src/buildTopLevelIndexFile.ts +52 -0
- package/src/helpers/nameConstructors.ts +93 -0
- package/src/helpers/nameUtils.ts +227 -0
- package/src/helpers/operationHelpers.ts +119 -0
- package/src/helpers/pathUtils.ts +9 -0
- package/src/helpers/schemaHelpers.ts +25 -0
- package/src/helpers/shortcutMethods.ts +60 -0
- package/src/index.ts +29 -0
- package/src/interfaces.ts +227 -0
- package/src/metadata/buildApiExtractorConfig.ts +59 -0
- package/src/metadata/buildESLintConfig.ts +34 -0
- package/src/metadata/buildLicenseFile.ts +39 -0
- package/src/metadata/buildPackageFile.ts +334 -0
- package/src/metadata/buildReadmeFile.ts +231 -0
- package/src/metadata/buildRollupConfig.ts +147 -0
- package/src/metadata/buildTsConfig.ts +79 -0
- package/src/static/paginateContent.ts +210 -0
- package/src/static/pollingContent.ts +94 -0
- package/src/static/serializeHelper.ts +29 -0
- package/src/test/buildEnvFile.ts +26 -0
- package/src/test/buildKarmaConfig.ts +15 -0
- package/src/test/buildRecordedClient.ts +18 -0
- package/src/test/buildSampleTest.ts +15 -0
- package/src/test/template.ts +191 -0
- package/tsconfig-cjs.json +9 -0
- package/tsconfig-common.json +13 -0
- package/tsconfig.json +13 -0
- package/types/buildClient.d.ts +2 -0
- package/types/buildClientDefinitions.d.ts +5 -0
- package/types/buildIndexFile.d.ts +5 -0
- package/types/buildIsUnexpectedHelper.d.ts +5 -0
- package/types/buildMethodShortcuts.d.ts +4 -0
- package/types/buildObjectTypes.d.ts +15 -0
- package/types/buildPaginateHelper.d.ts +5 -0
- package/types/buildParameterTypes.d.ts +13 -0
- package/types/buildPollingHelper.d.ts +5 -0
- package/types/buildResponseTypes.d.ts +5 -0
- package/types/buildSchemaType.d.ts +19 -0
- package/types/buildSerializeHelper.d.ts +5 -0
- package/types/buildTopLevelIndexFile.d.ts +5 -0
- package/types/helpers/nameConstructors.d.ts +28 -0
- package/types/helpers/nameUtils.d.ts +25 -0
- package/types/helpers/operationHelpers.d.ts +13 -0
- package/types/helpers/pathUtils.d.ts +1 -0
- package/types/helpers/schemaHelpers.d.ts +4 -0
- package/types/helpers/shortcutMethods.d.ts +3 -0
- package/types/index.d.ts +26 -0
- package/types/interfaces.d.ts +200 -0
- package/types/metadata/buildApiExtractorConfig.d.ts +5 -0
- package/types/metadata/buildESLintConfig.d.ts +5 -0
- package/types/metadata/buildLicenseFile.d.ts +5 -0
- package/types/metadata/buildPackageFile.d.ts +5 -0
- package/types/metadata/buildReadmeFile.d.ts +5 -0
- package/types/metadata/buildRollupConfig.d.ts +5 -0
- package/types/metadata/buildTsConfig.d.ts +5 -0
- package/types/static/paginateContent.d.ts +1 -0
- package/types/static/pollingContent.d.ts +1 -0
- package/types/static/serializeHelper.d.ts +4 -0
- package/types/test/buildEnvFile.d.ts +9 -0
- package/types/test/buildKarmaConfig.d.ts +5 -0
- package/types/test/buildRecordedClient.d.ts +5 -0
- package/types/test/buildSampleTest.d.ts +5 -0
- package/types/test/template.d.ts +5 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
OptionalKind,
|
|
6
|
+
MethodSignatureStructure,
|
|
7
|
+
InterfaceDeclarationStructure
|
|
8
|
+
} from "ts-morph";
|
|
9
|
+
import { PathMetadata, Paths } from "../interfaces.js";
|
|
10
|
+
import { buildMethodDefinitions } from "./operationHelpers.js";
|
|
11
|
+
import { NameType, normalizeName } from "./nameUtils.js";
|
|
12
|
+
|
|
13
|
+
export function generateMethodShortcuts(
|
|
14
|
+
paths: Paths
|
|
15
|
+
): OptionalKind<InterfaceDeclarationStructure>[] {
|
|
16
|
+
const keys: Record<string, OptionalKind<MethodSignatureStructure>[]> = {};
|
|
17
|
+
for (const path in paths) {
|
|
18
|
+
const groupName = paths[path].operationGroupName;
|
|
19
|
+
const definitions = buildOperationDefinitions(paths[path]);
|
|
20
|
+
if (!keys[groupName]) {
|
|
21
|
+
keys[groupName] = definitions;
|
|
22
|
+
} else {
|
|
23
|
+
keys[groupName] = [...keys[groupName], ...definitions];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const interfaces: OptionalKind<InterfaceDeclarationStructure>[] = [];
|
|
28
|
+
|
|
29
|
+
for (const interfaceName in keys) {
|
|
30
|
+
const methods = keys[interfaceName];
|
|
31
|
+
interfaces.push({
|
|
32
|
+
name: `${interfaceName}Operations`,
|
|
33
|
+
methods: methods,
|
|
34
|
+
isExported: true,
|
|
35
|
+
docs: [`Contains operations for ${interfaceName} operations`]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return interfaces;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildOperationDefinitions(
|
|
43
|
+
path: PathMetadata
|
|
44
|
+
): OptionalKind<MethodSignatureStructure>[] {
|
|
45
|
+
let ops: OptionalKind<MethodSignatureStructure>[] = [];
|
|
46
|
+
|
|
47
|
+
for (const verb in path.methods) {
|
|
48
|
+
const methods = path.methods[verb];
|
|
49
|
+
for (const method of methods) {
|
|
50
|
+
const name = normalizeName(method.operationName, NameType.Property);
|
|
51
|
+
const pathParams = path.pathParameters;
|
|
52
|
+
const methodDefinitions = buildMethodDefinitions(
|
|
53
|
+
{ [name]: [method] },
|
|
54
|
+
pathParams
|
|
55
|
+
);
|
|
56
|
+
ops = [...ops, ...methodDefinitions];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return ops;
|
|
60
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
export * from "./interfaces.js";
|
|
5
|
+
export * from "./buildClientDefinitions.js";
|
|
6
|
+
export * from "./buildSchemaType.js";
|
|
7
|
+
export * from "./buildClient.js";
|
|
8
|
+
export * from "./helpers/nameConstructors.js";
|
|
9
|
+
export * from "./buildResponseTypes.js";
|
|
10
|
+
export * from "./helpers/shortcutMethods.js";
|
|
11
|
+
export * from "./helpers/nameUtils.js";
|
|
12
|
+
export * from "./buildParameterTypes.js";
|
|
13
|
+
export * from "./buildIsUnexpectedHelper.js";
|
|
14
|
+
export * from "./buildTopLevelIndexFile.js";
|
|
15
|
+
export * from "./buildIndexFile.js";
|
|
16
|
+
export * from "./buildPaginateHelper.js";
|
|
17
|
+
export * from "./buildPollingHelper.js";
|
|
18
|
+
export * from "./test/buildKarmaConfig.js";
|
|
19
|
+
export * from "./test/buildEnvFile.js";
|
|
20
|
+
export * from "./test/buildRecordedClient.js";
|
|
21
|
+
export * from "./test/buildSampleTest.js";
|
|
22
|
+
export * from "./metadata/buildReadmeFile.js";
|
|
23
|
+
export * from "./metadata/buildApiExtractorConfig.js";
|
|
24
|
+
export * from "./metadata/buildPackageFile.js";
|
|
25
|
+
export * from "./metadata/buildRollupConfig.js";
|
|
26
|
+
export * from "./metadata/buildTsConfig.js";
|
|
27
|
+
export * from "./metadata/buildESLintConfig.js";
|
|
28
|
+
export * from "./metadata/buildLicenseFile.js";
|
|
29
|
+
export * from "./buildSerializeHelper.js";
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
export interface RLCModel {
|
|
4
|
+
libraryName: string;
|
|
5
|
+
srcPath: string;
|
|
6
|
+
paths: Paths;
|
|
7
|
+
options?: RLCOptions;
|
|
8
|
+
schemas: Schema[];
|
|
9
|
+
apiVersionInQueryParam?: Parameter;
|
|
10
|
+
parameters?: OperationParameter[];
|
|
11
|
+
responses?: OperationResponse[];
|
|
12
|
+
importSet?: Map<ImportKind, Set<string>>;
|
|
13
|
+
annotations?: AnnotationDetails;
|
|
14
|
+
urlInfo?: UrlInfo;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface PathTemplateApiVersion {
|
|
18
|
+
value: string;
|
|
19
|
+
templateName: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface UrlInfo {
|
|
23
|
+
endpoint?: string;
|
|
24
|
+
urlParameters?: PathParameter[];
|
|
25
|
+
pathTemplateApiVersion?: PathTemplateApiVersion;
|
|
26
|
+
}
|
|
27
|
+
export interface AnnotationDetails {
|
|
28
|
+
hasPaging?: boolean;
|
|
29
|
+
hasLongRunning?: boolean;
|
|
30
|
+
pageDetails?: PagingDetails;
|
|
31
|
+
hasMultiCollection?: boolean;
|
|
32
|
+
hasPipeCollection?: boolean;
|
|
33
|
+
hasSsvCollection?: boolean;
|
|
34
|
+
hasTsvCollection?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface PagingDetails {
|
|
38
|
+
itemNames: string[];
|
|
39
|
+
nextLinkNames: string[];
|
|
40
|
+
isComplexPaging: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type Methods = {
|
|
44
|
+
[key: string]: [OperationMethod];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export interface ResponseTypes {
|
|
48
|
+
success: string[];
|
|
49
|
+
error: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface OperationMethod {
|
|
53
|
+
optionsName: string;
|
|
54
|
+
description: string;
|
|
55
|
+
hasOptionalOptions: boolean;
|
|
56
|
+
returnType: string;
|
|
57
|
+
successStatus: string[];
|
|
58
|
+
responseTypes: ResponseTypes;
|
|
59
|
+
operationName: string;
|
|
60
|
+
annotations?: OperationAnnotations;
|
|
61
|
+
}
|
|
62
|
+
export interface PathMetadata {
|
|
63
|
+
name: string;
|
|
64
|
+
pathParameters: PathParameter[];
|
|
65
|
+
methods: Methods;
|
|
66
|
+
operationGroupName: string;
|
|
67
|
+
description: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type Paths = Record<string, PathMetadata>;
|
|
71
|
+
|
|
72
|
+
export type PathParameter = {
|
|
73
|
+
name: string;
|
|
74
|
+
type: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
value?: string | number | boolean;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export interface OperationAnnotations {
|
|
80
|
+
isLongRunning?: boolean;
|
|
81
|
+
isPageable?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface RLCOptions {
|
|
85
|
+
includeShortcuts?: boolean;
|
|
86
|
+
multiClient?: boolean;
|
|
87
|
+
batch?: any[];
|
|
88
|
+
packageDetails?: PackageDetails;
|
|
89
|
+
addCredentials?: boolean;
|
|
90
|
+
credentialScopes?: string[];
|
|
91
|
+
credentialKeyHeaderName?: string;
|
|
92
|
+
generateMetadata?: boolean;
|
|
93
|
+
generateTest?: boolean;
|
|
94
|
+
generateSample?: boolean;
|
|
95
|
+
azureSdkForJs?: boolean;
|
|
96
|
+
azureOutputDirectory?: string;
|
|
97
|
+
isCadlTest?: boolean;
|
|
98
|
+
title?: string;
|
|
99
|
+
dependencyInfo?: DependencyInfo;
|
|
100
|
+
productDocLink?: string;
|
|
101
|
+
serviceInfo?: ServiceInfo;
|
|
102
|
+
azureArm?: boolean;
|
|
103
|
+
sourceFrom?: "Cadl" | "Swagger";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface ServiceInfo {
|
|
107
|
+
title?: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface DependencyInfo {
|
|
112
|
+
link: string;
|
|
113
|
+
description: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export enum ImportKind {
|
|
117
|
+
ResponseOutput,
|
|
118
|
+
ParameterInput
|
|
119
|
+
}
|
|
120
|
+
export interface File {
|
|
121
|
+
path: string;
|
|
122
|
+
content: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export enum SchemaContext {
|
|
126
|
+
/** Schema is used as an input to an operation. */
|
|
127
|
+
Input = "input",
|
|
128
|
+
/** Schema is used as an output from an operation. */
|
|
129
|
+
Output = "output",
|
|
130
|
+
/** Schema is used as an exception from an operation. */
|
|
131
|
+
Exception = "exception"
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface Schema {
|
|
135
|
+
name: string;
|
|
136
|
+
type: string;
|
|
137
|
+
typeName?: string;
|
|
138
|
+
outputTypeName?: string;
|
|
139
|
+
description?: string;
|
|
140
|
+
required?: boolean;
|
|
141
|
+
default?: any;
|
|
142
|
+
readOnly?: boolean;
|
|
143
|
+
usage?: SchemaContext[];
|
|
144
|
+
alias?: string;
|
|
145
|
+
outputAlias?: string;
|
|
146
|
+
fromCore?: boolean;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface ObjectSchema extends Schema {
|
|
150
|
+
properties?: Record<string, Schema>;
|
|
151
|
+
discriminatorValue?: string;
|
|
152
|
+
discriminator?: Schema;
|
|
153
|
+
isPolyParent?: boolean;
|
|
154
|
+
children?: {
|
|
155
|
+
all?: ObjectSchema[];
|
|
156
|
+
immediate?: ObjectSchema[];
|
|
157
|
+
};
|
|
158
|
+
parents?: {
|
|
159
|
+
all?: ObjectSchema[];
|
|
160
|
+
immediate?: ObjectSchema[];
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface DictionarySchema extends Schema {
|
|
165
|
+
valueTypeName?: string;
|
|
166
|
+
outputValueTypeName?: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface Property extends Schema {}
|
|
170
|
+
|
|
171
|
+
export interface Parameter extends Schema {}
|
|
172
|
+
|
|
173
|
+
export interface PackageDetails {
|
|
174
|
+
name: string;
|
|
175
|
+
scopeName?: string;
|
|
176
|
+
nameWithoutScope?: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
version: string;
|
|
179
|
+
}
|
|
180
|
+
export interface OperationParameter {
|
|
181
|
+
operationGroup: string;
|
|
182
|
+
operationName: string;
|
|
183
|
+
/**
|
|
184
|
+
* An operation with multiple request parameters means that
|
|
185
|
+
* the operation can get different values for content-type and each value
|
|
186
|
+
* may have a different type associated to it.
|
|
187
|
+
*/
|
|
188
|
+
parameters: ParameterMetadatas[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface ParameterMetadatas {
|
|
192
|
+
parameters?: ParameterMetadata[];
|
|
193
|
+
body?: ParameterBodyMetadata;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface ParameterBodyMetadata {
|
|
197
|
+
// In case of formData we'd get multiple properties in body marked as partialBody
|
|
198
|
+
isPartialBody?: boolean;
|
|
199
|
+
body?: ParameterBodySchema[];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type ParameterBodySchema = Schema;
|
|
203
|
+
export interface ParameterMetadata {
|
|
204
|
+
type: "query" | "path" | "header";
|
|
205
|
+
name: string;
|
|
206
|
+
param: Schema;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface OperationResponse {
|
|
210
|
+
operationGroup: string;
|
|
211
|
+
operationName: string;
|
|
212
|
+
responses: ResponseMetadata[];
|
|
213
|
+
}
|
|
214
|
+
export interface ResponseMetadata {
|
|
215
|
+
statusCode: string;
|
|
216
|
+
description?: string;
|
|
217
|
+
headers?: ResponseHeaderSchema[];
|
|
218
|
+
body?: ResponseBodySchema;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type ResponseHeaderSchema = Schema;
|
|
222
|
+
export type ResponseBodySchema = Schema;
|
|
223
|
+
|
|
224
|
+
export type ContentBuilder = {
|
|
225
|
+
(model: RLCModel): File | undefined;
|
|
226
|
+
(model: RLCModel, hasSampleGenerated?: boolean): File | undefined;
|
|
227
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { Project } from "ts-morph";
|
|
5
|
+
import { RLCModel } from "../interfaces.js";
|
|
6
|
+
|
|
7
|
+
export function buildApiExtractorConfig(model: RLCModel) {
|
|
8
|
+
const generateMetadata = Boolean(model.options?.generateMetadata);
|
|
9
|
+
if (!generateMetadata) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const { generateTest, packageDetails } = model.options || {};
|
|
13
|
+
const project = new Project();
|
|
14
|
+
const config = {
|
|
15
|
+
$schema:
|
|
16
|
+
"https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
17
|
+
mainEntryPointFilePath: `./types${generateTest ? "/src" : ""}/index.d.ts`,
|
|
18
|
+
docModel: {
|
|
19
|
+
enabled: true
|
|
20
|
+
},
|
|
21
|
+
apiReport: {
|
|
22
|
+
enabled: true,
|
|
23
|
+
reportFolder: "./review"
|
|
24
|
+
},
|
|
25
|
+
dtsRollup: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
untrimmedFilePath: "",
|
|
28
|
+
publicTrimmedFilePath: `./types/${packageDetails?.nameWithoutScope}.d.ts`
|
|
29
|
+
},
|
|
30
|
+
messages: {
|
|
31
|
+
tsdocMessageReporting: {
|
|
32
|
+
default: {
|
|
33
|
+
logLevel: "none"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
extractorMessageReporting: {
|
|
37
|
+
"ae-missing-release-tag": {
|
|
38
|
+
logLevel: "none"
|
|
39
|
+
},
|
|
40
|
+
"ae-unresolved-link": {
|
|
41
|
+
logLevel: "none"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const filePath = "api-extractor.json";
|
|
48
|
+
const configFile = project.createSourceFile(
|
|
49
|
+
filePath,
|
|
50
|
+
JSON.stringify(config),
|
|
51
|
+
{
|
|
52
|
+
overwrite: true
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
return {
|
|
56
|
+
path: filePath,
|
|
57
|
+
content: configFile.getFullText()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import { RLCModel } from "../interfaces.js";
|
|
3
|
+
|
|
4
|
+
const esLintConfig = {
|
|
5
|
+
plugins: ["@azure/azure-sdk"],
|
|
6
|
+
extends: ["plugin:@azure/azure-sdk/azure-sdk-base"],
|
|
7
|
+
rules: {
|
|
8
|
+
"@azure/azure-sdk/ts-modules-only-named": "warn",
|
|
9
|
+
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
|
|
10
|
+
"@azure/azure-sdk/ts-package-json-types": "warn",
|
|
11
|
+
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
|
|
12
|
+
"tsdoc/syntax": "warn"
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function buildEsLintConfig(model: RLCModel) {
|
|
17
|
+
const generateMetadata = Boolean(model.options?.generateMetadata);
|
|
18
|
+
if (!generateMetadata) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const project = new Project();
|
|
22
|
+
const filePath = ".eslintrc.json";
|
|
23
|
+
const configFile = project.createSourceFile(
|
|
24
|
+
".eslintrc.json",
|
|
25
|
+
JSON.stringify(esLintConfig),
|
|
26
|
+
{
|
|
27
|
+
overwrite: true
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
return {
|
|
31
|
+
path: filePath,
|
|
32
|
+
content: configFile.getFullText()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { RLCModel } from "../interfaces.js";
|
|
5
|
+
|
|
6
|
+
const mitLicenseText = `
|
|
7
|
+
The MIT License (MIT)
|
|
8
|
+
|
|
9
|
+
Copyright (c) ${new Date().getFullYear()} Microsoft
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
export function buildLicenseFile(model: RLCModel) {
|
|
31
|
+
const generateMetadata = Boolean(model.options?.generateMetadata);
|
|
32
|
+
if (!generateMetadata) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
path: "LICENSE",
|
|
37
|
+
content: mitLicenseText.trim()
|
|
38
|
+
};
|
|
39
|
+
}
|