@azure-tools/typespec-java 0.27.1 → 0.27.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 +1 -7
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +191 -139
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/common/client.d.ts +1 -4
- package/dist/src/common/client.d.ts.map +1 -1
- package/dist/src/common/operation.d.ts +1 -2
- package/dist/src/common/operation.d.ts.map +1 -1
- package/dist/src/common/operation.js.map +1 -1
- package/dist/src/emitter.d.ts +1 -34
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +54 -56
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/external-schemas.d.ts.map +1 -1
- package/dist/src/external-schemas.js +3 -4
- package/dist/src/external-schemas.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +224 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +114 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/operation-utils.d.ts +1 -2
- package/dist/src/operation-utils.d.ts.map +1 -1
- package/dist/src/operation-utils.js +0 -6
- package/dist/src/operation-utils.js.map +1 -1
- package/dist/src/type-utils.d.ts +2 -2
- package/dist/src/type-utils.d.ts.map +1 -1
- package/dist/src/type-utils.js +5 -3
- package/dist/src/type-utils.js.map +1 -1
- package/dist/src/utils.d.ts +11 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +17 -20
- package/dist/src/utils.js.map +1 -1
- package/dist/src/validate.d.ts +1 -0
- package/dist/src/validate.d.ts.map +1 -1
- package/dist/src/validate.js +68 -23
- package/dist/src/validate.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/generator/http-client-generator/target/emitter.jar +0 -0
- package/package.json +40 -37
- package/readme.md +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AnySchema, ApiVersion, ArraySchema, BinaryResponse, BinarySchema, BooleanSchema, ByteArraySchema, ChoiceValue, DateSchema, DateTimeSchema, DictionarySchema, Discriminator, GroupProperty, GroupSchema, HttpHeader, HttpParameter, ImplementationLocation, KeySecurityScheme, Language, Metadata, NumberSchema, OAuth2SecurityScheme, ObjectSchema, OperationGroup, Parameter, ParameterLocation, Property, Relations, Response, SchemaResponse, SchemaType, Security, SerializationStyle, StringSchema, TimeSchema, UnixTimeSchema, UriSchema, VirtualParameter, } from "@autorest/codemodel";
|
|
2
2
|
import { KnownMediaType } from "@azure-tools/codegen";
|
|
3
|
-
import { createSdkContext, getAllModels,
|
|
4
|
-
import {
|
|
5
|
-
import { Visibility, getAuthentication,
|
|
3
|
+
import { createSdkContext, getAllModels, isApiVersion, isSdkBuiltInKind, isSdkIntKind, } from "@azure-tools/typespec-client-generator-core";
|
|
4
|
+
import { NoTarget, getDoc, getNamespaceFullName, getOverloadedOperation, getSummary, isArrayModelType, isRecordModelType, listServices, } from "@typespec/compiler";
|
|
5
|
+
import { Visibility, getAuthentication, } from "@typespec/http";
|
|
6
6
|
import { getSegment } from "@typespec/rest";
|
|
7
7
|
import { getAddedOnVersions } from "@typespec/versioning";
|
|
8
8
|
import { fail } from "assert";
|
|
9
9
|
import pkg from "lodash";
|
|
10
|
-
import { Client as CodeModelClient
|
|
10
|
+
import { Client as CodeModelClient } from "./common/client.js";
|
|
11
11
|
import { CodeModel } from "./common/code-model.js";
|
|
12
12
|
import { LongRunningMetadata } from "./common/long-running-metadata.js";
|
|
13
13
|
import { Operation as CodeModelOperation, ConvenienceApi, Request } from "./common/operation.js";
|
|
@@ -17,31 +17,31 @@ import { OrSchema } from "./common/schemas/relationship.js";
|
|
|
17
17
|
import { DurationSchema } from "./common/schemas/time.js";
|
|
18
18
|
import { SchemaContext } from "./common/schemas/usage.js";
|
|
19
19
|
import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./external-schemas.js";
|
|
20
|
+
import { createDiagnostic, reportDiagnostic } from "./lib.js";
|
|
20
21
|
import { ClientContext } from "./models.js";
|
|
21
|
-
import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, getServiceVersion, isKnownContentType, isLroNewPollingStrategy,
|
|
22
|
-
import { ProcessingCache, getAccess, getDurationFormat, getNonNullSdkType, getUnionDescription, getUsage,
|
|
23
|
-
import {
|
|
22
|
+
import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, getServiceVersion, isKnownContentType, isLroNewPollingStrategy, operationIsJsonMergePatch, operationIsMultipart, operationIsMultipleContentTypes, } from "./operation-utils.js";
|
|
23
|
+
import { ProcessingCache, getAccess, getDurationFormat, getNonNullSdkType, getPropertySerializedName, getUnionDescription, getUsage, modelIs, pushDistinct, } from "./type-utils.js";
|
|
24
|
+
import { DiagnosticError, getNamespace, isStableApiVersion, pascalCase, removeClientSuffix, stringArrayContainsIgnoreCase, trace, } from "./utils.js";
|
|
24
25
|
const { isEqual } = pkg;
|
|
25
26
|
export class CodeModelBuilder {
|
|
26
27
|
constructor(program1, context) {
|
|
27
|
-
var _a, _b
|
|
28
|
-
this.loggingEnabled = false;
|
|
28
|
+
var _a, _b;
|
|
29
29
|
this.schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
|
|
30
30
|
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
|
|
31
31
|
this.options = context.options;
|
|
32
32
|
this.program = program1;
|
|
33
33
|
this.emitterContext = context;
|
|
34
|
-
if ((_a = this.options["dev-options"]) === null || _a === void 0 ? void 0 : _a.loglevel) {
|
|
35
|
-
this.loggingEnabled = true;
|
|
36
|
-
}
|
|
37
34
|
if (this.options["skip-special-headers"]) {
|
|
38
35
|
this.options["skip-special-headers"].forEach((it) => SPECIAL_HEADER_NAMES.add(it.toLowerCase()));
|
|
39
36
|
}
|
|
40
37
|
const service = listServices(this.program)[0];
|
|
41
38
|
if (!service) {
|
|
42
|
-
this.
|
|
39
|
+
reportDiagnostic(this.program, {
|
|
40
|
+
code: "no-service",
|
|
41
|
+
target: NoTarget,
|
|
42
|
+
});
|
|
43
43
|
}
|
|
44
|
-
this.serviceNamespace = (
|
|
44
|
+
this.serviceNamespace = (_a = service === null || service === void 0 ? void 0 : service.type) !== null && _a !== void 0 ? _a : this.program.getGlobalNamespaceType();
|
|
45
45
|
this.namespace = getNamespaceFullName(this.serviceNamespace) || "Client";
|
|
46
46
|
const namespace1 = this.namespace;
|
|
47
47
|
this.typeNameOptions = {
|
|
@@ -52,7 +52,7 @@ export class CodeModelBuilder {
|
|
|
52
52
|
},
|
|
53
53
|
};
|
|
54
54
|
// init code model
|
|
55
|
-
const title = (
|
|
55
|
+
const title = (_b = this.options["service-name"]) !== null && _b !== void 0 ? _b : this.serviceNamespace.name;
|
|
56
56
|
const description = this.getDoc(this.serviceNamespace);
|
|
57
57
|
this.codeModel = new CodeModel(title, false, {
|
|
58
58
|
info: {
|
|
@@ -96,7 +96,7 @@ export class CodeModelBuilder {
|
|
|
96
96
|
// TODO: it is not very likely, but different client could have different auth
|
|
97
97
|
const auth = getAuthentication(this.program, this.serviceNamespace);
|
|
98
98
|
if (auth) {
|
|
99
|
-
this.processAuth(auth);
|
|
99
|
+
this.processAuth(auth, this.serviceNamespace);
|
|
100
100
|
}
|
|
101
101
|
if (this.sdkContext.arm) {
|
|
102
102
|
// ARM
|
|
@@ -145,18 +145,33 @@ export class CodeModelBuilder {
|
|
|
145
145
|
});
|
|
146
146
|
return hostParameters;
|
|
147
147
|
}
|
|
148
|
-
processAuth(auth) {
|
|
148
|
+
processAuth(auth, serviceNamespace) {
|
|
149
149
|
const securitySchemes = [];
|
|
150
150
|
for (const option of auth.options) {
|
|
151
151
|
for (const scheme of option.schemes) {
|
|
152
152
|
switch (scheme.type) {
|
|
153
153
|
case "oauth2":
|
|
154
154
|
{
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
if (this.isBranded()) {
|
|
156
|
+
const oauth2Scheme = new OAuth2SecurityScheme({
|
|
157
|
+
scopes: [],
|
|
158
|
+
});
|
|
159
|
+
scheme.flows.forEach((it) => oauth2Scheme.scopes.push(...it.scopes.map((it) => it.value)));
|
|
160
|
+
securitySchemes.push(oauth2Scheme);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// there is no TokenCredential in clientcore, hence use Bearer Authentication directly
|
|
164
|
+
reportDiagnostic(this.program, {
|
|
165
|
+
code: "auth-scheme-not-supported",
|
|
166
|
+
messageId: "oauth2Unbranded",
|
|
167
|
+
target: serviceNamespace,
|
|
168
|
+
});
|
|
169
|
+
const keyScheme = new KeySecurityScheme({
|
|
170
|
+
name: "authorization",
|
|
171
|
+
});
|
|
172
|
+
keyScheme.prefix = "Bearer";
|
|
173
|
+
securitySchemes.push(keyScheme);
|
|
174
|
+
}
|
|
160
175
|
}
|
|
161
176
|
break;
|
|
162
177
|
case "apiKey":
|
|
@@ -168,7 +183,11 @@ export class CodeModelBuilder {
|
|
|
168
183
|
securitySchemes.push(keyScheme);
|
|
169
184
|
}
|
|
170
185
|
else {
|
|
171
|
-
this.
|
|
186
|
+
reportDiagnostic(this.program, {
|
|
187
|
+
code: "auth-scheme-not-supported",
|
|
188
|
+
messageId: "apiKeyLocation",
|
|
189
|
+
target: serviceNamespace,
|
|
190
|
+
});
|
|
172
191
|
}
|
|
173
192
|
}
|
|
174
193
|
break;
|
|
@@ -180,7 +199,12 @@ export class CodeModelBuilder {
|
|
|
180
199
|
schemeOrApiKeyPrefix = pascalCase(schemeOrApiKeyPrefix);
|
|
181
200
|
if (this.isBranded()) {
|
|
182
201
|
// Azure would not allow BasicAuth or BearerAuth
|
|
183
|
-
this.
|
|
202
|
+
reportDiagnostic(this.program, {
|
|
203
|
+
code: "auth-scheme-not-supported",
|
|
204
|
+
messageId: "basicAuthBranded",
|
|
205
|
+
format: { scheme: scheme.scheme },
|
|
206
|
+
target: serviceNamespace,
|
|
207
|
+
});
|
|
184
208
|
continue;
|
|
185
209
|
}
|
|
186
210
|
}
|
|
@@ -341,7 +365,7 @@ export class CodeModelBuilder {
|
|
|
341
365
|
// at present, use global security definition
|
|
342
366
|
security: this.codeModel.security,
|
|
343
367
|
});
|
|
344
|
-
codeModelClient.crossLanguageDefinitionId = client.crossLanguageDefinitionId;
|
|
368
|
+
codeModelClient.language.default.crossLanguageDefinitionId = client.crossLanguageDefinitionId;
|
|
345
369
|
// versioning
|
|
346
370
|
const versions = client.apiVersions;
|
|
347
371
|
if (versions && versions.length > 0) {
|
|
@@ -351,7 +375,11 @@ export class CodeModelBuilder {
|
|
|
351
375
|
else {
|
|
352
376
|
this.apiVersion = versions.find((it) => it === this.sdkContext.apiVersion);
|
|
353
377
|
if (!this.apiVersion) {
|
|
354
|
-
this.
|
|
378
|
+
reportDiagnostic(this.program, {
|
|
379
|
+
code: "invalid-api-version",
|
|
380
|
+
format: { apiVersion: this.sdkContext.apiVersion },
|
|
381
|
+
target: NoTarget,
|
|
382
|
+
});
|
|
355
383
|
}
|
|
356
384
|
}
|
|
357
385
|
codeModelClient.apiVersions = [];
|
|
@@ -364,7 +392,8 @@ export class CodeModelBuilder {
|
|
|
364
392
|
// client initialization
|
|
365
393
|
let baseUri = "{endpoint}";
|
|
366
394
|
let hostParameters = [];
|
|
367
|
-
client.
|
|
395
|
+
client.clientInitialization.parameters.forEach((initializationProperty) => {
|
|
396
|
+
var _a;
|
|
368
397
|
if (initializationProperty.kind === "endpoint") {
|
|
369
398
|
let sdkPathParameters = [];
|
|
370
399
|
if (initializationProperty.type.kind === "union") {
|
|
@@ -378,7 +407,10 @@ export class CodeModelBuilder {
|
|
|
378
407
|
}
|
|
379
408
|
}
|
|
380
409
|
else if (initializationProperty.type.variantTypes.length > 2) {
|
|
381
|
-
this.
|
|
410
|
+
reportDiagnostic(this.program, {
|
|
411
|
+
code: "multiple-server-not-supported",
|
|
412
|
+
target: (_a = initializationProperty.type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
|
|
413
|
+
});
|
|
382
414
|
}
|
|
383
415
|
}
|
|
384
416
|
else if (initializationProperty.type.kind === "endpoint") {
|
|
@@ -395,6 +427,7 @@ export class CodeModelBuilder {
|
|
|
395
427
|
// operations without operation group
|
|
396
428
|
const serviceMethodsWithoutSubClient = this.listServiceMethodsUnderClient(client);
|
|
397
429
|
let codeModelGroup = new OperationGroup("");
|
|
430
|
+
codeModelGroup.language.default.crossLanguageDefinitionId = client.crossLanguageDefinitionId;
|
|
398
431
|
for (const serviceMethod of serviceMethodsWithoutSubClient) {
|
|
399
432
|
if (!this.needToSkipProcessingOperation(serviceMethod.__raw, clientContext)) {
|
|
400
433
|
codeModelGroup.addOperation(this.processOperation(serviceMethod, clientContext, ""));
|
|
@@ -418,6 +451,8 @@ export class CodeModelBuilder {
|
|
|
418
451
|
// operation group with no operation is skipped
|
|
419
452
|
if (serviceMethods.length > 0) {
|
|
420
453
|
codeModelGroup = new OperationGroup(subClient.name);
|
|
454
|
+
codeModelGroup.language.default.crossLanguageDefinitionId =
|
|
455
|
+
subClient.crossLanguageDefinitionId;
|
|
421
456
|
for (const serviceMethod of serviceMethods) {
|
|
422
457
|
if (!this.needToSkipProcessingOperation(serviceMethod.__raw, clientContext)) {
|
|
423
458
|
codeModelGroup.addOperation(this.processOperation(serviceMethod, clientContext, subClient.name));
|
|
@@ -508,7 +543,7 @@ export class CodeModelBuilder {
|
|
|
508
543
|
}
|
|
509
544
|
return versions
|
|
510
545
|
.slice(0, versions.indexOf(pinnedApiVersion) + 1)
|
|
511
|
-
.filter((version) => !excludePreview || !
|
|
546
|
+
.filter((version) => !excludePreview || !isStableApiVersion(pinnedApiVersion) || isStableApiVersion(version));
|
|
512
547
|
}
|
|
513
548
|
needToSkipProcessingOperation(operation, clientContext) {
|
|
514
549
|
// don't generate protocol and convenience method for overloaded operations
|
|
@@ -547,7 +582,7 @@ export class CodeModelBuilder {
|
|
|
547
582
|
}
|
|
548
583
|
}
|
|
549
584
|
processOperation(sdkMethod, clientContext, groupName) {
|
|
550
|
-
var _a;
|
|
585
|
+
var _a, _b, _c, _d;
|
|
551
586
|
const operationName = sdkMethod.name;
|
|
552
587
|
const httpOperation = sdkMethod.operation;
|
|
553
588
|
const operationId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
|
|
@@ -560,42 +595,57 @@ export class CodeModelBuilder {
|
|
|
560
595
|
"x-ms-examples": operationExamples,
|
|
561
596
|
},
|
|
562
597
|
});
|
|
563
|
-
codeModelOperation.crossLanguageDefinitionId =
|
|
564
|
-
sdkMethod.
|
|
598
|
+
codeModelOperation.language.default.crossLanguageDefinitionId =
|
|
599
|
+
sdkMethod.crossLanguageDefinitionId;
|
|
565
600
|
codeModelOperation.internalApi = sdkMethod.access === "internal";
|
|
566
601
|
const convenienceApiName = this.getConvenienceApiName(sdkMethod);
|
|
567
602
|
let generateConvenienceApi = sdkMethod.generateConvenient;
|
|
568
603
|
let generateProtocolApi = sdkMethod.generateProtocol;
|
|
569
|
-
let
|
|
604
|
+
let diagnostic = undefined;
|
|
570
605
|
if (generateConvenienceApi) {
|
|
571
606
|
// check if the convenience API need to be disabled for some special cases
|
|
572
607
|
if (operationIsMultipart(httpOperation)) {
|
|
573
608
|
// do not generate protocol method for multipart/form-data, as it be very hard for user to prepare the request body as BinaryData
|
|
574
609
|
generateProtocolApi = false;
|
|
575
|
-
|
|
576
|
-
|
|
610
|
+
diagnostic = createDiagnostic({
|
|
611
|
+
code: "protocol-api-not-generated",
|
|
612
|
+
messageId: "multipartFormData",
|
|
613
|
+
format: { operationName: operationName },
|
|
614
|
+
target: (_b = sdkMethod.__raw) !== null && _b !== void 0 ? _b : NoTarget,
|
|
615
|
+
});
|
|
616
|
+
this.program.reportDiagnostic(diagnostic);
|
|
577
617
|
}
|
|
578
618
|
else if (operationIsMultipleContentTypes(httpOperation)) {
|
|
579
619
|
// and multiple content types
|
|
580
620
|
// issue link: https://github.com/Azure/autorest.java/issues/1958#issuecomment-1562558219
|
|
581
621
|
generateConvenienceApi = false;
|
|
582
|
-
|
|
583
|
-
|
|
622
|
+
diagnostic = createDiagnostic({
|
|
623
|
+
code: "convenience-api-not-generated",
|
|
624
|
+
messageId: "multipleContentType",
|
|
625
|
+
format: { operationName: operationName },
|
|
626
|
+
target: (_c = sdkMethod.__raw) !== null && _c !== void 0 ? _c : NoTarget,
|
|
627
|
+
});
|
|
628
|
+
this.program.reportDiagnostic(diagnostic);
|
|
584
629
|
}
|
|
585
630
|
else if (operationIsJsonMergePatch(httpOperation) &&
|
|
586
631
|
this.options["stream-style-serialization"] === false) {
|
|
587
632
|
// do not generate convenient method for json merge patch operation if stream-style-serialization is not enabled
|
|
588
633
|
generateConvenienceApi = false;
|
|
589
|
-
|
|
590
|
-
|
|
634
|
+
diagnostic = createDiagnostic({
|
|
635
|
+
code: "convenience-api-not-generated",
|
|
636
|
+
messageId: "jsonMergePatch",
|
|
637
|
+
format: { operationName: operationName },
|
|
638
|
+
target: (_d = sdkMethod.__raw) !== null && _d !== void 0 ? _d : NoTarget,
|
|
639
|
+
});
|
|
640
|
+
this.program.reportDiagnostic(diagnostic);
|
|
591
641
|
}
|
|
592
642
|
}
|
|
593
643
|
if (generateConvenienceApi && convenienceApiName) {
|
|
594
644
|
codeModelOperation.convenienceApi = new ConvenienceApi(convenienceApiName);
|
|
595
645
|
}
|
|
596
|
-
if (
|
|
646
|
+
if (diagnostic) {
|
|
597
647
|
codeModelOperation.language.java = new Language();
|
|
598
|
-
codeModelOperation.language.java.comment =
|
|
648
|
+
codeModelOperation.language.java.comment = diagnostic.message;
|
|
599
649
|
}
|
|
600
650
|
// check for generating protocol api or not
|
|
601
651
|
codeModelOperation.generateProtocolApi = generateProtocolApi && !codeModelOperation.internalApi;
|
|
@@ -612,8 +662,7 @@ export class CodeModelBuilder {
|
|
|
612
662
|
clientContext.hostParameters.forEach((it) => codeModelOperation.addParameter(it));
|
|
613
663
|
// path/query/header parameters
|
|
614
664
|
for (const param of httpOperation.parameters) {
|
|
615
|
-
|
|
616
|
-
if (param.__raw && isCookieParam(this.program, param.__raw)) {
|
|
665
|
+
if (param.kind === "cookie") {
|
|
617
666
|
// ignore cookie parameter
|
|
618
667
|
continue;
|
|
619
668
|
}
|
|
@@ -664,32 +713,49 @@ export class CodeModelBuilder {
|
|
|
664
713
|
}
|
|
665
714
|
processRouteForPaged(op, responses, sdkMethod) {
|
|
666
715
|
var _a, _b;
|
|
667
|
-
if (!this.isBranded()) {
|
|
668
|
-
// TODO: currently unbranded does not support paged operation
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
716
|
if (sdkMethod.kind === "paging" || sdkMethod.kind === "lropaging") {
|
|
672
717
|
for (const response of responses) {
|
|
673
718
|
const bodyType = response.type;
|
|
674
719
|
if (bodyType && bodyType.kind === "model") {
|
|
675
|
-
const
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
};
|
|
682
|
-
(_b = op.responses) === null || _b === void 0 ? void 0 : _b.forEach((r) => {
|
|
720
|
+
const itemClientName = sdkMethod.response.resultPath;
|
|
721
|
+
const nextLinkClientName = sdkMethod.nextLinkPath;
|
|
722
|
+
let itemSerializedName = undefined;
|
|
723
|
+
let nextLinkSerializedName = undefined;
|
|
724
|
+
(_a = op.responses) === null || _a === void 0 ? void 0 : _a.forEach((r) => {
|
|
725
|
+
var _a;
|
|
683
726
|
if (r instanceof SchemaResponse) {
|
|
684
727
|
this.trackSchemaUsage(r.schema, { usage: [SchemaContext.Paged] });
|
|
728
|
+
// find serializedName for items and nextLink
|
|
729
|
+
if (r.schema instanceof ObjectSchema) {
|
|
730
|
+
(_a = r.schema.properties) === null || _a === void 0 ? void 0 : _a.forEach((p) => {
|
|
731
|
+
if (itemClientName &&
|
|
732
|
+
!itemSerializedName &&
|
|
733
|
+
p.serializedName &&
|
|
734
|
+
p.language.default.name === itemClientName) {
|
|
735
|
+
itemSerializedName = p.serializedName;
|
|
736
|
+
}
|
|
737
|
+
if (nextLinkClientName &&
|
|
738
|
+
!nextLinkSerializedName &&
|
|
739
|
+
p.serializedName &&
|
|
740
|
+
p.language.default.name === nextLinkClientName) {
|
|
741
|
+
nextLinkSerializedName = p.serializedName;
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
685
745
|
}
|
|
686
746
|
});
|
|
747
|
+
op.extensions = (_b = op.extensions) !== null && _b !== void 0 ? _b : {};
|
|
748
|
+
op.extensions["x-ms-pageable"] = {
|
|
749
|
+
itemName: itemSerializedName,
|
|
750
|
+
nextLinkName: nextLinkSerializedName,
|
|
751
|
+
};
|
|
687
752
|
break;
|
|
688
753
|
}
|
|
689
754
|
}
|
|
690
755
|
}
|
|
691
756
|
}
|
|
692
757
|
processLroMetadata(op, sdkMethod) {
|
|
758
|
+
var _a;
|
|
693
759
|
const trackConvenienceApi = Boolean(op.convenienceApi);
|
|
694
760
|
const lroMetadata = sdkMethod.lroMetadata;
|
|
695
761
|
if (lroMetadata && lroMetadata.pollingStep) {
|
|
@@ -734,8 +800,20 @@ export class CodeModelBuilder {
|
|
|
734
800
|
lroMetadata.finalStep &&
|
|
735
801
|
lroMetadata.finalStep.kind === "pollingSuccessProperty" &&
|
|
736
802
|
lroMetadata.finalResponse.resultPath) {
|
|
737
|
-
|
|
738
|
-
|
|
803
|
+
const finalResultPropertyClientName = lroMetadata.finalResponse.resultPath;
|
|
804
|
+
// find serializedName for lro result
|
|
805
|
+
if (finalResultPropertyClientName) {
|
|
806
|
+
(_a = lroMetadata.finalResponse.envelopeResult.properties) === null || _a === void 0 ? void 0 : _a.forEach((p) => {
|
|
807
|
+
var _a, _b, _c;
|
|
808
|
+
// TODO: "p.__raw?.name" should be "p.name", after TCGC fix https://github.com/Azure/typespec-azure/issues/2072
|
|
809
|
+
if (!finalResultPropertySerializedName &&
|
|
810
|
+
p.kind === "property" &&
|
|
811
|
+
((_a = p.serializationOptions.json) === null || _a === void 0 ? void 0 : _a.name) &&
|
|
812
|
+
((_b = p.__raw) === null || _b === void 0 ? void 0 : _b.name) === finalResultPropertyClientName) {
|
|
813
|
+
finalResultPropertySerializedName = (_c = p.serializationOptions.json) === null || _c === void 0 ? void 0 : _c.name;
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
}
|
|
739
817
|
}
|
|
740
818
|
}
|
|
741
819
|
// track usage
|
|
@@ -769,7 +847,7 @@ export class CodeModelBuilder {
|
|
|
769
847
|
}
|
|
770
848
|
}
|
|
771
849
|
processParameter(op, param, clientContext) {
|
|
772
|
-
var _a, _b;
|
|
850
|
+
var _a, _b, _c;
|
|
773
851
|
if (clientContext.apiVersions && isApiVersion(this.sdkContext, param)) {
|
|
774
852
|
// pre-condition for "isApiVersion": the client supports ApiVersions
|
|
775
853
|
if (this.isArm()) {
|
|
@@ -866,19 +944,19 @@ export class CodeModelBuilder {
|
|
|
866
944
|
break;
|
|
867
945
|
default:
|
|
868
946
|
if (format) {
|
|
869
|
-
this.
|
|
947
|
+
reportDiagnostic(this.program, {
|
|
948
|
+
code: "header-parameter-format-not-supported",
|
|
949
|
+
format: { format: format },
|
|
950
|
+
target: (_b = param.__raw) !== null && _b !== void 0 ? _b : NoTarget,
|
|
951
|
+
});
|
|
870
952
|
}
|
|
871
953
|
break;
|
|
872
954
|
}
|
|
873
955
|
}
|
|
874
956
|
}
|
|
875
|
-
|
|
876
|
-
const parameterOnClient = !isApiVersion(this.sdkContext, param) &&
|
|
877
|
-
param.correspondingMethodParams &&
|
|
878
|
-
param.correspondingMethodParams.length > 0 &&
|
|
879
|
-
param.correspondingMethodParams[0].onClient;
|
|
957
|
+
const parameterOnClient = param.onClient;
|
|
880
958
|
const nullable = param.type.kind === "nullable";
|
|
881
|
-
const parameter = new Parameter(param.name, (
|
|
959
|
+
const parameter = new Parameter(param.name, (_c = param.doc) !== null && _c !== void 0 ? _c : "", schema, {
|
|
882
960
|
summary: param.summary,
|
|
883
961
|
implementation: parameterOnClient
|
|
884
962
|
? ImplementationLocation.Client
|
|
@@ -1153,7 +1231,9 @@ export class CodeModelBuilder {
|
|
|
1153
1231
|
}
|
|
1154
1232
|
addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, originalParameter) {
|
|
1155
1233
|
var _a, _b, _c, _d, _e;
|
|
1156
|
-
const serializedName = opParameter.
|
|
1234
|
+
const serializedName = opParameter.kind === "property"
|
|
1235
|
+
? getPropertySerializedName(opParameter)
|
|
1236
|
+
: opParameter.serializedName;
|
|
1157
1237
|
let existParameter;
|
|
1158
1238
|
if (opParameter.kind !== "property") {
|
|
1159
1239
|
// not body property
|
|
@@ -1195,10 +1275,6 @@ export class CodeModelBuilder {
|
|
|
1195
1275
|
}
|
|
1196
1276
|
}
|
|
1197
1277
|
}
|
|
1198
|
-
findResponseBody(bodyType) {
|
|
1199
|
-
// find a type that possibly without http metadata like @statusCode
|
|
1200
|
-
return this.getEffectiveSchemaType(bodyType);
|
|
1201
|
-
}
|
|
1202
1278
|
processResponse(op, statusCode, sdkResponse, longRunning, isErrorResponse) {
|
|
1203
1279
|
var _a;
|
|
1204
1280
|
// TODO: what to do if more than 1 response?
|
|
@@ -1331,6 +1407,7 @@ export class CodeModelBuilder {
|
|
|
1331
1407
|
return this.schemaCache.process(type, nameHint) || fail("Unable to process schema.");
|
|
1332
1408
|
}
|
|
1333
1409
|
processSchemaImpl(type, nameHint) {
|
|
1410
|
+
var _a;
|
|
1334
1411
|
if (isSdkBuiltInKind(type.kind)) {
|
|
1335
1412
|
return this.processBuiltInType(type, nameHint);
|
|
1336
1413
|
}
|
|
@@ -1362,9 +1439,12 @@ export class CodeModelBuilder {
|
|
|
1362
1439
|
}
|
|
1363
1440
|
}
|
|
1364
1441
|
}
|
|
1365
|
-
const
|
|
1366
|
-
|
|
1367
|
-
|
|
1442
|
+
const diagnostic = createDiagnostic({
|
|
1443
|
+
code: "unrecognized-type",
|
|
1444
|
+
format: { typeKind: type.kind },
|
|
1445
|
+
target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
|
|
1446
|
+
});
|
|
1447
|
+
throw new DiagnosticError(diagnostic);
|
|
1368
1448
|
}
|
|
1369
1449
|
processBuiltInType(type, nameHint) {
|
|
1370
1450
|
nameHint = nameHint || type.kind;
|
|
@@ -1499,7 +1579,7 @@ export class CodeModelBuilder {
|
|
|
1499
1579
|
},
|
|
1500
1580
|
},
|
|
1501
1581
|
});
|
|
1502
|
-
schema.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1582
|
+
schema.language.default.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1503
1583
|
return this.codeModel.schemas.add(schema);
|
|
1504
1584
|
}
|
|
1505
1585
|
processConstantSchema(type, name) {
|
|
@@ -1573,8 +1653,7 @@ export class CodeModelBuilder {
|
|
|
1573
1653
|
},
|
|
1574
1654
|
},
|
|
1575
1655
|
});
|
|
1576
|
-
objectSchema.crossLanguageDefinitionId =
|
|
1577
|
-
type.crossLanguageDefinitionId;
|
|
1656
|
+
objectSchema.language.default.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1578
1657
|
this.codeModel.schemas.add(objectSchema);
|
|
1579
1658
|
// cache this now before we accidentally recurse on this type.
|
|
1580
1659
|
if (!this.schemaCache.has(type)) {
|
|
@@ -1638,26 +1717,8 @@ export class CodeModelBuilder {
|
|
|
1638
1717
|
}
|
|
1639
1718
|
return objectSchema;
|
|
1640
1719
|
}
|
|
1641
|
-
getEffectiveSchemaType(type) {
|
|
1642
|
-
var _a;
|
|
1643
|
-
const program = this.program;
|
|
1644
|
-
function isSchemaProperty(property) {
|
|
1645
|
-
return isPayloadProperty(program, property);
|
|
1646
|
-
}
|
|
1647
|
-
if (type.kind === "Model") {
|
|
1648
|
-
const effective = getEffectiveModelType(program, type, isSchemaProperty);
|
|
1649
|
-
if (this.isArm() && ((_a = getNamespace(effective)) === null || _a === void 0 ? void 0 : _a.startsWith("Azure.ResourceManager"))) {
|
|
1650
|
-
// e.g. typespec: Catalog is TrackedResource<CatalogProperties>
|
|
1651
|
-
return type;
|
|
1652
|
-
}
|
|
1653
|
-
else if (effective.name) {
|
|
1654
|
-
return effective;
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
return type;
|
|
1658
|
-
}
|
|
1659
1720
|
processModelProperty(prop) {
|
|
1660
|
-
var _a;
|
|
1721
|
+
var _a, _b;
|
|
1661
1722
|
let nullable = false;
|
|
1662
1723
|
let nonNullType = prop.type;
|
|
1663
1724
|
if (nonNullType.kind === "nullable") {
|
|
@@ -1681,9 +1742,9 @@ export class CodeModelBuilder {
|
|
|
1681
1742
|
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
1682
1743
|
extensions["x-ms-mutability"] = mutability;
|
|
1683
1744
|
}
|
|
1684
|
-
if (prop.kind === "property" && prop.
|
|
1745
|
+
if (prop.kind === "property" && prop.serializationOptions.multipart) {
|
|
1685
1746
|
// TODO: handle MultipartOptions.isMulti
|
|
1686
|
-
if (prop.
|
|
1747
|
+
if ((_a = prop.serializationOptions.multipart) === null || _a === void 0 ? void 0 : _a.isFilePart) {
|
|
1687
1748
|
schema = this.processMultipartFormDataFilePropertySchema(prop);
|
|
1688
1749
|
}
|
|
1689
1750
|
else if (prop.type.kind === "model" &&
|
|
@@ -1698,25 +1759,30 @@ export class CodeModelBuilder {
|
|
|
1698
1759
|
else {
|
|
1699
1760
|
schema = this.processSchema(nonNullType, "");
|
|
1700
1761
|
}
|
|
1701
|
-
return new Property(prop.name, (
|
|
1762
|
+
return new Property(prop.name, (_b = prop.doc) !== null && _b !== void 0 ? _b : "", schema, {
|
|
1702
1763
|
summary: prop.summary,
|
|
1703
1764
|
required: !prop.optional,
|
|
1704
1765
|
nullable: nullable,
|
|
1705
1766
|
readOnly: this.isReadOnly(prop),
|
|
1706
|
-
serializedName: prop.kind === "property" ? prop
|
|
1767
|
+
serializedName: prop.kind === "property" ? getPropertySerializedName(prop) : undefined,
|
|
1707
1768
|
extensions: extensions,
|
|
1708
1769
|
});
|
|
1709
1770
|
}
|
|
1710
1771
|
processUnionSchema(type, name) {
|
|
1711
|
-
var _a, _b;
|
|
1772
|
+
var _a, _b, _c;
|
|
1712
1773
|
if (!(type.__raw && type.__raw.kind === "Union")) {
|
|
1713
|
-
this.
|
|
1774
|
+
reportDiagnostic(this.program, {
|
|
1775
|
+
code: "unrecognized-type",
|
|
1776
|
+
messageId: "unionType",
|
|
1777
|
+
format: { typeKind: type.kind },
|
|
1778
|
+
target: (_a = type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
|
|
1779
|
+
});
|
|
1714
1780
|
}
|
|
1715
1781
|
const rawUnionType = type.__raw;
|
|
1716
1782
|
const namespace = getNamespace(rawUnionType);
|
|
1717
|
-
const baseName = (
|
|
1718
|
-
this.
|
|
1719
|
-
const unionSchema = new OrSchema(baseName + "Base", (
|
|
1783
|
+
const baseName = (_b = type.name) !== null && _b !== void 0 ? _b : pascalCase(name) + "Model";
|
|
1784
|
+
this.trace(`Convert TypeSpec Union '${getUnionDescription(rawUnionType, this.typeNameOptions)}' to Class '${baseName}'`);
|
|
1785
|
+
const unionSchema = new OrSchema(baseName + "Base", (_c = type.doc) !== null && _c !== void 0 ? _c : "", {
|
|
1720
1786
|
summary: type.summary,
|
|
1721
1787
|
});
|
|
1722
1788
|
unionSchema.anyOf = [];
|
|
@@ -1756,7 +1822,7 @@ export class CodeModelBuilder {
|
|
|
1756
1822
|
getUnionVariantName(type, option) {
|
|
1757
1823
|
var _a, _b;
|
|
1758
1824
|
if (type === undefined) {
|
|
1759
|
-
this.
|
|
1825
|
+
this.trace("Union variant type is undefined.");
|
|
1760
1826
|
return "UnionVariant";
|
|
1761
1827
|
}
|
|
1762
1828
|
switch (type.kind) {
|
|
@@ -1814,12 +1880,12 @@ export class CodeModelBuilder {
|
|
|
1814
1880
|
case "UnionVariant":
|
|
1815
1881
|
return (_b = (typeof type.name === "string" ? type.name : undefined)) !== null && _b !== void 0 ? _b : "UnionVariant";
|
|
1816
1882
|
default:
|
|
1817
|
-
this.
|
|
1883
|
+
this.trace(`Unrecognized type for union variable: '${type.kind}'.`);
|
|
1818
1884
|
return "UnionVariant";
|
|
1819
1885
|
}
|
|
1820
1886
|
}
|
|
1821
1887
|
processMultipartFormDataFilePropertySchema(property) {
|
|
1822
|
-
var _a;
|
|
1888
|
+
var _a, _b;
|
|
1823
1889
|
const processSchemaFunc = (type) => this.processSchema(type, "");
|
|
1824
1890
|
const processNamespaceFunc = (type) => {
|
|
1825
1891
|
var _a;
|
|
@@ -1839,9 +1905,13 @@ export class CodeModelBuilder {
|
|
|
1839
1905
|
});
|
|
1840
1906
|
}
|
|
1841
1907
|
else {
|
|
1842
|
-
const
|
|
1843
|
-
|
|
1844
|
-
|
|
1908
|
+
const diagnostic = createDiagnostic({
|
|
1909
|
+
code: "unrecognized-type",
|
|
1910
|
+
messageId: "multipartFormData",
|
|
1911
|
+
format: { typeKind: property.type.kind },
|
|
1912
|
+
target: (_b = property.type.__raw) !== null && _b !== void 0 ? _b : NoTarget,
|
|
1913
|
+
});
|
|
1914
|
+
throw new DiagnosticError(diagnostic);
|
|
1845
1915
|
}
|
|
1846
1916
|
}
|
|
1847
1917
|
getDoc(target) {
|
|
@@ -1850,21 +1920,6 @@ export class CodeModelBuilder {
|
|
|
1850
1920
|
getSummary(target) {
|
|
1851
1921
|
return target ? getSummary(this.program, target) : undefined;
|
|
1852
1922
|
}
|
|
1853
|
-
getSerializedName(target) {
|
|
1854
|
-
if (isHeader(this.program, target)) {
|
|
1855
|
-
return getHeaderFieldName(this.program, target);
|
|
1856
|
-
}
|
|
1857
|
-
else if (isQueryParam(this.program, target)) {
|
|
1858
|
-
return getQueryParamName(this.program, target);
|
|
1859
|
-
}
|
|
1860
|
-
else if (isPathParam(this.program, target)) {
|
|
1861
|
-
return getPathParamName(this.program, target);
|
|
1862
|
-
}
|
|
1863
|
-
else {
|
|
1864
|
-
// TODO: currently this is only for JSON
|
|
1865
|
-
return getWireName(this.sdkContext, target);
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
1923
|
isReadOnly(target) {
|
|
1869
1924
|
const segment = target.__raw ? getSegment(this.program, target.__raw) !== undefined : false;
|
|
1870
1925
|
if (segment) {
|
|
@@ -1946,18 +2001,19 @@ export class CodeModelBuilder {
|
|
|
1946
2001
|
// clientNamespace from TCGC
|
|
1947
2002
|
const clientNamespace = type === null || type === void 0 ? void 0 : type.clientNamespace;
|
|
1948
2003
|
if (type) {
|
|
2004
|
+
const crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1949
2005
|
if (this.isBranded()) {
|
|
1950
2006
|
// special handling for namespace of model that cannot be mapped to azure-core
|
|
1951
|
-
if (
|
|
2007
|
+
if (crossLanguageDefinitionId === "TypeSpec.Http.File") {
|
|
1952
2008
|
// TypeSpec.Http.File
|
|
1953
2009
|
return this.baseJavaNamespace;
|
|
1954
2010
|
}
|
|
1955
|
-
else if (
|
|
2011
|
+
else if (crossLanguageDefinitionId === "Azure.Core.Foundations.OperationState") {
|
|
1956
2012
|
// Azure.Core.OperationState
|
|
1957
2013
|
return this.baseJavaNamespace;
|
|
1958
2014
|
}
|
|
1959
|
-
else if (
|
|
1960
|
-
|
|
2015
|
+
else if (crossLanguageDefinitionId === "Azure.Core.ResourceOperationStatus" ||
|
|
2016
|
+
crossLanguageDefinitionId === "Azure.Core.Foundations.OperationStatus") {
|
|
1961
2017
|
// Azure.Core.ResourceOperationStatus<>
|
|
1962
2018
|
// Azure.Core.Foundations.OperationStatus<>
|
|
1963
2019
|
// usually this model will not be generated, but javadoc of protocol method requires it be in SDK namespace
|
|
@@ -1969,8 +2025,12 @@ export class CodeModelBuilder {
|
|
|
1969
2025
|
}
|
|
1970
2026
|
}
|
|
1971
2027
|
else {
|
|
1972
|
-
// special handling for namespace of model in TypeSpec
|
|
1973
|
-
if (
|
|
2028
|
+
// special handling for namespace of model in TypeSpec
|
|
2029
|
+
if (crossLanguageDefinitionId === "TypeSpec.Http.File") {
|
|
2030
|
+
// TypeSpec.Http.File
|
|
2031
|
+
return this.baseJavaNamespace;
|
|
2032
|
+
}
|
|
2033
|
+
else if (crossLanguageDefinitionId.startsWith("TypeSpec.Rest.Resource.")) {
|
|
1974
2034
|
// models in TypeSpec.Rest.Resource
|
|
1975
2035
|
return this.baseJavaNamespace;
|
|
1976
2036
|
}
|
|
@@ -1983,14 +2043,6 @@ export class CodeModelBuilder {
|
|
|
1983
2043
|
return clientNamespace.toLowerCase();
|
|
1984
2044
|
}
|
|
1985
2045
|
}
|
|
1986
|
-
logError(msg) {
|
|
1987
|
-
logError(this.program, msg);
|
|
1988
|
-
}
|
|
1989
|
-
logWarning(msg) {
|
|
1990
|
-
if (this.loggingEnabled) {
|
|
1991
|
-
logWarning(this.program, msg);
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
2046
|
trace(msg) {
|
|
1995
2047
|
trace(this.program, msg);
|
|
1996
2048
|
}
|