@azure-tools/typespec-java 0.27.2 → 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 -6
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +116 -108
- package/dist/src/code-model-builder.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 +40 -54
- package/dist/src/emitter.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 +6 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +9 -17
- package/dist/src/utils.js.map +1 -1
- package/dist/src/validate.d.ts +1 -1
- package/dist/src/validate.d.ts.map +1 -1
- package/dist/src/validate.js +39 -19
- 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 +22 -19
|
@@ -2,7 +2,7 @@ import { AnySchema, BinarySchema, BooleanSchema, NumberSchema, ObjectSchema, Par
|
|
|
2
2
|
import { SdkType } from "@azure-tools/typespec-client-generator-core";
|
|
3
3
|
import { EmitContext, Program, Type, Union } from "@typespec/compiler";
|
|
4
4
|
import { CodeModel } from "./common/code-model.js";
|
|
5
|
-
import { EmitterOptions } from "./
|
|
5
|
+
import { EmitterOptions } from "./lib.js";
|
|
6
6
|
import { ProcessingCache } from "./type-utils.js";
|
|
7
7
|
export declare class CodeModelBuilder {
|
|
8
8
|
private program;
|
|
@@ -55,7 +55,6 @@ export declare class CodeModelBuilder {
|
|
|
55
55
|
private processEtagHeaderParameters;
|
|
56
56
|
private processParameterBody;
|
|
57
57
|
private addParameterOrBodyPropertyToCodeModelRequest;
|
|
58
|
-
private findResponseBody;
|
|
59
58
|
private processResponse;
|
|
60
59
|
private getStatusCodes;
|
|
61
60
|
private processSchema;
|
|
@@ -80,7 +79,6 @@ export declare class CodeModelBuilder {
|
|
|
80
79
|
private processDurationSchema;
|
|
81
80
|
private processUrlSchema;
|
|
82
81
|
private processObjectSchema;
|
|
83
|
-
private getEffectiveSchemaType;
|
|
84
82
|
private processModelProperty;
|
|
85
83
|
private processUnionSchema;
|
|
86
84
|
private processBinarySchema;
|
|
@@ -88,15 +86,12 @@ export declare class CodeModelBuilder {
|
|
|
88
86
|
private processMultipartFormDataFilePropertySchema;
|
|
89
87
|
private getDoc;
|
|
90
88
|
private getSummary;
|
|
91
|
-
private getSerializedName;
|
|
92
89
|
private isReadOnly;
|
|
93
90
|
private isSecret;
|
|
94
91
|
private getMutability;
|
|
95
92
|
private getConvenienceApiName;
|
|
96
93
|
private getBaseJavaNamespace;
|
|
97
94
|
private getJavaNamespace;
|
|
98
|
-
private logError;
|
|
99
|
-
private logWarning;
|
|
100
95
|
private trace;
|
|
101
96
|
private _stringSchema?;
|
|
102
97
|
get stringSchema(): StringSchema;
|
|
@@ -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;AA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AAgB;IAyBxB,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -1,8 +1,8 @@
|
|
|
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";
|
|
@@ -17,10 +17,11 @@ 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) {
|
|
@@ -35,7 +36,10 @@ export class CodeModelBuilder {
|
|
|
35
36
|
}
|
|
36
37
|
const service = listServices(this.program)[0];
|
|
37
38
|
if (!service) {
|
|
38
|
-
this.
|
|
39
|
+
reportDiagnostic(this.program, {
|
|
40
|
+
code: "no-service",
|
|
41
|
+
target: NoTarget,
|
|
42
|
+
});
|
|
39
43
|
}
|
|
40
44
|
this.serviceNamespace = (_a = service === null || service === void 0 ? void 0 : service.type) !== null && _a !== void 0 ? _a : this.program.getGlobalNamespaceType();
|
|
41
45
|
this.namespace = getNamespaceFullName(this.serviceNamespace) || "Client";
|
|
@@ -92,7 +96,7 @@ export class CodeModelBuilder {
|
|
|
92
96
|
// TODO: it is not very likely, but different client could have different auth
|
|
93
97
|
const auth = getAuthentication(this.program, this.serviceNamespace);
|
|
94
98
|
if (auth) {
|
|
95
|
-
this.processAuth(auth);
|
|
99
|
+
this.processAuth(auth, this.serviceNamespace);
|
|
96
100
|
}
|
|
97
101
|
if (this.sdkContext.arm) {
|
|
98
102
|
// ARM
|
|
@@ -141,7 +145,7 @@ export class CodeModelBuilder {
|
|
|
141
145
|
});
|
|
142
146
|
return hostParameters;
|
|
143
147
|
}
|
|
144
|
-
processAuth(auth) {
|
|
148
|
+
processAuth(auth, serviceNamespace) {
|
|
145
149
|
const securitySchemes = [];
|
|
146
150
|
for (const option of auth.options) {
|
|
147
151
|
for (const scheme of option.schemes) {
|
|
@@ -157,7 +161,11 @@ export class CodeModelBuilder {
|
|
|
157
161
|
}
|
|
158
162
|
else {
|
|
159
163
|
// there is no TokenCredential in clientcore, hence use Bearer Authentication directly
|
|
160
|
-
this.
|
|
164
|
+
reportDiagnostic(this.program, {
|
|
165
|
+
code: "auth-scheme-not-supported",
|
|
166
|
+
messageId: "oauth2Unbranded",
|
|
167
|
+
target: serviceNamespace,
|
|
168
|
+
});
|
|
161
169
|
const keyScheme = new KeySecurityScheme({
|
|
162
170
|
name: "authorization",
|
|
163
171
|
});
|
|
@@ -175,7 +183,11 @@ export class CodeModelBuilder {
|
|
|
175
183
|
securitySchemes.push(keyScheme);
|
|
176
184
|
}
|
|
177
185
|
else {
|
|
178
|
-
this.
|
|
186
|
+
reportDiagnostic(this.program, {
|
|
187
|
+
code: "auth-scheme-not-supported",
|
|
188
|
+
messageId: "apiKeyLocation",
|
|
189
|
+
target: serviceNamespace,
|
|
190
|
+
});
|
|
179
191
|
}
|
|
180
192
|
}
|
|
181
193
|
break;
|
|
@@ -187,7 +199,12 @@ export class CodeModelBuilder {
|
|
|
187
199
|
schemeOrApiKeyPrefix = pascalCase(schemeOrApiKeyPrefix);
|
|
188
200
|
if (this.isBranded()) {
|
|
189
201
|
// Azure would not allow BasicAuth or BearerAuth
|
|
190
|
-
this.
|
|
202
|
+
reportDiagnostic(this.program, {
|
|
203
|
+
code: "auth-scheme-not-supported",
|
|
204
|
+
messageId: "basicAuthBranded",
|
|
205
|
+
format: { scheme: scheme.scheme },
|
|
206
|
+
target: serviceNamespace,
|
|
207
|
+
});
|
|
191
208
|
continue;
|
|
192
209
|
}
|
|
193
210
|
}
|
|
@@ -358,7 +375,11 @@ export class CodeModelBuilder {
|
|
|
358
375
|
else {
|
|
359
376
|
this.apiVersion = versions.find((it) => it === this.sdkContext.apiVersion);
|
|
360
377
|
if (!this.apiVersion) {
|
|
361
|
-
this.
|
|
378
|
+
reportDiagnostic(this.program, {
|
|
379
|
+
code: "invalid-api-version",
|
|
380
|
+
format: { apiVersion: this.sdkContext.apiVersion },
|
|
381
|
+
target: NoTarget,
|
|
382
|
+
});
|
|
362
383
|
}
|
|
363
384
|
}
|
|
364
385
|
codeModelClient.apiVersions = [];
|
|
@@ -371,7 +392,8 @@ export class CodeModelBuilder {
|
|
|
371
392
|
// client initialization
|
|
372
393
|
let baseUri = "{endpoint}";
|
|
373
394
|
let hostParameters = [];
|
|
374
|
-
client.
|
|
395
|
+
client.clientInitialization.parameters.forEach((initializationProperty) => {
|
|
396
|
+
var _a;
|
|
375
397
|
if (initializationProperty.kind === "endpoint") {
|
|
376
398
|
let sdkPathParameters = [];
|
|
377
399
|
if (initializationProperty.type.kind === "union") {
|
|
@@ -385,7 +407,10 @@ export class CodeModelBuilder {
|
|
|
385
407
|
}
|
|
386
408
|
}
|
|
387
409
|
else if (initializationProperty.type.variantTypes.length > 2) {
|
|
388
|
-
this.
|
|
410
|
+
reportDiagnostic(this.program, {
|
|
411
|
+
code: "multiple-server-not-supported",
|
|
412
|
+
target: (_a = initializationProperty.type.__raw) !== null && _a !== void 0 ? _a : NoTarget,
|
|
413
|
+
});
|
|
389
414
|
}
|
|
390
415
|
}
|
|
391
416
|
else if (initializationProperty.type.kind === "endpoint") {
|
|
@@ -518,7 +543,7 @@ export class CodeModelBuilder {
|
|
|
518
543
|
}
|
|
519
544
|
return versions
|
|
520
545
|
.slice(0, versions.indexOf(pinnedApiVersion) + 1)
|
|
521
|
-
.filter((version) => !excludePreview || !
|
|
546
|
+
.filter((version) => !excludePreview || !isStableApiVersion(pinnedApiVersion) || isStableApiVersion(version));
|
|
522
547
|
}
|
|
523
548
|
needToSkipProcessingOperation(operation, clientContext) {
|
|
524
549
|
// don't generate protocol and convenience method for overloaded operations
|
|
@@ -557,7 +582,7 @@ export class CodeModelBuilder {
|
|
|
557
582
|
}
|
|
558
583
|
}
|
|
559
584
|
processOperation(sdkMethod, clientContext, groupName) {
|
|
560
|
-
var _a;
|
|
585
|
+
var _a, _b, _c, _d;
|
|
561
586
|
const operationName = sdkMethod.name;
|
|
562
587
|
const httpOperation = sdkMethod.operation;
|
|
563
588
|
const operationId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
|
|
@@ -576,36 +601,51 @@ export class CodeModelBuilder {
|
|
|
576
601
|
const convenienceApiName = this.getConvenienceApiName(sdkMethod);
|
|
577
602
|
let generateConvenienceApi = sdkMethod.generateConvenient;
|
|
578
603
|
let generateProtocolApi = sdkMethod.generateProtocol;
|
|
579
|
-
let
|
|
604
|
+
let diagnostic = undefined;
|
|
580
605
|
if (generateConvenienceApi) {
|
|
581
606
|
// check if the convenience API need to be disabled for some special cases
|
|
582
607
|
if (operationIsMultipart(httpOperation)) {
|
|
583
608
|
// do not generate protocol method for multipart/form-data, as it be very hard for user to prepare the request body as BinaryData
|
|
584
609
|
generateProtocolApi = false;
|
|
585
|
-
|
|
586
|
-
|
|
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);
|
|
587
617
|
}
|
|
588
618
|
else if (operationIsMultipleContentTypes(httpOperation)) {
|
|
589
619
|
// and multiple content types
|
|
590
620
|
// issue link: https://github.com/Azure/autorest.java/issues/1958#issuecomment-1562558219
|
|
591
621
|
generateConvenienceApi = false;
|
|
592
|
-
|
|
593
|
-
|
|
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);
|
|
594
629
|
}
|
|
595
630
|
else if (operationIsJsonMergePatch(httpOperation) &&
|
|
596
631
|
this.options["stream-style-serialization"] === false) {
|
|
597
632
|
// do not generate convenient method for json merge patch operation if stream-style-serialization is not enabled
|
|
598
633
|
generateConvenienceApi = false;
|
|
599
|
-
|
|
600
|
-
|
|
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);
|
|
601
641
|
}
|
|
602
642
|
}
|
|
603
643
|
if (generateConvenienceApi && convenienceApiName) {
|
|
604
644
|
codeModelOperation.convenienceApi = new ConvenienceApi(convenienceApiName);
|
|
605
645
|
}
|
|
606
|
-
if (
|
|
646
|
+
if (diagnostic) {
|
|
607
647
|
codeModelOperation.language.java = new Language();
|
|
608
|
-
codeModelOperation.language.java.comment =
|
|
648
|
+
codeModelOperation.language.java.comment = diagnostic.message;
|
|
609
649
|
}
|
|
610
650
|
// check for generating protocol api or not
|
|
611
651
|
codeModelOperation.generateProtocolApi = generateProtocolApi && !codeModelOperation.internalApi;
|
|
@@ -622,8 +662,7 @@ export class CodeModelBuilder {
|
|
|
622
662
|
clientContext.hostParameters.forEach((it) => codeModelOperation.addParameter(it));
|
|
623
663
|
// path/query/header parameters
|
|
624
664
|
for (const param of httpOperation.parameters) {
|
|
625
|
-
|
|
626
|
-
if (param.__raw && isCookieParam(this.program, param.__raw)) {
|
|
665
|
+
if (param.kind === "cookie") {
|
|
627
666
|
// ignore cookie parameter
|
|
628
667
|
continue;
|
|
629
668
|
}
|
|
@@ -674,10 +713,6 @@ export class CodeModelBuilder {
|
|
|
674
713
|
}
|
|
675
714
|
processRouteForPaged(op, responses, sdkMethod) {
|
|
676
715
|
var _a, _b;
|
|
677
|
-
if (!this.isBranded()) {
|
|
678
|
-
// TODO: currently unbranded does not support paged operation
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
716
|
if (sdkMethod.kind === "paging" || sdkMethod.kind === "lropaging") {
|
|
682
717
|
for (const response of responses) {
|
|
683
718
|
const bodyType = response.type;
|
|
@@ -769,12 +804,13 @@ export class CodeModelBuilder {
|
|
|
769
804
|
// find serializedName for lro result
|
|
770
805
|
if (finalResultPropertyClientName) {
|
|
771
806
|
(_a = lroMetadata.finalResponse.envelopeResult.properties) === null || _a === void 0 ? void 0 : _a.forEach((p) => {
|
|
772
|
-
var _a;
|
|
807
|
+
var _a, _b, _c;
|
|
773
808
|
// TODO: "p.__raw?.name" should be "p.name", after TCGC fix https://github.com/Azure/typespec-azure/issues/2072
|
|
774
|
-
if (
|
|
775
|
-
p.
|
|
776
|
-
((_a = p.
|
|
777
|
-
|
|
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;
|
|
778
814
|
}
|
|
779
815
|
});
|
|
780
816
|
}
|
|
@@ -811,7 +847,7 @@ export class CodeModelBuilder {
|
|
|
811
847
|
}
|
|
812
848
|
}
|
|
813
849
|
processParameter(op, param, clientContext) {
|
|
814
|
-
var _a, _b;
|
|
850
|
+
var _a, _b, _c;
|
|
815
851
|
if (clientContext.apiVersions && isApiVersion(this.sdkContext, param)) {
|
|
816
852
|
// pre-condition for "isApiVersion": the client supports ApiVersions
|
|
817
853
|
if (this.isArm()) {
|
|
@@ -908,19 +944,19 @@ export class CodeModelBuilder {
|
|
|
908
944
|
break;
|
|
909
945
|
default:
|
|
910
946
|
if (format) {
|
|
911
|
-
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
|
+
});
|
|
912
952
|
}
|
|
913
953
|
break;
|
|
914
954
|
}
|
|
915
955
|
}
|
|
916
956
|
}
|
|
917
|
-
|
|
918
|
-
const parameterOnClient = !isApiVersion(this.sdkContext, param) &&
|
|
919
|
-
param.correspondingMethodParams &&
|
|
920
|
-
param.correspondingMethodParams.length > 0 &&
|
|
921
|
-
param.correspondingMethodParams[0].onClient;
|
|
957
|
+
const parameterOnClient = param.onClient;
|
|
922
958
|
const nullable = param.type.kind === "nullable";
|
|
923
|
-
const parameter = new Parameter(param.name, (
|
|
959
|
+
const parameter = new Parameter(param.name, (_c = param.doc) !== null && _c !== void 0 ? _c : "", schema, {
|
|
924
960
|
summary: param.summary,
|
|
925
961
|
implementation: parameterOnClient
|
|
926
962
|
? ImplementationLocation.Client
|
|
@@ -1195,7 +1231,9 @@ export class CodeModelBuilder {
|
|
|
1195
1231
|
}
|
|
1196
1232
|
addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, originalParameter) {
|
|
1197
1233
|
var _a, _b, _c, _d, _e;
|
|
1198
|
-
const serializedName = opParameter.
|
|
1234
|
+
const serializedName = opParameter.kind === "property"
|
|
1235
|
+
? getPropertySerializedName(opParameter)
|
|
1236
|
+
: opParameter.serializedName;
|
|
1199
1237
|
let existParameter;
|
|
1200
1238
|
if (opParameter.kind !== "property") {
|
|
1201
1239
|
// not body property
|
|
@@ -1237,10 +1275,6 @@ export class CodeModelBuilder {
|
|
|
1237
1275
|
}
|
|
1238
1276
|
}
|
|
1239
1277
|
}
|
|
1240
|
-
findResponseBody(bodyType) {
|
|
1241
|
-
// find a type that possibly without http metadata like @statusCode
|
|
1242
|
-
return this.getEffectiveSchemaType(bodyType);
|
|
1243
|
-
}
|
|
1244
1278
|
processResponse(op, statusCode, sdkResponse, longRunning, isErrorResponse) {
|
|
1245
1279
|
var _a;
|
|
1246
1280
|
// TODO: what to do if more than 1 response?
|
|
@@ -1373,6 +1407,7 @@ export class CodeModelBuilder {
|
|
|
1373
1407
|
return this.schemaCache.process(type, nameHint) || fail("Unable to process schema.");
|
|
1374
1408
|
}
|
|
1375
1409
|
processSchemaImpl(type, nameHint) {
|
|
1410
|
+
var _a;
|
|
1376
1411
|
if (isSdkBuiltInKind(type.kind)) {
|
|
1377
1412
|
return this.processBuiltInType(type, nameHint);
|
|
1378
1413
|
}
|
|
@@ -1404,9 +1439,12 @@ export class CodeModelBuilder {
|
|
|
1404
1439
|
}
|
|
1405
1440
|
}
|
|
1406
1441
|
}
|
|
1407
|
-
const
|
|
1408
|
-
|
|
1409
|
-
|
|
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);
|
|
1410
1448
|
}
|
|
1411
1449
|
processBuiltInType(type, nameHint) {
|
|
1412
1450
|
nameHint = nameHint || type.kind;
|
|
@@ -1679,26 +1717,8 @@ export class CodeModelBuilder {
|
|
|
1679
1717
|
}
|
|
1680
1718
|
return objectSchema;
|
|
1681
1719
|
}
|
|
1682
|
-
getEffectiveSchemaType(type) {
|
|
1683
|
-
var _a;
|
|
1684
|
-
const program = this.program;
|
|
1685
|
-
function isSchemaProperty(property) {
|
|
1686
|
-
return isPayloadProperty(program, property);
|
|
1687
|
-
}
|
|
1688
|
-
if (type.kind === "Model") {
|
|
1689
|
-
const effective = getEffectiveModelType(program, type, isSchemaProperty);
|
|
1690
|
-
if (this.isArm() && ((_a = getNamespace(effective)) === null || _a === void 0 ? void 0 : _a.startsWith("Azure.ResourceManager"))) {
|
|
1691
|
-
// e.g. typespec: Catalog is TrackedResource<CatalogProperties>
|
|
1692
|
-
return type;
|
|
1693
|
-
}
|
|
1694
|
-
else if (effective.name) {
|
|
1695
|
-
return effective;
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
return type;
|
|
1699
|
-
}
|
|
1700
1720
|
processModelProperty(prop) {
|
|
1701
|
-
var _a;
|
|
1721
|
+
var _a, _b;
|
|
1702
1722
|
let nullable = false;
|
|
1703
1723
|
let nonNullType = prop.type;
|
|
1704
1724
|
if (nonNullType.kind === "nullable") {
|
|
@@ -1722,9 +1742,9 @@ export class CodeModelBuilder {
|
|
|
1722
1742
|
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
1723
1743
|
extensions["x-ms-mutability"] = mutability;
|
|
1724
1744
|
}
|
|
1725
|
-
if (prop.kind === "property" && prop.
|
|
1745
|
+
if (prop.kind === "property" && prop.serializationOptions.multipart) {
|
|
1726
1746
|
// TODO: handle MultipartOptions.isMulti
|
|
1727
|
-
if (prop.
|
|
1747
|
+
if ((_a = prop.serializationOptions.multipart) === null || _a === void 0 ? void 0 : _a.isFilePart) {
|
|
1728
1748
|
schema = this.processMultipartFormDataFilePropertySchema(prop);
|
|
1729
1749
|
}
|
|
1730
1750
|
else if (prop.type.kind === "model" &&
|
|
@@ -1739,25 +1759,30 @@ export class CodeModelBuilder {
|
|
|
1739
1759
|
else {
|
|
1740
1760
|
schema = this.processSchema(nonNullType, "");
|
|
1741
1761
|
}
|
|
1742
|
-
return new Property(prop.name, (
|
|
1762
|
+
return new Property(prop.name, (_b = prop.doc) !== null && _b !== void 0 ? _b : "", schema, {
|
|
1743
1763
|
summary: prop.summary,
|
|
1744
1764
|
required: !prop.optional,
|
|
1745
1765
|
nullable: nullable,
|
|
1746
1766
|
readOnly: this.isReadOnly(prop),
|
|
1747
|
-
serializedName: prop.kind === "property" ? prop
|
|
1767
|
+
serializedName: prop.kind === "property" ? getPropertySerializedName(prop) : undefined,
|
|
1748
1768
|
extensions: extensions,
|
|
1749
1769
|
});
|
|
1750
1770
|
}
|
|
1751
1771
|
processUnionSchema(type, name) {
|
|
1752
|
-
var _a, _b;
|
|
1772
|
+
var _a, _b, _c;
|
|
1753
1773
|
if (!(type.__raw && type.__raw.kind === "Union")) {
|
|
1754
|
-
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
|
+
});
|
|
1755
1780
|
}
|
|
1756
1781
|
const rawUnionType = type.__raw;
|
|
1757
1782
|
const namespace = getNamespace(rawUnionType);
|
|
1758
|
-
const baseName = (
|
|
1759
|
-
this.
|
|
1760
|
-
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 : "", {
|
|
1761
1786
|
summary: type.summary,
|
|
1762
1787
|
});
|
|
1763
1788
|
unionSchema.anyOf = [];
|
|
@@ -1797,7 +1822,7 @@ export class CodeModelBuilder {
|
|
|
1797
1822
|
getUnionVariantName(type, option) {
|
|
1798
1823
|
var _a, _b;
|
|
1799
1824
|
if (type === undefined) {
|
|
1800
|
-
this.
|
|
1825
|
+
this.trace("Union variant type is undefined.");
|
|
1801
1826
|
return "UnionVariant";
|
|
1802
1827
|
}
|
|
1803
1828
|
switch (type.kind) {
|
|
@@ -1855,12 +1880,12 @@ export class CodeModelBuilder {
|
|
|
1855
1880
|
case "UnionVariant":
|
|
1856
1881
|
return (_b = (typeof type.name === "string" ? type.name : undefined)) !== null && _b !== void 0 ? _b : "UnionVariant";
|
|
1857
1882
|
default:
|
|
1858
|
-
this.
|
|
1883
|
+
this.trace(`Unrecognized type for union variable: '${type.kind}'.`);
|
|
1859
1884
|
return "UnionVariant";
|
|
1860
1885
|
}
|
|
1861
1886
|
}
|
|
1862
1887
|
processMultipartFormDataFilePropertySchema(property) {
|
|
1863
|
-
var _a;
|
|
1888
|
+
var _a, _b;
|
|
1864
1889
|
const processSchemaFunc = (type) => this.processSchema(type, "");
|
|
1865
1890
|
const processNamespaceFunc = (type) => {
|
|
1866
1891
|
var _a;
|
|
@@ -1880,9 +1905,13 @@ export class CodeModelBuilder {
|
|
|
1880
1905
|
});
|
|
1881
1906
|
}
|
|
1882
1907
|
else {
|
|
1883
|
-
const
|
|
1884
|
-
|
|
1885
|
-
|
|
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);
|
|
1886
1915
|
}
|
|
1887
1916
|
}
|
|
1888
1917
|
getDoc(target) {
|
|
@@ -1891,21 +1920,6 @@ export class CodeModelBuilder {
|
|
|
1891
1920
|
getSummary(target) {
|
|
1892
1921
|
return target ? getSummary(this.program, target) : undefined;
|
|
1893
1922
|
}
|
|
1894
|
-
getSerializedName(target) {
|
|
1895
|
-
if (isHeader(this.program, target)) {
|
|
1896
|
-
return getHeaderFieldName(this.program, target);
|
|
1897
|
-
}
|
|
1898
|
-
else if (isQueryParam(this.program, target)) {
|
|
1899
|
-
return getQueryParamName(this.program, target);
|
|
1900
|
-
}
|
|
1901
|
-
else if (isPathParam(this.program, target)) {
|
|
1902
|
-
return getPathParamName(this.program, target);
|
|
1903
|
-
}
|
|
1904
|
-
else {
|
|
1905
|
-
// TODO: currently this is only for JSON
|
|
1906
|
-
return getWireName(this.sdkContext, target);
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
1923
|
isReadOnly(target) {
|
|
1910
1924
|
const segment = target.__raw ? getSegment(this.program, target.__raw) !== undefined : false;
|
|
1911
1925
|
if (segment) {
|
|
@@ -2029,12 +2043,6 @@ export class CodeModelBuilder {
|
|
|
2029
2043
|
return clientNamespace.toLowerCase();
|
|
2030
2044
|
}
|
|
2031
2045
|
}
|
|
2032
|
-
logError(msg) {
|
|
2033
|
-
logError(this.program, msg);
|
|
2034
|
-
}
|
|
2035
|
-
logWarning(msg) {
|
|
2036
|
-
logWarning(this.program, msg);
|
|
2037
|
-
}
|
|
2038
2046
|
trace(msg) {
|
|
2039
2047
|
trace(this.program, msg);
|
|
2040
2048
|
}
|