@azure-tools/typespec-java 0.25.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 +206 -141
- 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 +2 -1
- package/dist/src/emitter.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 +3 -3
- 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;IAC7B,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,gBAAgB,CAAY;IAEpC,OAAO,CAAC,cAAc,CAAkB;IAExC,QAAQ,CA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,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,
|
|
@@ -291,96 +303,110 @@ export class CodeModelBuilder {
|
|
|
291
303
|
}
|
|
292
304
|
}
|
|
293
305
|
processClients() {
|
|
294
|
-
var _a
|
|
306
|
+
var _a;
|
|
295
307
|
// preprocess group-etag-headers
|
|
296
308
|
this.options["group-etag-headers"] = (_a = this.options["group-etag-headers"]) !== null && _a !== void 0 ? _a : true;
|
|
297
309
|
const sdkPackage = this.sdkContext.sdkPackage;
|
|
298
310
|
for (const client of sdkPackage.clients) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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,
|
|
317
330
|
},
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
//
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const apiVersion = new ApiVersion();
|
|
337
|
-
apiVersion.version = version;
|
|
338
|
-
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);
|
|
339
349
|
}
|
|
340
350
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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;
|
|
355
371
|
}
|
|
356
372
|
}
|
|
357
|
-
else if (initializationProperty.type.variantTypes.length > 2) {
|
|
358
|
-
throw new Error("Multiple server url defined for one client is not supported yet.");
|
|
359
|
-
}
|
|
360
373
|
}
|
|
361
|
-
else if (initializationProperty.type.
|
|
362
|
-
|
|
363
|
-
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.");
|
|
364
376
|
}
|
|
365
|
-
hostParameters = this.processHostParameters(sdkPathParameters);
|
|
366
|
-
codeModelClient.addGlobalParameters(hostParameters);
|
|
367
377
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
// operations without operation group
|
|
372
|
-
const serviceMethodsWithoutSubClient = this.listServiceMethodsUnderClient(client);
|
|
373
|
-
let codeModelGroup = new OperationGroup("");
|
|
374
|
-
for (const serviceMethod of serviceMethodsWithoutSubClient) {
|
|
375
|
-
if (!this.needToSkipProcessingOperation(serviceMethod.__raw, clientContext)) {
|
|
376
|
-
codeModelGroup.addOperation(this.processOperation(serviceMethod, clientContext, ""));
|
|
378
|
+
else if (initializationProperty.type.kind === "endpoint") {
|
|
379
|
+
sdkPathParameters = initializationProperty.type.templateArguments;
|
|
380
|
+
baseUri = initializationProperty.type.serverUrl;
|
|
377
381
|
}
|
|
382
|
+
hostParameters = this.processHostParameters(sdkPathParameters);
|
|
383
|
+
codeModelClient.addGlobalParameters(hostParameters);
|
|
378
384
|
}
|
|
379
|
-
|
|
380
|
-
|
|
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);
|
|
381
406
|
}
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
382
409
|
// operations under operation groups
|
|
383
|
-
const subClients = this.listSubClientsUnderClient(client, true, true);
|
|
384
410
|
for (const subClient of subClients) {
|
|
385
411
|
const serviceMethods = this.listServiceMethodsUnderClient(subClient);
|
|
386
412
|
// operation group with no operation is skipped
|
|
@@ -394,45 +420,47 @@ export class CodeModelBuilder {
|
|
|
394
420
|
codeModelClient.operationGroups.push(codeModelGroup);
|
|
395
421
|
}
|
|
396
422
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
else if (!sharedApiVersions) {
|
|
408
|
-
// first client, set it to sharedApiVersions
|
|
409
|
-
sharedApiVersions = apiVersions;
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
apiVersionSameForAllClients = isEqual(sharedApiVersions, apiVersions);
|
|
413
|
-
}
|
|
414
|
-
if (!apiVersionSameForAllClients) {
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
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;
|
|
417
433
|
}
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
client.serviceVersion = serviceVersion;
|
|
422
|
-
}
|
|
434
|
+
else if (!sharedApiVersions) {
|
|
435
|
+
// first client, set it to sharedApiVersions
|
|
436
|
+
sharedApiVersions = apiVersions;
|
|
423
437
|
}
|
|
424
438
|
else {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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);
|
|
430
456
|
}
|
|
431
457
|
}
|
|
432
458
|
}
|
|
459
|
+
return codeModelClient;
|
|
433
460
|
}
|
|
434
|
-
listSubClientsUnderClient(client,
|
|
435
|
-
const
|
|
461
|
+
listSubClientsUnderClient(client, includeNestedSubClients) {
|
|
462
|
+
const isRootClient = !client.parent;
|
|
463
|
+
const subClients = [];
|
|
436
464
|
for (const method of client.methods) {
|
|
437
465
|
if (method.kind === "clientaccessor") {
|
|
438
466
|
const subClient = method.response;
|
|
@@ -441,15 +469,15 @@ export class CodeModelBuilder {
|
|
|
441
469
|
subClient.name =
|
|
442
470
|
removeClientSuffix(client.name) + removeClientSuffix(pascalCase(subClient.name));
|
|
443
471
|
}
|
|
444
|
-
|
|
445
|
-
if (
|
|
446
|
-
for (const operationGroup of this.listSubClientsUnderClient(subClient,
|
|
447
|
-
|
|
472
|
+
subClients.push(subClient);
|
|
473
|
+
if (includeNestedSubClients) {
|
|
474
|
+
for (const operationGroup of this.listSubClientsUnderClient(subClient, includeNestedSubClients)) {
|
|
475
|
+
subClients.push(operationGroup);
|
|
448
476
|
}
|
|
449
477
|
}
|
|
450
478
|
}
|
|
451
479
|
}
|
|
452
|
-
return
|
|
480
|
+
return subClients;
|
|
453
481
|
}
|
|
454
482
|
listServiceMethodsUnderClient(client) {
|
|
455
483
|
const methods = [];
|
|
@@ -664,7 +692,7 @@ export class CodeModelBuilder {
|
|
|
664
692
|
language: {
|
|
665
693
|
java: {
|
|
666
694
|
name: "OperationLocationPollingStrategy",
|
|
667
|
-
namespace: this.
|
|
695
|
+
namespace: this.baseJavaNamespace + ".implementation",
|
|
668
696
|
},
|
|
669
697
|
},
|
|
670
698
|
});
|
|
@@ -1076,7 +1104,7 @@ export class CodeModelBuilder {
|
|
|
1076
1104
|
namespace: namespace,
|
|
1077
1105
|
},
|
|
1078
1106
|
java: {
|
|
1079
|
-
namespace: this.getJavaNamespace(
|
|
1107
|
+
namespace: this.getJavaNamespace(),
|
|
1080
1108
|
},
|
|
1081
1109
|
},
|
|
1082
1110
|
}));
|
|
@@ -1447,7 +1475,7 @@ export class CodeModelBuilder {
|
|
|
1447
1475
|
namespace: namespace,
|
|
1448
1476
|
},
|
|
1449
1477
|
java: {
|
|
1450
|
-
namespace: this.getJavaNamespace(
|
|
1478
|
+
namespace: this.getJavaNamespace(type),
|
|
1451
1479
|
},
|
|
1452
1480
|
},
|
|
1453
1481
|
});
|
|
@@ -1521,7 +1549,7 @@ export class CodeModelBuilder {
|
|
|
1521
1549
|
namespace: namespace,
|
|
1522
1550
|
},
|
|
1523
1551
|
java: {
|
|
1524
|
-
namespace: this.getJavaNamespace(
|
|
1552
|
+
namespace: this.getJavaNamespace(type),
|
|
1525
1553
|
},
|
|
1526
1554
|
},
|
|
1527
1555
|
});
|
|
@@ -1599,7 +1627,7 @@ export class CodeModelBuilder {
|
|
|
1599
1627
|
if (type.kind === "Model") {
|
|
1600
1628
|
const effective = getEffectiveModelType(program, type, isSchemaProperty);
|
|
1601
1629
|
if (this.isArm() && ((_a = getNamespace(effective)) === null || _a === void 0 ? void 0 : _a.startsWith("Azure.ResourceManager"))) {
|
|
1602
|
-
// Catalog is TrackedResource<CatalogProperties>
|
|
1630
|
+
// e.g. typespec: Catalog is TrackedResource<CatalogProperties>
|
|
1603
1631
|
return type;
|
|
1604
1632
|
}
|
|
1605
1633
|
else if (effective.name) {
|
|
@@ -1685,7 +1713,7 @@ export class CodeModelBuilder {
|
|
|
1685
1713
|
namespace: namespace,
|
|
1686
1714
|
},
|
|
1687
1715
|
java: {
|
|
1688
|
-
namespace: this.getJavaNamespace(
|
|
1716
|
+
namespace: this.getJavaNamespace(),
|
|
1689
1717
|
},
|
|
1690
1718
|
},
|
|
1691
1719
|
});
|
|
@@ -1769,20 +1797,22 @@ export class CodeModelBuilder {
|
|
|
1769
1797
|
}
|
|
1770
1798
|
}
|
|
1771
1799
|
processMultipartFormDataFilePropertySchema(property) {
|
|
1772
|
-
var _a
|
|
1800
|
+
var _a;
|
|
1773
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
|
+
};
|
|
1774
1808
|
if (property.type.kind === "bytes" || property.type.kind === "model") {
|
|
1775
|
-
const
|
|
1776
|
-
|
|
1777
|
-
: this.namespace;
|
|
1778
|
-
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);
|
|
1779
1811
|
}
|
|
1780
1812
|
else if (property.type.kind === "array" &&
|
|
1781
1813
|
(property.type.valueType.kind === "bytes" || property.type.valueType.kind === "model")) {
|
|
1782
|
-
const
|
|
1783
|
-
|
|
1784
|
-
: this.namespace;
|
|
1785
|
-
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), {
|
|
1786
1816
|
summary: property.summary,
|
|
1787
1817
|
});
|
|
1788
1818
|
}
|
|
@@ -1871,18 +1901,53 @@ export class CodeModelBuilder {
|
|
|
1871
1901
|
return undefined;
|
|
1872
1902
|
}
|
|
1873
1903
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
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
|
+
}
|
|
1879
1945
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
return baseJavaNamespace + namespace.slice(tspNamespace.length).toLowerCase();
|
|
1946
|
+
if (this.legacyJavaNamespace || !clientNamespace) {
|
|
1947
|
+
return this.baseJavaNamespace;
|
|
1883
1948
|
}
|
|
1884
1949
|
else {
|
|
1885
|
-
return
|
|
1950
|
+
return clientNamespace.toLowerCase();
|
|
1886
1951
|
}
|
|
1887
1952
|
}
|
|
1888
1953
|
logWarning(msg) {
|