@azure-tools/typespec-java 0.24.0 → 0.26.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/dist/src/code-model-builder.d.ts +4 -0
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +215 -145
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/common/client.d.ts +5 -0
- package/dist/src/common/client.d.ts.map +1 -1
- package/dist/src/common/client.js +11 -0
- package/dist/src/common/client.js.map +1 -1
- package/dist/src/emitter.d.ts +1 -0
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +4 -7
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/external-schemas.d.ts +1 -0
- package/dist/src/external-schemas.d.ts.map +1 -1
- package/dist/src/external-schemas.js +46 -11
- package/dist/src/external-schemas.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +2 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/generator/http-client-generator/target/emitter.jar +0 -0
- package/package.json +8 -8
- package/readme.md +7 -31
|
@@ -8,6 +8,8 @@ export declare class CodeModelBuilder {
|
|
|
8
8
|
private program;
|
|
9
9
|
private typeNameOptions;
|
|
10
10
|
private namespace;
|
|
11
|
+
private baseJavaNamespace;
|
|
12
|
+
private legacyJavaNamespace;
|
|
11
13
|
private sdkContext;
|
|
12
14
|
private options;
|
|
13
15
|
private codeModel;
|
|
@@ -27,6 +29,7 @@ export declare class CodeModelBuilder {
|
|
|
27
29
|
private deduplicateSchemaName;
|
|
28
30
|
private resolveSchemaUsage;
|
|
29
31
|
private processClients;
|
|
32
|
+
private processClient;
|
|
30
33
|
private listSubClientsUnderClient;
|
|
31
34
|
private listServiceMethodsUnderClient;
|
|
32
35
|
/**
|
|
@@ -91,6 +94,7 @@ export declare class CodeModelBuilder {
|
|
|
91
94
|
private isSecret;
|
|
92
95
|
private getMutability;
|
|
93
96
|
private getConvenienceApiName;
|
|
97
|
+
private getBaseJavaNamespace;
|
|
94
98
|
private getJavaNamespace;
|
|
95
99
|
private logWarning;
|
|
96
100
|
private trace;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIT,YAAY,EACZ,aAAa,EAeb,YAAY,EAEZ,YAAY,EAEZ,SAAS,EAKT,MAAM,EAMN,YAAY,EAKb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAyBL,OAAO,EAQR,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIT,YAAY,EACZ,aAAa,EAeb,YAAY,EAEZ,YAAY,EAEZ,SAAS,EAKT,MAAM,EAMN,YAAY,EAKb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAyBL,OAAO,EAQR,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,WAAW,EAKX,OAAO,EACP,IAAI,EAEJ,KAAK,EAUN,MAAM,oBAAoB,CAAC;AAwB5B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAQnD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAgB9C,OAAO,EACL,eAAe,EAShB,MAAM,iBAAiB,CAAC;AAWzB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,iBAAiB,CAAc;IACvC,OAAO,CAAC,mBAAmB,CAAkB;IAC7C,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,SAAS,CAAY;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AAa,CAOjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,IAAI,SAAS,IAAI,SAAS,CAIzB;IAED,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,IAAI,YAAY,IAAI,YAAY,CAK/B;IAED,OAAO,CAAC,iBAAiB,CAAC,CAAe;IACzC,IAAI,gBAAgB,IAAI,YAAY,CAQnC;IAED,OAAO,CAAC,yBAAyB;IA8BjC,OAAO,CAAC,oBAAoB,CAAC,CAAY;IACzC,IAAI,mBAAmB,IAAI,SAAS,CAQnC;IAED,OAAO,CAAC,0BAA0B,CAAC,CAAY;IAC/C,IAAI,yBAAyB,IAAI,SAAS,CASzC;IAED,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,uBAAuB;IAwB/B,OAAO,CAAC,sBAAsB,CAAC,CAAY;IAE3C,OAAO,CAAC,oBAAoB;IA+E5B,OAAO,CAAC,gBAAgB;IAyBxB,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -25,6 +25,8 @@ const { isEqual } = pkg;
|
|
|
25
25
|
export class CodeModelBuilder {
|
|
26
26
|
constructor(program1, context) {
|
|
27
27
|
var _a, _b;
|
|
28
|
+
this.baseJavaNamespace = ""; // it will be set at the start of "build" function
|
|
29
|
+
this.legacyJavaNamespace = false; // backward-compatible mode, that emitter ignores clientNamespace from TCGC
|
|
28
30
|
this.loggingEnabled = false;
|
|
29
31
|
this.schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
|
|
30
32
|
this.typeUnionRefCache = new Map(); // Union means it ref a Union type, null means it does not ref any Union, undefined means type visited but not completed
|
|
@@ -43,8 +45,6 @@ export class CodeModelBuilder {
|
|
|
43
45
|
}
|
|
44
46
|
this.serviceNamespace = service.type;
|
|
45
47
|
this.namespace = getNamespaceFullName(this.serviceNamespace) || "Azure.Client";
|
|
46
|
-
// java namespace
|
|
47
|
-
const javaNamespace = this.getJavaNamespace(this.namespace);
|
|
48
48
|
const namespace1 = this.namespace;
|
|
49
49
|
this.typeNameOptions = {
|
|
50
50
|
// shorten type names by removing TypeSpec and service namespace
|
|
@@ -67,9 +67,7 @@ export class CodeModelBuilder {
|
|
|
67
67
|
summary: this.getSummary(this.serviceNamespace),
|
|
68
68
|
namespace: this.namespace,
|
|
69
69
|
},
|
|
70
|
-
java: {
|
|
71
|
-
namespace: javaNamespace,
|
|
72
|
-
},
|
|
70
|
+
java: {},
|
|
73
71
|
},
|
|
74
72
|
});
|
|
75
73
|
}
|
|
@@ -77,6 +75,20 @@ export class CodeModelBuilder {
|
|
|
77
75
|
this.sdkContext = await createSdkContext(this.emitterContext, "@azure-tools/typespec-java", {
|
|
78
76
|
versioning: { previewStringRegex: /$/ },
|
|
79
77
|
}); // include all versions and do the filter by ourselves
|
|
78
|
+
// java namespace
|
|
79
|
+
if (this.options.namespace) {
|
|
80
|
+
// legacy mode, clientNamespace from TCGC will be ignored
|
|
81
|
+
this.legacyJavaNamespace = true;
|
|
82
|
+
this.baseJavaNamespace = this.options.namespace;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.legacyJavaNamespace = false;
|
|
86
|
+
// baseJavaNamespace is used for model from Azure.Core/Azure.ResourceManager but cannot be mapped to azure-core,
|
|
87
|
+
// or some model (e.g. Options, FileDetails) that is created in this emitter.
|
|
88
|
+
// otherwise, the clientNamespace from SdkType will be used.
|
|
89
|
+
this.baseJavaNamespace = this.getBaseJavaNamespace();
|
|
90
|
+
}
|
|
91
|
+
this.codeModel.language.java.namespace = this.baseJavaNamespace;
|
|
80
92
|
// TODO: reportDiagnostics from TCGC temporary disabled
|
|
81
93
|
// issue https://github.com/Azure/typespec-azure/issues/1675
|
|
82
94
|
// this.program.reportDiagnostics(this.sdkContext.diagnostics);
|
|
@@ -108,7 +120,7 @@ export class CodeModelBuilder {
|
|
|
108
120
|
else {
|
|
109
121
|
const schema = this.processSchema(arg.type, arg.name);
|
|
110
122
|
this.trackSchemaUsage(schema, {
|
|
111
|
-
usage: [SchemaContext.Input, SchemaContext.Output
|
|
123
|
+
usage: [SchemaContext.Input, SchemaContext.Output, SchemaContext.Public],
|
|
112
124
|
});
|
|
113
125
|
parameter = new Parameter(arg.name, (_a = arg.doc) !== null && _a !== void 0 ? _a : "", schema, {
|
|
114
126
|
implementation: ImplementationLocation.Client,
|
|
@@ -237,10 +249,13 @@ export class CodeModelBuilder {
|
|
|
237
249
|
// deduplicate model name
|
|
238
250
|
const nameCount = new Map();
|
|
239
251
|
const deduplicateName = (schema) => {
|
|
240
|
-
var _a, _b;
|
|
252
|
+
var _a, _b, _c, _d;
|
|
241
253
|
const name = schema.language.default.name;
|
|
242
|
-
|
|
243
|
-
|
|
254
|
+
if (name &&
|
|
255
|
+
// skip models under "com.azure.core." in java, or "Azure." in typespec, if branded
|
|
256
|
+
!(this.isBranded() &&
|
|
257
|
+
(((_b = (_a = schema.language.java) === null || _a === void 0 ? void 0 : _a.namespace) === null || _b === void 0 ? void 0 : _b.startsWith("com.azure.core.")) ||
|
|
258
|
+
((_d = (_c = schema.language.default) === null || _c === void 0 ? void 0 : _c.namespace) === null || _d === void 0 ? void 0 : _d.startsWith("Azure."))))) {
|
|
244
259
|
if (!nameCount.has(name)) {
|
|
245
260
|
nameCount.set(name, 1);
|
|
246
261
|
}
|
|
@@ -288,96 +303,110 @@ export class CodeModelBuilder {
|
|
|
288
303
|
}
|
|
289
304
|
}
|
|
290
305
|
processClients() {
|
|
291
|
-
var _a
|
|
306
|
+
var _a;
|
|
292
307
|
// preprocess group-etag-headers
|
|
293
308
|
this.options["group-etag-headers"] = (_a = this.options["group-etag-headers"]) !== null && _a !== void 0 ? _a : true;
|
|
294
309
|
const sdkPackage = this.sdkContext.sdkPackage;
|
|
295
310
|
for (const client of sdkPackage.clients) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
311
|
+
this.processClient(client);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
processClient(client) {
|
|
315
|
+
var _a, _b;
|
|
316
|
+
let clientName = client.name;
|
|
317
|
+
let javaNamespace = this.getJavaNamespace(client);
|
|
318
|
+
const clientFullName = client.name;
|
|
319
|
+
const clientNameSegments = clientFullName.split(".");
|
|
320
|
+
if (clientNameSegments.length > 1) {
|
|
321
|
+
clientName = clientNameSegments.at(-1);
|
|
322
|
+
const clientSubNamespace = clientNameSegments.slice(0, -1).join(".").toLowerCase();
|
|
323
|
+
javaNamespace = javaNamespace + "." + clientSubNamespace;
|
|
324
|
+
}
|
|
325
|
+
const codeModelClient = new CodeModelClient(clientName, (_a = client.doc) !== null && _a !== void 0 ? _a : "", {
|
|
326
|
+
summary: client.summary,
|
|
327
|
+
language: {
|
|
328
|
+
default: {
|
|
329
|
+
namespace: this.namespace,
|
|
314
330
|
},
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
//
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const apiVersion = new ApiVersion();
|
|
334
|
-
apiVersion.version = version;
|
|
335
|
-
codeModelClient.apiVersions.push(apiVersion);
|
|
331
|
+
java: {
|
|
332
|
+
namespace: javaNamespace,
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
// at present, use global security definition
|
|
336
|
+
security: this.codeModel.security,
|
|
337
|
+
});
|
|
338
|
+
codeModelClient.crossLanguageDefinitionId = client.crossLanguageDefinitionId;
|
|
339
|
+
// versioning
|
|
340
|
+
const versions = client.apiVersions;
|
|
341
|
+
if (versions && versions.length > 0) {
|
|
342
|
+
if (!this.sdkContext.apiVersion || ["all", "latest"].includes(this.sdkContext.apiVersion)) {
|
|
343
|
+
this.apiVersion = versions[versions.length - 1];
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
this.apiVersion = versions.find((it) => it === this.sdkContext.apiVersion);
|
|
347
|
+
if (!this.apiVersion) {
|
|
348
|
+
throw new Error("Unrecognized api-version: " + this.sdkContext.apiVersion);
|
|
336
349
|
}
|
|
337
350
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
351
|
+
codeModelClient.apiVersions = [];
|
|
352
|
+
for (const version of this.getFilteredApiVersions(this.apiVersion, versions, this.options["service-version-exclude-preview"])) {
|
|
353
|
+
const apiVersion = new ApiVersion();
|
|
354
|
+
apiVersion.version = version;
|
|
355
|
+
codeModelClient.apiVersions.push(apiVersion);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// client initialization
|
|
359
|
+
let baseUri = "{endpoint}";
|
|
360
|
+
let hostParameters = [];
|
|
361
|
+
client.initialization.properties.forEach((initializationProperty) => {
|
|
362
|
+
if (initializationProperty.kind === "endpoint") {
|
|
363
|
+
let sdkPathParameters = [];
|
|
364
|
+
if (initializationProperty.type.kind === "union") {
|
|
365
|
+
if (initializationProperty.type.variantTypes.length === 2) {
|
|
366
|
+
// only get the sdkPathParameters from the endpoint whose serverUrl is not {"endpoint"}
|
|
367
|
+
for (const endpointType of initializationProperty.type.variantTypes) {
|
|
368
|
+
if (endpointType.kind === "endpoint" && endpointType.serverUrl !== "{endpoint}") {
|
|
369
|
+
sdkPathParameters = endpointType.templateArguments;
|
|
370
|
+
baseUri = endpointType.serverUrl;
|
|
352
371
|
}
|
|
353
372
|
}
|
|
354
|
-
else if (initializationProperty.type.variantTypes.length > 2) {
|
|
355
|
-
throw new Error("Multiple server url defined for one client is not supported yet.");
|
|
356
|
-
}
|
|
357
373
|
}
|
|
358
|
-
else if (initializationProperty.type.
|
|
359
|
-
|
|
360
|
-
baseUri = initializationProperty.type.serverUrl;
|
|
374
|
+
else if (initializationProperty.type.variantTypes.length > 2) {
|
|
375
|
+
throw new Error("Multiple server url defined for one client is not supported yet.");
|
|
361
376
|
}
|
|
362
|
-
hostParameters = this.processHostParameters(sdkPathParameters);
|
|
363
|
-
codeModelClient.addGlobalParameters(hostParameters);
|
|
364
377
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
// operations without operation group
|
|
369
|
-
const serviceMethodsWithoutSubClient = this.listServiceMethodsUnderClient(client);
|
|
370
|
-
let codeModelGroup = new OperationGroup("");
|
|
371
|
-
for (const serviceMethod of serviceMethodsWithoutSubClient) {
|
|
372
|
-
if (!this.needToSkipProcessingOperation(serviceMethod.__raw, clientContext)) {
|
|
373
|
-
codeModelGroup.addOperation(this.processOperation(serviceMethod, clientContext, ""));
|
|
378
|
+
else if (initializationProperty.type.kind === "endpoint") {
|
|
379
|
+
sdkPathParameters = initializationProperty.type.templateArguments;
|
|
380
|
+
baseUri = initializationProperty.type.serverUrl;
|
|
374
381
|
}
|
|
382
|
+
hostParameters = this.processHostParameters(sdkPathParameters);
|
|
383
|
+
codeModelClient.addGlobalParameters(hostParameters);
|
|
375
384
|
}
|
|
376
|
-
|
|
377
|
-
|
|
385
|
+
});
|
|
386
|
+
const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters, codeModelClient.apiVersions);
|
|
387
|
+
const enableSubclient = Boolean(this.options["enable-subclient"]);
|
|
388
|
+
// preprocess operation groups and operations
|
|
389
|
+
// operations without operation group
|
|
390
|
+
const serviceMethodsWithoutSubClient = this.listServiceMethodsUnderClient(client);
|
|
391
|
+
let codeModelGroup = new OperationGroup("");
|
|
392
|
+
for (const serviceMethod of serviceMethodsWithoutSubClient) {
|
|
393
|
+
if (!this.needToSkipProcessingOperation(serviceMethod.__raw, clientContext)) {
|
|
394
|
+
codeModelGroup.addOperation(this.processOperation(serviceMethod, clientContext, ""));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (((_b = codeModelGroup.operations) === null || _b === void 0 ? void 0 : _b.length) > 0 || enableSubclient) {
|
|
398
|
+
codeModelClient.operationGroups.push(codeModelGroup);
|
|
399
|
+
}
|
|
400
|
+
const subClients = this.listSubClientsUnderClient(client, !enableSubclient);
|
|
401
|
+
if (enableSubclient) {
|
|
402
|
+
// subclient, no operation group
|
|
403
|
+
for (const subClient of subClients) {
|
|
404
|
+
const codeModelSubclient = this.processClient(subClient);
|
|
405
|
+
codeModelClient.addSubClient(codeModelSubclient);
|
|
378
406
|
}
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
379
409
|
// operations under operation groups
|
|
380
|
-
const subClients = this.listSubClientsUnderClient(client, true, true);
|
|
381
410
|
for (const subClient of subClients) {
|
|
382
411
|
const serviceMethods = this.listServiceMethodsUnderClient(subClient);
|
|
383
412
|
// operation group with no operation is skipped
|
|
@@ -391,45 +420,47 @@ export class CodeModelBuilder {
|
|
|
391
420
|
codeModelClient.operationGroups.push(codeModelGroup);
|
|
392
421
|
}
|
|
393
422
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
else if (!sharedApiVersions) {
|
|
405
|
-
// first client, set it to sharedApiVersions
|
|
406
|
-
sharedApiVersions = apiVersions;
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
apiVersionSameForAllClients = isEqual(sharedApiVersions, apiVersions);
|
|
410
|
-
}
|
|
411
|
-
if (!apiVersionSameForAllClients) {
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
423
|
+
}
|
|
424
|
+
this.codeModel.clients.push(codeModelClient);
|
|
425
|
+
// postprocess for ServiceVersion
|
|
426
|
+
let apiVersionSameForAllClients = true;
|
|
427
|
+
let sharedApiVersions = undefined;
|
|
428
|
+
for (const client of this.codeModel.clients) {
|
|
429
|
+
const apiVersions = client.apiVersions;
|
|
430
|
+
if (!apiVersions) {
|
|
431
|
+
// client does not have apiVersions
|
|
432
|
+
apiVersionSameForAllClients = false;
|
|
414
433
|
}
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
client.serviceVersion = serviceVersion;
|
|
419
|
-
}
|
|
434
|
+
else if (!sharedApiVersions) {
|
|
435
|
+
// first client, set it to sharedApiVersions
|
|
436
|
+
sharedApiVersions = apiVersions;
|
|
420
437
|
}
|
|
421
438
|
else {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
439
|
+
apiVersionSameForAllClients = isEqual(sharedApiVersions, apiVersions);
|
|
440
|
+
}
|
|
441
|
+
if (!apiVersionSameForAllClients) {
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (apiVersionSameForAllClients) {
|
|
446
|
+
const serviceVersion = getServiceVersion(this.codeModel);
|
|
447
|
+
for (const client of this.codeModel.clients) {
|
|
448
|
+
client.serviceVersion = serviceVersion;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
for (const client of this.codeModel.clients) {
|
|
453
|
+
const apiVersions = client.apiVersions;
|
|
454
|
+
if (apiVersions) {
|
|
455
|
+
client.serviceVersion = getServiceVersion(client);
|
|
427
456
|
}
|
|
428
457
|
}
|
|
429
458
|
}
|
|
459
|
+
return codeModelClient;
|
|
430
460
|
}
|
|
431
|
-
listSubClientsUnderClient(client,
|
|
432
|
-
const
|
|
461
|
+
listSubClientsUnderClient(client, includeNestedSubClients) {
|
|
462
|
+
const isRootClient = !client.parent;
|
|
463
|
+
const subClients = [];
|
|
433
464
|
for (const method of client.methods) {
|
|
434
465
|
if (method.kind === "clientaccessor") {
|
|
435
466
|
const subClient = method.response;
|
|
@@ -438,15 +469,15 @@ export class CodeModelBuilder {
|
|
|
438
469
|
subClient.name =
|
|
439
470
|
removeClientSuffix(client.name) + removeClientSuffix(pascalCase(subClient.name));
|
|
440
471
|
}
|
|
441
|
-
|
|
442
|
-
if (
|
|
443
|
-
for (const operationGroup of this.listSubClientsUnderClient(subClient,
|
|
444
|
-
|
|
472
|
+
subClients.push(subClient);
|
|
473
|
+
if (includeNestedSubClients) {
|
|
474
|
+
for (const operationGroup of this.listSubClientsUnderClient(subClient, includeNestedSubClients)) {
|
|
475
|
+
subClients.push(operationGroup);
|
|
445
476
|
}
|
|
446
477
|
}
|
|
447
478
|
}
|
|
448
479
|
}
|
|
449
|
-
return
|
|
480
|
+
return subClients;
|
|
450
481
|
}
|
|
451
482
|
listServiceMethodsUnderClient(client) {
|
|
452
483
|
const methods = [];
|
|
@@ -661,7 +692,7 @@ export class CodeModelBuilder {
|
|
|
661
692
|
language: {
|
|
662
693
|
java: {
|
|
663
694
|
name: "OperationLocationPollingStrategy",
|
|
664
|
-
namespace: this.
|
|
695
|
+
namespace: this.baseJavaNamespace + ".implementation",
|
|
665
696
|
},
|
|
666
697
|
},
|
|
667
698
|
});
|
|
@@ -1073,7 +1104,7 @@ export class CodeModelBuilder {
|
|
|
1073
1104
|
namespace: namespace,
|
|
1074
1105
|
},
|
|
1075
1106
|
java: {
|
|
1076
|
-
namespace: this.getJavaNamespace(
|
|
1107
|
+
namespace: this.getJavaNamespace(),
|
|
1077
1108
|
},
|
|
1078
1109
|
},
|
|
1079
1110
|
}));
|
|
@@ -1444,7 +1475,7 @@ export class CodeModelBuilder {
|
|
|
1444
1475
|
namespace: namespace,
|
|
1445
1476
|
},
|
|
1446
1477
|
java: {
|
|
1447
|
-
namespace: this.getJavaNamespace(
|
|
1478
|
+
namespace: this.getJavaNamespace(type),
|
|
1448
1479
|
},
|
|
1449
1480
|
},
|
|
1450
1481
|
});
|
|
@@ -1518,7 +1549,7 @@ export class CodeModelBuilder {
|
|
|
1518
1549
|
namespace: namespace,
|
|
1519
1550
|
},
|
|
1520
1551
|
java: {
|
|
1521
|
-
namespace: this.getJavaNamespace(
|
|
1552
|
+
namespace: this.getJavaNamespace(type),
|
|
1522
1553
|
},
|
|
1523
1554
|
},
|
|
1524
1555
|
});
|
|
@@ -1596,7 +1627,7 @@ export class CodeModelBuilder {
|
|
|
1596
1627
|
if (type.kind === "Model") {
|
|
1597
1628
|
const effective = getEffectiveModelType(program, type, isSchemaProperty);
|
|
1598
1629
|
if (this.isArm() && ((_a = getNamespace(effective)) === null || _a === void 0 ? void 0 : _a.startsWith("Azure.ResourceManager"))) {
|
|
1599
|
-
// Catalog is TrackedResource<CatalogProperties>
|
|
1630
|
+
// e.g. typespec: Catalog is TrackedResource<CatalogProperties>
|
|
1600
1631
|
return type;
|
|
1601
1632
|
}
|
|
1602
1633
|
else if (effective.name) {
|
|
@@ -1682,7 +1713,7 @@ export class CodeModelBuilder {
|
|
|
1682
1713
|
namespace: namespace,
|
|
1683
1714
|
},
|
|
1684
1715
|
java: {
|
|
1685
|
-
namespace: this.getJavaNamespace(
|
|
1716
|
+
namespace: this.getJavaNamespace(),
|
|
1686
1717
|
},
|
|
1687
1718
|
},
|
|
1688
1719
|
});
|
|
@@ -1703,7 +1734,7 @@ export class CodeModelBuilder {
|
|
|
1703
1734
|
}));
|
|
1704
1735
|
}
|
|
1705
1736
|
getUnionVariantName(type, option) {
|
|
1706
|
-
var _a;
|
|
1737
|
+
var _a, _b;
|
|
1707
1738
|
if (type === undefined) {
|
|
1708
1739
|
throw new Error("type is undefined.");
|
|
1709
1740
|
}
|
|
@@ -1759,25 +1790,29 @@ export class CodeModelBuilder {
|
|
|
1759
1790
|
return pascalCase(type.value ? "True" : "False");
|
|
1760
1791
|
case "Union":
|
|
1761
1792
|
return (_a = type.name) !== null && _a !== void 0 ? _a : "Union";
|
|
1793
|
+
case "UnionVariant":
|
|
1794
|
+
return (_b = (typeof type.name === "string" ? type.name : undefined)) !== null && _b !== void 0 ? _b : "UnionVariant";
|
|
1762
1795
|
default:
|
|
1763
1796
|
throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
|
|
1764
1797
|
}
|
|
1765
1798
|
}
|
|
1766
1799
|
processMultipartFormDataFilePropertySchema(property) {
|
|
1767
|
-
var _a
|
|
1800
|
+
var _a;
|
|
1768
1801
|
const processSchemaFunc = (type) => this.processSchema(type, "");
|
|
1802
|
+
const processNamespaceFunc = (type) => {
|
|
1803
|
+
var _a;
|
|
1804
|
+
const namespace = type.kind === "model" ? ((_a = getNamespace(type.__raw)) !== null && _a !== void 0 ? _a : this.namespace) : this.namespace;
|
|
1805
|
+
const javaNamespace = type.kind === "model" ? this.getJavaNamespace(type) : this.getJavaNamespace();
|
|
1806
|
+
return { namespace, javaNamespace };
|
|
1807
|
+
};
|
|
1769
1808
|
if (property.type.kind === "bytes" || property.type.kind === "model") {
|
|
1770
|
-
const
|
|
1771
|
-
|
|
1772
|
-
: this.namespace;
|
|
1773
|
-
return getFileDetailsSchema(property, (_b = getNamespace(property.type.__raw)) !== null && _b !== void 0 ? _b : this.namespace, namespace, this.codeModel.schemas, this.binarySchema, this.stringSchema, processSchemaFunc);
|
|
1809
|
+
const namespaceTuple = processNamespaceFunc(property.type);
|
|
1810
|
+
return getFileDetailsSchema(property, namespaceTuple.namespace, namespaceTuple.javaNamespace, this.codeModel.schemas, this.binarySchema, this.stringSchema, processSchemaFunc);
|
|
1774
1811
|
}
|
|
1775
1812
|
else if (property.type.kind === "array" &&
|
|
1776
1813
|
(property.type.valueType.kind === "bytes" || property.type.valueType.kind === "model")) {
|
|
1777
|
-
const
|
|
1778
|
-
|
|
1779
|
-
: this.namespace;
|
|
1780
|
-
return new ArraySchema(property.name, (_d = property.doc) !== null && _d !== void 0 ? _d : "", getFileDetailsSchema(property, namespace, this.getJavaNamespace(namespace), this.codeModel.schemas, this.binarySchema, this.stringSchema, processSchemaFunc), {
|
|
1814
|
+
const namespaceTuple = processNamespaceFunc(property.type.valueType);
|
|
1815
|
+
return new ArraySchema(property.name, (_a = property.doc) !== null && _a !== void 0 ? _a : "", getFileDetailsSchema(property, namespaceTuple.namespace, namespaceTuple.javaNamespace, this.codeModel.schemas, this.binarySchema, this.stringSchema, processSchemaFunc), {
|
|
1781
1816
|
summary: property.summary,
|
|
1782
1817
|
});
|
|
1783
1818
|
}
|
|
@@ -1866,18 +1901,53 @@ export class CodeModelBuilder {
|
|
|
1866
1901
|
return undefined;
|
|
1867
1902
|
}
|
|
1868
1903
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1904
|
+
getBaseJavaNamespace() {
|
|
1905
|
+
// hack, just find the shortest clientNamespace among all clients
|
|
1906
|
+
// hopefully it is the root namespace of the SDK
|
|
1907
|
+
let baseJavaNamespace = undefined;
|
|
1908
|
+
this.sdkContext.sdkPackage.clients
|
|
1909
|
+
.map((it) => it.clientNamespace)
|
|
1910
|
+
.forEach((it) => {
|
|
1911
|
+
if (baseJavaNamespace === undefined || baseJavaNamespace.length > it.length) {
|
|
1912
|
+
baseJavaNamespace = it;
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
// fallback if there is no client
|
|
1916
|
+
if (!baseJavaNamespace) {
|
|
1917
|
+
baseJavaNamespace = this.namespace;
|
|
1918
|
+
}
|
|
1919
|
+
return baseJavaNamespace.toLowerCase();
|
|
1920
|
+
}
|
|
1921
|
+
getJavaNamespace(type = undefined) {
|
|
1922
|
+
// clientNamespace from TCGC
|
|
1923
|
+
const clientNamespace = type === null || type === void 0 ? void 0 : type.clientNamespace;
|
|
1924
|
+
if (this.isBranded() && type) {
|
|
1925
|
+
// special handling for namespace of model that cannot be mapped to azure-core
|
|
1926
|
+
if (type.crossLanguageDefinitionId === "TypeSpec.Http.File") {
|
|
1927
|
+
// TypeSpec.Http.File
|
|
1928
|
+
return this.baseJavaNamespace;
|
|
1929
|
+
}
|
|
1930
|
+
else if (type.crossLanguageDefinitionId === "Azure.Core.Foundations.OperationState") {
|
|
1931
|
+
// Azure.Core.OperationState
|
|
1932
|
+
return this.baseJavaNamespace;
|
|
1933
|
+
}
|
|
1934
|
+
else if (type.crossLanguageDefinitionId === "Azure.Core.ResourceOperationStatus" ||
|
|
1935
|
+
type.crossLanguageDefinitionId === "Azure.Core.Foundations.OperationStatus") {
|
|
1936
|
+
// Azure.Core.ResourceOperationStatus<>
|
|
1937
|
+
// Azure.Core.Foundations.OperationStatus<>
|
|
1938
|
+
// usually this model will not be generated, but javadoc of protocol method requires it be in SDK namespace
|
|
1939
|
+
return this.baseJavaNamespace;
|
|
1940
|
+
}
|
|
1941
|
+
else if (type.crossLanguageDefinitionId.startsWith("Azure.ResourceManager.")) {
|
|
1942
|
+
// models in Azure.ResourceManager
|
|
1943
|
+
return this.baseJavaNamespace;
|
|
1944
|
+
}
|
|
1874
1945
|
}
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
return baseJavaNamespace + namespace.slice(tspNamespace.length).toLowerCase();
|
|
1946
|
+
if (this.legacyJavaNamespace || !clientNamespace) {
|
|
1947
|
+
return this.baseJavaNamespace;
|
|
1878
1948
|
}
|
|
1879
1949
|
else {
|
|
1880
|
-
return
|
|
1950
|
+
return clientNamespace.toLowerCase();
|
|
1881
1951
|
}
|
|
1882
1952
|
}
|
|
1883
1953
|
logWarning(msg) {
|