@azure-tools/typespec-java 0.7.1 → 0.7.3
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/src/code-model-builder.d.ts +3 -3
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +76 -44
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/emitter.d.ts +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/models.d.ts +5 -2
- package/dist/src/models.d.ts.map +1 -1
- package/dist/src/models.js +19 -1
- package/dist/src/models.js.map +1 -1
- package/dist/src/operation-utils.d.ts +18 -0
- package/dist/src/operation-utils.d.ts.map +1 -0
- package/dist/src/operation-utils.js +162 -0
- package/dist/src/operation-utils.js.map +1 -0
- package/dist/src/type-utils.d.ts +31 -0
- package/dist/src/type-utils.d.ts.map +1 -0
- package/dist/src/type-utils.js +112 -0
- package/dist/src/type-utils.js.map +1 -0
- package/dist/src/utils.d.ts +3 -44
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +11 -246
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/target/azure-typespec-extension-jar-with-dependencies.jar +0 -0
package/dist/src/utils.js
CHANGED
|
@@ -1,57 +1,6 @@
|
|
|
1
|
-
import { NoTarget
|
|
2
|
-
import { getHeaderFieldName, getQueryParamName, getPathParamName, isStatusCode, getAllHttpServices, } from "@typespec/http";
|
|
3
|
-
import { resolveOperationId } from "@typespec/openapi";
|
|
4
|
-
import { ServiceVersion } from "./common/client.js";
|
|
5
|
-
import { getVersion } from "@typespec/versioning";
|
|
6
|
-
export const specialHeaderNames = new Set([
|
|
7
|
-
"repeatability-request-id",
|
|
8
|
-
"repeatability-first-sent",
|
|
9
|
-
"x-ms-client-request-id",
|
|
10
|
-
]);
|
|
11
|
-
export const originApiVersion = "modelerfour:synthesized/api-version";
|
|
12
|
-
/** Acts as a cache for processing inputs.
|
|
13
|
-
*
|
|
14
|
-
* If the input is undefined, the output is always undefined.
|
|
15
|
-
* for a given input, the process is only ever called once.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
export class ProcessingCache {
|
|
20
|
-
constructor(transform) {
|
|
21
|
-
this.transform = transform;
|
|
22
|
-
this.results = new Map();
|
|
23
|
-
}
|
|
24
|
-
has(original) {
|
|
25
|
-
return !!original && !!this.results.get(original);
|
|
26
|
-
}
|
|
27
|
-
set(original, result) {
|
|
28
|
-
this.results.set(original, result);
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
process(original, ...args) {
|
|
32
|
-
if (original) {
|
|
33
|
-
const result = this.results.get(original) || this.transform(original, ...args);
|
|
34
|
-
this.results.set(original, result);
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/** adds only if the item is not in the collection already
|
|
41
|
-
*
|
|
42
|
-
* @note While this isn't very efficient, it doesn't disturb the original
|
|
43
|
-
* collection, so you won't get inadvertent side effects from using Set, etc.
|
|
44
|
-
*/
|
|
45
|
-
export function pushDistinct(targetArray, ...items) {
|
|
46
|
-
for (const i of items) {
|
|
47
|
-
if (!targetArray.includes(i)) {
|
|
48
|
-
targetArray.push(i);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return targetArray;
|
|
52
|
-
}
|
|
1
|
+
import { NoTarget } from "@typespec/compiler";
|
|
53
2
|
export function logWarning(program, msg) {
|
|
54
|
-
|
|
3
|
+
trace(program, msg);
|
|
55
4
|
program.reportDiagnostic({
|
|
56
5
|
code: "typespec-java",
|
|
57
6
|
severity: "warning",
|
|
@@ -59,62 +8,16 @@ export function logWarning(program, msg) {
|
|
|
59
8
|
target: NoTarget,
|
|
60
9
|
});
|
|
61
10
|
}
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
if (options["examples-directory"]) {
|
|
65
|
-
const operationIdExamplesMap = new Map();
|
|
66
|
-
const service = ignoreDiagnostics(getAllHttpServices(program))[0];
|
|
67
|
-
let version = undefined;
|
|
68
|
-
const versioning = getVersion(program, service.namespace);
|
|
69
|
-
if (versioning && versioning.getVersions()) {
|
|
70
|
-
const versions = versioning.getVersions();
|
|
71
|
-
version = versions[versions.length - 1].value;
|
|
72
|
-
}
|
|
73
|
-
const exampleDir = version
|
|
74
|
-
? resolvePath(options["examples-directory"], version)
|
|
75
|
-
: resolvePath(options["examples-directory"]);
|
|
76
|
-
try {
|
|
77
|
-
if (!(await program.host.stat(exampleDir)).isDirectory())
|
|
78
|
-
return operationExamplesMap;
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
logWarning(program, `Examples directory '${exampleDir}' does not exist.`);
|
|
82
|
-
return operationExamplesMap;
|
|
83
|
-
}
|
|
84
|
-
const exampleFiles = await program.host.readDir(exampleDir);
|
|
85
|
-
for (const fileName of exampleFiles) {
|
|
86
|
-
try {
|
|
87
|
-
const exampleFile = await program.host.readFile(resolvePath(exampleDir, fileName));
|
|
88
|
-
const example = JSON.parse(exampleFile.text);
|
|
89
|
-
if (!example.operationId) {
|
|
90
|
-
logWarning(program, `Example file '${fileName}' is missing operationId.`);
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (!operationIdExamplesMap.has(example.operationId)) {
|
|
94
|
-
operationIdExamplesMap.set(example.operationId, example);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
logWarning(program, `Failed to load example file '${fileName}'.`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (operationIdExamplesMap.size > 0) {
|
|
102
|
-
const routes = service.operations;
|
|
103
|
-
routes.forEach((it) => {
|
|
104
|
-
const operationId = pascalCaseForOperationId(resolveOperationId(program, it.operation));
|
|
105
|
-
if (operationIdExamplesMap.has(operationId)) {
|
|
106
|
-
operationExamplesMap.set(it.operation, operationIdExamplesMap.get(operationId));
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return operationExamplesMap;
|
|
11
|
+
export function trace(program, msg) {
|
|
12
|
+
program.trace("typespec-java", msg);
|
|
112
13
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
.
|
|
116
|
-
|
|
117
|
-
|
|
14
|
+
export function pascalCase(name) {
|
|
15
|
+
if (name.length > 0) {
|
|
16
|
+
return name[0].toUpperCase() + name.slice(1);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return name;
|
|
20
|
+
}
|
|
118
21
|
}
|
|
119
22
|
export function getNamespace(type) {
|
|
120
23
|
let namespaceRef = type.namespace;
|
|
@@ -128,145 +31,7 @@ export function getNamespace(type) {
|
|
|
128
31
|
export function getJavaNamespace(namespace) {
|
|
129
32
|
return namespace ? "com." + namespace.toLowerCase() : undefined;
|
|
130
33
|
}
|
|
131
|
-
export function modelContainsDerivedModel(model) {
|
|
132
|
-
return !isTemplateDeclaration(model) && !(isTemplateInstance(model) && model.derivedModels.length === 0);
|
|
133
|
-
}
|
|
134
|
-
export function isModelReferredInTemplate(template, target) {
|
|
135
|
-
var _a, _b, _c;
|
|
136
|
-
return (template === target ||
|
|
137
|
-
((_c = (_b = (_a = template === null || template === void 0 ? void 0 : template.templateMapper) === null || _a === void 0 ? void 0 : _a.args) === null || _b === void 0 ? void 0 : _b.some((it) => it.kind === "Model" || it.kind === "Union" ? isModelReferredInTemplate(it, target) : false)) !== null && _c !== void 0 ? _c : false));
|
|
138
|
-
}
|
|
139
|
-
export function getNameForTemplate(target) {
|
|
140
|
-
switch (target.kind) {
|
|
141
|
-
case "Model": {
|
|
142
|
-
let name = target.name;
|
|
143
|
-
if (target.templateMapper && target.templateMapper.args) {
|
|
144
|
-
name = name + target.templateMapper.args.map((it) => getNameForTemplate(it)).join("");
|
|
145
|
-
}
|
|
146
|
-
return name;
|
|
147
|
-
}
|
|
148
|
-
case "String":
|
|
149
|
-
return target.value;
|
|
150
|
-
default:
|
|
151
|
-
return "";
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
34
|
export function stringArrayContainsIgnoreCase(stringList, str) {
|
|
155
35
|
return stringList && str ? stringList.findIndex((s) => s.toLowerCase() === str.toLowerCase()) != -1 : false;
|
|
156
36
|
}
|
|
157
|
-
export function operationContainsJsonMergePatch(op) {
|
|
158
|
-
for (const param of op.parameters.parameters) {
|
|
159
|
-
if (param.type === "header" && param.name.toLowerCase() === "content-type") {
|
|
160
|
-
if (param.param.type.kind === "String" && param.param.type.value === "application/merge-patch+json") {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
export function pascalCase(name) {
|
|
168
|
-
if (name.length > 0) {
|
|
169
|
-
return name[0].toUpperCase() + name.slice(1);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
return name;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
export function isPayloadProperty(program, property) {
|
|
176
|
-
const headerInfo = getHeaderFieldName(program, property);
|
|
177
|
-
const queryInfo = getQueryParamName(program, property);
|
|
178
|
-
const pathInfo = getPathParamName(program, property);
|
|
179
|
-
const statusCodeInfo = isStatusCode(program, property);
|
|
180
|
-
return !(headerInfo || queryInfo || pathInfo || statusCodeInfo);
|
|
181
|
-
}
|
|
182
|
-
export function getClientApiVersions(client) {
|
|
183
|
-
var _a;
|
|
184
|
-
if ((_a = client.globalParameters) === null || _a === void 0 ? void 0 : _a.find((it) => it.origin === originApiVersion)) {
|
|
185
|
-
return client.apiVersions;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
export function getServiceVersion(client) {
|
|
192
|
-
let name = client.language.default.name;
|
|
193
|
-
let description = name;
|
|
194
|
-
if (name.endsWith("Client")) {
|
|
195
|
-
name = name.substring(0, name.length - "Client".length);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
description = description + "Client";
|
|
199
|
-
}
|
|
200
|
-
if (name.endsWith("Service")) {
|
|
201
|
-
name = name + "Version";
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
name = name + "ServiceVersion";
|
|
205
|
-
}
|
|
206
|
-
return new ServiceVersion(name, description);
|
|
207
|
-
}
|
|
208
|
-
export function isLroMetadataSupported(operation, lroMetadata) {
|
|
209
|
-
const azureCoreLroSvs = [
|
|
210
|
-
"LongRunningResourceCreateOrReplace",
|
|
211
|
-
"LongRunningResourceCreateOrUpdate",
|
|
212
|
-
"LongRunningResourceDelete",
|
|
213
|
-
"LongRunningResourceAction",
|
|
214
|
-
];
|
|
215
|
-
let ret = false;
|
|
216
|
-
if (lroMetadata.statusMonitorStep &&
|
|
217
|
-
lroMetadata.statusMonitorStep.responseModel.name === "OperationStatus" &&
|
|
218
|
-
getNamespace(lroMetadata.statusMonitorStep.responseModel) === "Azure.Core.Foundations") {
|
|
219
|
-
if (operation.node.signature.kind === SyntaxKind.OperationSignatureReference) {
|
|
220
|
-
if (operation.node.signature.baseOperation.target.kind === SyntaxKind.MemberExpression) {
|
|
221
|
-
const sv = operation.node.signature.baseOperation.target.id.sv;
|
|
222
|
-
ret = azureCoreLroSvs.includes(sv);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return ret;
|
|
227
|
-
}
|
|
228
|
-
export function isLroNewPollingStrategy(operation, lroMetadata) {
|
|
229
|
-
// at present, it is same as isLroMetadataSupported, which checks if operation uses template from Azure.Core
|
|
230
|
-
// will change later when isLroMetadataSupported extends to other types of operations
|
|
231
|
-
return true;
|
|
232
|
-
// if (verb === "put" && !lroMetadata.finalStep) {
|
|
233
|
-
// // PUT without last GET on resource
|
|
234
|
-
// useNewPollStrategy = true;
|
|
235
|
-
// } else if (
|
|
236
|
-
// verb === "post" &&
|
|
237
|
-
// lroMetadata.finalStep &&
|
|
238
|
-
// lroMetadata.finalStep.kind === "pollingSuccessProperty" &&
|
|
239
|
-
// lroMetadata.finalStep.target.name === "result"
|
|
240
|
-
// ) {
|
|
241
|
-
// // POST with final result in "result" property
|
|
242
|
-
// useNewPollStrategy = true;
|
|
243
|
-
// }
|
|
244
|
-
}
|
|
245
|
-
export function getDurationFormat(encode) {
|
|
246
|
-
let format = "duration-rfc3339";
|
|
247
|
-
// duration encoded as seconds
|
|
248
|
-
if (encode.encoding === "seconds") {
|
|
249
|
-
const scalarName = encode.type.name;
|
|
250
|
-
if (scalarName.startsWith("int") || scalarName.startsWith("uint") || scalarName === "safeint") {
|
|
251
|
-
format = "seconds-integer";
|
|
252
|
-
}
|
|
253
|
-
else if (scalarName.startsWith("float")) {
|
|
254
|
-
format = "seconds-number";
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
throw new Error(`Unrecognized scalar type used by duration encoded as seconds: '${scalarName}'.`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return format;
|
|
261
|
-
}
|
|
262
|
-
export function hasScalarAsBase(type, scalarName) {
|
|
263
|
-
let scalarType = type;
|
|
264
|
-
while (scalarType) {
|
|
265
|
-
if (scalarType.name === scalarName) {
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
scalarType = scalarType.baseScalar;
|
|
269
|
-
}
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
37
|
//# sourceMappingURL=utils.js.map
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,QAAQ,EAA6B,MAAM,oBAAoB,CAAC;AAEtF,MAAM,UAAU,UAAU,CAAC,OAAgB,EAAE,GAAW;IACtD,KAAK,CAAC,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