@azure-tools/typespec-java 0.15.18 → 0.16.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 +28 -33
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +303 -644
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/operation-utils.d.ts +1 -1
- package/dist/src/operation-utils.d.ts.map +1 -1
- package/dist/src/operation-utils.js +3 -0
- package/dist/src/operation-utils.js.map +1 -1
- package/dist/src/type-utils.d.ts +6 -4
- package/dist/src/type-utils.d.ts.map +1 -1
- package/dist/src/type-utils.js +67 -40
- package/dist/src/type-utils.js.map +1 -1
- package/dist/src/utils.d.ts +2 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +11 -6
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/target/emitter.jar +0 -0
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import {
|
|
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
|
+
import { KnownMediaType } from "@azure-tools/codegen";
|
|
3
|
+
import { getLroMetadata, getPagedResult, isPollingLocation } from "@azure-tools/typespec-azure-core";
|
|
4
|
+
import { createSdkContext, getAllModels, getClientNameOverride, getClientType, getCrossLanguageDefinitionId, getDefaultApiVersion, getWireName, isApiVersion, isInternal, isSdkBuiltInKind, isSdkIntKind, listClients, listOperationGroups, listOperationsInOperationGroup, shouldGenerateConvenient, shouldGenerateProtocol, } from "@azure-tools/typespec-client-generator-core";
|
|
5
|
+
import { getDoc, getEffectiveModelType, getEncode, getFriendlyName, getNamespaceFullName, getOverloadedOperation, getProjectedName, getSummary, getTypeName, getVisibility, ignoreDiagnostics, isArrayModelType, isErrorModel, isRecordModelType, isVoidType, listServices, } from "@typespec/compiler";
|
|
6
|
+
import { Visibility, getAuthentication, getHeaderFieldOptions, getHttpOperation, getQueryParamOptions, getServers, getStatusCodeDescription, isPathParam, } from "@typespec/http";
|
|
2
7
|
import { getResourceOperation, getSegment } from "@typespec/rest";
|
|
3
|
-
import { getAuthentication, getServers, getStatusCodeDescription, getHttpOperation, getQueryParamOptions, getHeaderFieldOptions, isPathParam, } from "@typespec/http";
|
|
4
8
|
import { getAddedOnVersions, getVersion } from "@typespec/versioning";
|
|
5
|
-
import { isPollingLocation, getPagedResult, getLroMetadata, getUnionAsEnum, } from "@azure-tools/typespec-azure-core";
|
|
6
|
-
import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, getClientNameOverride, shouldFlattenProperty, getWireName, getDefaultApiVersion, } from "@azure-tools/typespec-client-generator-core";
|
|
7
9
|
import { fail } from "assert";
|
|
8
|
-
import
|
|
9
|
-
import { KnownMediaType } from "@azure-tools/codegen";
|
|
10
|
-
import { CodeModel } from "./common/code-model.js";
|
|
10
|
+
import pkg from "lodash";
|
|
11
11
|
import { Client as CodeModelClient, ObjectScheme } from "./common/client.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { CodeModel } from "./common/code-model.js";
|
|
13
|
+
import { LongRunningMetadata } from "./common/long-running-metadata.js";
|
|
14
|
+
import { Operation as CodeModelOperation, ConvenienceApi, Request } from "./common/operation.js";
|
|
14
15
|
import { ChoiceSchema, SealedChoiceSchema } from "./common/schemas/choice.js";
|
|
15
16
|
import { ConstantSchema, ConstantValue } from "./common/schemas/constant.js";
|
|
16
17
|
import { OrSchema } from "./common/schemas/relationship.js";
|
|
17
|
-
import { LongRunningMetadata } from "./common/long-running-metadata.js";
|
|
18
18
|
import { DurationSchema } from "./common/schemas/time.js";
|
|
19
|
-
import {
|
|
19
|
+
import { SchemaContext } from "./common/schemas/usage.js";
|
|
20
20
|
import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./external-schemas.js";
|
|
21
21
|
import { ClientContext } from "./models.js";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import pkg from "lodash";
|
|
22
|
+
import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, getServiceVersion, isKnownContentType, isLroNewPollingStrategy, isPayloadProperty, loadExamples, operationIsJsonMergePatch, operationIsMultipart, operationIsMultipleContentTypes, } from "./operation-utils.js";
|
|
23
|
+
import { PreNamer } from "./prenamer/prenamer.js";
|
|
24
|
+
import { ProcessingCache, getAccess, getDurationFormatFromSdkType, getNameForTemplate, getNamePrefixForProperty, getUnionDescription, getUsage, hasScalarAsBase, isArmCommonType, isModelReferredInTemplate, isNullableType, isStable, modelIs, pushDistinct, } from "./type-utils.js";
|
|
25
|
+
import { getJavaNamespace, getNamespace, logWarning, pascalCase, stringArrayContainsIgnoreCase, trace, } from "./utils.js";
|
|
27
26
|
const { isEqual } = pkg;
|
|
28
27
|
export class CodeModelBuilder {
|
|
29
28
|
constructor(program1, context) {
|
|
30
29
|
var _a, _b;
|
|
31
30
|
this.loggingEnabled = false;
|
|
32
|
-
this.schemaCache = new ProcessingCache((type, name) => this.
|
|
33
|
-
this.typeUnionRefCache = new Map(); // Union means it ref a Union type, null means it does not ref any Union,
|
|
31
|
+
this.schemaCache = new ProcessingCache((type, name) => this.processSchemaFromSdkTypeImpl(type, name));
|
|
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
|
|
34
33
|
this.operationExamples = new Map();
|
|
35
34
|
this.options = context.options;
|
|
36
35
|
this.program = program1;
|
|
@@ -108,7 +107,8 @@ export class CodeModelBuilder {
|
|
|
108
107
|
parameter = this.createApiVersionParameter(it.name, ParameterLocation.Uri);
|
|
109
108
|
}
|
|
110
109
|
else {
|
|
111
|
-
const
|
|
110
|
+
const sdkType = getClientType(this.sdkContext, it.type);
|
|
111
|
+
const schema = this.processSchemaFromSdkType(sdkType, it.name);
|
|
112
112
|
this.trackSchemaUsage(schema, {
|
|
113
113
|
usage: [SchemaContext.Input, SchemaContext.Output /*SchemaContext.Public*/],
|
|
114
114
|
});
|
|
@@ -119,7 +119,6 @@ export class CodeModelBuilder {
|
|
|
119
119
|
protocol: {
|
|
120
120
|
http: new HttpParameter(ParameterLocation.Uri),
|
|
121
121
|
},
|
|
122
|
-
clientDefaultValue: this.getDefaultValue(it.default),
|
|
123
122
|
language: {
|
|
124
123
|
default: {
|
|
125
124
|
serializedName: it.name,
|
|
@@ -219,54 +218,36 @@ export class CodeModelBuilder {
|
|
|
219
218
|
}
|
|
220
219
|
}
|
|
221
220
|
processModels(clients) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
(_a = client.service.namespaces) === null || _a === void 0 ? void 0 : _a.forEach((it) => {
|
|
229
|
-
Array.from(it.models.values()).forEach((it) => models.push(it));
|
|
230
|
-
Array.from(it.enums.values()).forEach((it) => models.push(it));
|
|
231
|
-
Array.from(it.unions.values()).forEach((it) => models.push(it));
|
|
221
|
+
const processedSdkModels = new Set();
|
|
222
|
+
// lambda to mark model as public
|
|
223
|
+
const modelAsPublic = (model) => {
|
|
224
|
+
const schema = this.processSchemaFromSdkType(model, "");
|
|
225
|
+
this.trackSchemaUsage(schema, {
|
|
226
|
+
usage: [SchemaContext.Public],
|
|
232
227
|
});
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
else if (access === "internal") {
|
|
256
|
-
const schema = this.processSchema(model, "");
|
|
257
|
-
this.trackSchemaUsage(schema, {
|
|
258
|
-
usage: [SchemaContext.Internal],
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
const usage = getUsage(model);
|
|
262
|
-
if (usage) {
|
|
263
|
-
const schema = this.processSchema(model, "");
|
|
264
|
-
this.trackSchemaUsage(schema, {
|
|
265
|
-
usage: usage,
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
processedModels.add(model);
|
|
228
|
+
};
|
|
229
|
+
const sdkModels = getAllModels(this.sdkContext);
|
|
230
|
+
// process sdk models
|
|
231
|
+
for (const model of sdkModels) {
|
|
232
|
+
if (!processedSdkModels.has(model)) {
|
|
233
|
+
const access = getAccess(model.__raw);
|
|
234
|
+
if (access === "public") {
|
|
235
|
+
modelAsPublic(model);
|
|
236
|
+
}
|
|
237
|
+
else if (access === "internal") {
|
|
238
|
+
const schema = this.processSchemaFromSdkType(model, model.name);
|
|
239
|
+
this.trackSchemaUsage(schema, {
|
|
240
|
+
usage: [SchemaContext.Internal],
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
const usage = getUsage(model.__raw);
|
|
244
|
+
if (usage) {
|
|
245
|
+
const schema = this.processSchemaFromSdkType(model, "");
|
|
246
|
+
this.trackSchemaUsage(schema, {
|
|
247
|
+
usage: usage,
|
|
248
|
+
});
|
|
269
249
|
}
|
|
250
|
+
processedSdkModels.add(model);
|
|
270
251
|
}
|
|
271
252
|
}
|
|
272
253
|
}
|
|
@@ -684,7 +665,8 @@ export class CodeModelBuilder {
|
|
|
684
665
|
}
|
|
685
666
|
else {
|
|
686
667
|
const pollType = this.findResponseBody(lroMetadata.pollingInfo.responseModel);
|
|
687
|
-
|
|
668
|
+
const sdkType = getClientType(this.sdkContext, pollType);
|
|
669
|
+
pollingSchema = this.processSchemaFromSdkType(sdkType, "pollResult");
|
|
688
670
|
}
|
|
689
671
|
}
|
|
690
672
|
// finalSchema
|
|
@@ -695,25 +677,24 @@ export class CodeModelBuilder {
|
|
|
695
677
|
lroMetadata.finalEnvelopeResult !== "void") {
|
|
696
678
|
const finalResult = useNewPollStrategy ? lroMetadata.finalResult : lroMetadata.finalEnvelopeResult;
|
|
697
679
|
const finalType = this.findResponseBody(finalResult);
|
|
698
|
-
|
|
680
|
+
const sdkType = getClientType(this.sdkContext, finalType);
|
|
681
|
+
finalSchema = this.processSchemaFromSdkType(sdkType, "finalResult");
|
|
699
682
|
}
|
|
700
683
|
// track usage
|
|
701
684
|
if (pollingSchema) {
|
|
702
685
|
this.trackSchemaUsage(pollingSchema, { usage: [SchemaContext.Output] });
|
|
703
|
-
if (op.
|
|
704
|
-
this.trackSchemaUsage(pollingSchema, {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
this.trackSchemaUsage(pollingSchema, { usage: [SchemaContext.Public] });
|
|
686
|
+
if (op.convenienceApi) {
|
|
687
|
+
this.trackSchemaUsage(pollingSchema, {
|
|
688
|
+
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
|
|
689
|
+
});
|
|
708
690
|
}
|
|
709
691
|
}
|
|
710
692
|
if (finalSchema) {
|
|
711
693
|
this.trackSchemaUsage(finalSchema, { usage: [SchemaContext.Output] });
|
|
712
|
-
if (op.
|
|
713
|
-
this.trackSchemaUsage(
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
this.trackSchemaUsage(finalSchema, { usage: [SchemaContext.Public] });
|
|
694
|
+
if (op.convenienceApi) {
|
|
695
|
+
this.trackSchemaUsage(finalSchema, {
|
|
696
|
+
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
|
|
697
|
+
});
|
|
717
698
|
}
|
|
718
699
|
}
|
|
719
700
|
op.lroMetadata = new LongRunningMetadata(true, pollingSchema, finalSchema, pollingStrategy);
|
|
@@ -775,16 +756,18 @@ export class CodeModelBuilder {
|
|
|
775
756
|
else {
|
|
776
757
|
// schema
|
|
777
758
|
let schema;
|
|
759
|
+
const sdkType = getClientType(this.sdkContext, param.param);
|
|
778
760
|
if (param.type === "header" &&
|
|
779
761
|
param.param.type.kind === "Scalar" &&
|
|
780
762
|
getEncode(this.program, param.param) === undefined &&
|
|
781
763
|
getEncode(this.program, param.param.type) === undefined &&
|
|
782
|
-
(hasScalarAsBase(param.param.type, "utcDateTime") || hasScalarAsBase(param.param.type, "offsetDateTime"))
|
|
764
|
+
(hasScalarAsBase(param.param.type, "utcDateTime") || hasScalarAsBase(param.param.type, "offsetDateTime")) &&
|
|
765
|
+
(sdkType.kind === "utcDateTime" || sdkType.kind === "offsetDateTime")) {
|
|
783
766
|
// utcDateTime in header maps to rfc7231
|
|
784
|
-
schema = this.
|
|
767
|
+
schema = this.processDateTimeSchemaFromSdkType(sdkType, param.param.name, true);
|
|
785
768
|
}
|
|
786
769
|
else {
|
|
787
|
-
schema = this.
|
|
770
|
+
schema = this.processSchemaFromSdkType(sdkType, param.param.name);
|
|
788
771
|
}
|
|
789
772
|
// skip-url-encoding
|
|
790
773
|
let extensions = undefined;
|
|
@@ -857,7 +840,6 @@ export class CodeModelBuilder {
|
|
|
857
840
|
explode: explode,
|
|
858
841
|
}),
|
|
859
842
|
},
|
|
860
|
-
// clientDefaultValue: this.getDefaultValue(param.param.default),
|
|
861
843
|
language: {
|
|
862
844
|
default: {
|
|
863
845
|
serializedName: param.name,
|
|
@@ -867,11 +849,8 @@ export class CodeModelBuilder {
|
|
|
867
849
|
});
|
|
868
850
|
op.addParameter(parameter);
|
|
869
851
|
this.trackSchemaUsage(schema, { usage: [SchemaContext.Input] });
|
|
870
|
-
if (op.
|
|
871
|
-
this.trackSchemaUsage(schema, { usage: [SchemaContext.Internal] });
|
|
872
|
-
}
|
|
873
|
-
else if (op.convenienceApi) {
|
|
874
|
-
this.trackSchemaUsage(schema, { usage: [SchemaContext.Public] });
|
|
852
|
+
if (op.convenienceApi) {
|
|
853
|
+
this.trackSchemaUsage(schema, { usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public] });
|
|
875
854
|
}
|
|
876
855
|
if (param.name.toLowerCase() === CONTENT_TYPE_KEY) {
|
|
877
856
|
let mediaTypes = ["application/json"];
|
|
@@ -995,11 +974,10 @@ export class CodeModelBuilder {
|
|
|
995
974
|
nullable: true,
|
|
996
975
|
});
|
|
997
976
|
this.trackSchemaUsage(requestConditionsSchema, { usage: [SchemaContext.Input] });
|
|
998
|
-
if (op.
|
|
999
|
-
this.trackSchemaUsage(requestConditionsSchema, {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
this.trackSchemaUsage(requestConditionsSchema, { usage: [SchemaContext.Public] });
|
|
977
|
+
if (op.convenienceApi) {
|
|
978
|
+
this.trackSchemaUsage(requestConditionsSchema, {
|
|
979
|
+
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
|
|
980
|
+
});
|
|
1003
981
|
}
|
|
1004
982
|
// update group schema for properties
|
|
1005
983
|
for (const parameter of request.parameters) {
|
|
@@ -1030,6 +1008,7 @@ export class CodeModelBuilder {
|
|
|
1030
1008
|
const unknownRequestBody = op.requests[0].protocol.http.mediaTypes &&
|
|
1031
1009
|
op.requests[0].protocol.http.mediaTypes.length > 0 &&
|
|
1032
1010
|
!isKnownContentType(op.requests[0].protocol.http.mediaTypes);
|
|
1011
|
+
const sdkType = getClientType(this.sdkContext, body, httpOperation.operation);
|
|
1033
1012
|
let schema;
|
|
1034
1013
|
if (unknownRequestBody &&
|
|
1035
1014
|
body.kind === "ModelProperty" &&
|
|
@@ -1039,8 +1018,9 @@ export class CodeModelBuilder {
|
|
|
1039
1018
|
schema = this.processBinarySchema(body.type);
|
|
1040
1019
|
}
|
|
1041
1020
|
else {
|
|
1042
|
-
schema = this.
|
|
1021
|
+
schema = this.processSchemaFromSdkType(sdkType, body.name);
|
|
1043
1022
|
}
|
|
1023
|
+
const isAnonymousModel = sdkType.kind === "model" && sdkType.isGeneratedName === true;
|
|
1044
1024
|
const parameter = new Parameter(this.getName(body), this.getDoc(body), schema, {
|
|
1045
1025
|
summary: this.getSummary(body),
|
|
1046
1026
|
implementation: ImplementationLocation.Method,
|
|
@@ -1048,26 +1028,20 @@ export class CodeModelBuilder {
|
|
|
1048
1028
|
protocol: {
|
|
1049
1029
|
http: new HttpParameter(ParameterLocation.Body),
|
|
1050
1030
|
},
|
|
1051
|
-
// clientDefaultValue: this.getDefaultValue(body.default),
|
|
1052
1031
|
});
|
|
1053
1032
|
op.addParameter(parameter);
|
|
1054
1033
|
this.trackSchemaUsage(schema, { usage: [SchemaContext.Input] });
|
|
1055
|
-
if (op.
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
else if (op.convenienceApi) {
|
|
1059
|
-
this.trackSchemaUsage(schema, { usage: [SchemaContext.Public] });
|
|
1034
|
+
if (op.convenienceApi) {
|
|
1035
|
+
// model/schema does not need to be Public or Internal, if it is not to be used in convenience API
|
|
1036
|
+
this.trackSchemaUsage(schema, { usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public] });
|
|
1060
1037
|
}
|
|
1061
1038
|
if (operationIsJsonMergePatch(httpOperation)) {
|
|
1062
1039
|
this.trackSchemaUsage(schema, { usage: [SchemaContext.JsonMergePatch] });
|
|
1063
1040
|
}
|
|
1064
1041
|
if (op.convenienceApi && operationIsMultipart(httpOperation)) {
|
|
1065
|
-
if (schema instanceof ObjectSchema) {
|
|
1066
|
-
this.processMultipartFormDataSchema(schema);
|
|
1067
|
-
}
|
|
1068
1042
|
this.trackSchemaUsage(schema, { serializationFormats: [KnownMediaType.Multipart] });
|
|
1069
1043
|
}
|
|
1070
|
-
if (schema instanceof ObjectSchema &&
|
|
1044
|
+
if (schema instanceof ObjectSchema && isAnonymousModel) {
|
|
1071
1045
|
// anonymous model
|
|
1072
1046
|
// name the schema for documentation
|
|
1073
1047
|
schema.language.default.name = pascalCase(op.language.default.name) + "Request";
|
|
@@ -1147,11 +1121,10 @@ export class CodeModelBuilder {
|
|
|
1147
1121
|
}));
|
|
1148
1122
|
});
|
|
1149
1123
|
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Input] });
|
|
1150
|
-
if (op.
|
|
1151
|
-
this.trackSchemaUsage(optionBagSchema, {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Public] });
|
|
1124
|
+
if (op.convenienceApi) {
|
|
1125
|
+
this.trackSchemaUsage(optionBagSchema, {
|
|
1126
|
+
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
|
|
1127
|
+
});
|
|
1155
1128
|
}
|
|
1156
1129
|
// option bag parameter
|
|
1157
1130
|
const optionBagParameter = new Parameter("options", optionBagSchema.language.default.description, optionBagSchema, {
|
|
@@ -1182,7 +1155,8 @@ export class CodeModelBuilder {
|
|
|
1182
1155
|
for (const response of resp.responses.values()) {
|
|
1183
1156
|
if (response.headers) {
|
|
1184
1157
|
for (const [key, header] of Object.entries(response.headers)) {
|
|
1185
|
-
const
|
|
1158
|
+
const sdkType = getClientType(this.sdkContext, header);
|
|
1159
|
+
const schema = this.processSchemaFromSdkType(sdkType, key);
|
|
1186
1160
|
headers.push(new HttpHeader(key, schema, {
|
|
1187
1161
|
language: {
|
|
1188
1162
|
default: {
|
|
@@ -1266,7 +1240,8 @@ export class CodeModelBuilder {
|
|
|
1266
1240
|
schema = op.lroMetadata.pollResultType;
|
|
1267
1241
|
}
|
|
1268
1242
|
else {
|
|
1269
|
-
|
|
1243
|
+
const sdkType = getClientType(this.sdkContext, bodyType);
|
|
1244
|
+
schema = this.processSchemaFromSdkType(sdkType, op.language.default.name + "Response");
|
|
1270
1245
|
}
|
|
1271
1246
|
}
|
|
1272
1247
|
response = new SchemaResponse(schema, {
|
|
@@ -1314,11 +1289,10 @@ export class CodeModelBuilder {
|
|
|
1314
1289
|
op.addResponse(response);
|
|
1315
1290
|
if (response instanceof SchemaResponse) {
|
|
1316
1291
|
this.trackSchemaUsage(response.schema, { usage: [SchemaContext.Output] });
|
|
1317
|
-
if (
|
|
1318
|
-
this.trackSchemaUsage(response.schema, {
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
this.trackSchemaUsage(response.schema, { usage: [SchemaContext.Public] });
|
|
1292
|
+
if (trackConvenienceApi) {
|
|
1293
|
+
this.trackSchemaUsage(response.schema, {
|
|
1294
|
+
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
|
|
1295
|
+
});
|
|
1322
1296
|
}
|
|
1323
1297
|
}
|
|
1324
1298
|
}
|
|
@@ -1344,229 +1318,150 @@ export class CodeModelBuilder {
|
|
|
1344
1318
|
(resp.statusCodes === "*" ? "An unexpected error response" : getStatusCodeDescription(resp.statusCodes)) ||
|
|
1345
1319
|
"");
|
|
1346
1320
|
}
|
|
1347
|
-
|
|
1321
|
+
processSchemaFromSdkType(type, nameHint) {
|
|
1348
1322
|
return this.schemaCache.process(type, nameHint) || fail("Unable to process schema.");
|
|
1349
1323
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
schema = this.processSchema(type.type, schemaNameHint);
|
|
1381
|
-
}
|
|
1382
|
-
return this.applyModelPropertyDecorators(type, nameHint, schema);
|
|
1324
|
+
processSchemaFromSdkTypeImpl(type, nameHint) {
|
|
1325
|
+
if (isSdkBuiltInKind(type.kind)) {
|
|
1326
|
+
return this.processBuiltInFromSdkType(type, nameHint);
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
switch (type.kind) {
|
|
1330
|
+
case "enum":
|
|
1331
|
+
return this.processChoiceSchemaFromSdkType(type, type.name);
|
|
1332
|
+
case "enumvalue":
|
|
1333
|
+
return this.processConstantSchemaFromEnumValueFromSdkType(type, nameHint);
|
|
1334
|
+
case "union":
|
|
1335
|
+
return this.processUnionSchemaFromSdkType(type, type.name);
|
|
1336
|
+
case "model":
|
|
1337
|
+
return this.processObjectSchemaFromSdkType(type, type.name);
|
|
1338
|
+
case "dict":
|
|
1339
|
+
return this.processDictionarySchemaFromSdkType(type, nameHint);
|
|
1340
|
+
case "array":
|
|
1341
|
+
return this.processArraySchemaFromSdkType(type, nameHint);
|
|
1342
|
+
case "duration":
|
|
1343
|
+
return this.processDurationSchemaFromSdkType(type, nameHint, getDurationFormatFromSdkType(type));
|
|
1344
|
+
case "constant":
|
|
1345
|
+
return this.processConstantSchemaFromSdkType(type, nameHint);
|
|
1346
|
+
case "utcDateTime":
|
|
1347
|
+
case "offsetDateTime":
|
|
1348
|
+
if (type.encode === "unixTimestamp") {
|
|
1349
|
+
return this.processUnixTimeSchemaFromSdkType(type, nameHint);
|
|
1350
|
+
}
|
|
1351
|
+
else {
|
|
1352
|
+
return this.processDateTimeSchemaFromSdkType(type, nameHint, type.encode === "rfc7231");
|
|
1353
|
+
}
|
|
1383
1354
|
}
|
|
1384
|
-
case "Scalar":
|
|
1385
|
-
return this.processScalar(type, undefined, nameHint);
|
|
1386
|
-
case "Model":
|
|
1387
|
-
if (isArrayModelType(this.program, type)) {
|
|
1388
|
-
return this.processArraySchema(type, nameHint);
|
|
1389
|
-
}
|
|
1390
|
-
else if (isRecordModelType(this.program, type) && type.properties.size == 0) {
|
|
1391
|
-
// "pure" Record that does not have properties in it
|
|
1392
|
-
return this.processDictionarySchema(type, nameHint);
|
|
1393
|
-
}
|
|
1394
|
-
else {
|
|
1395
|
-
return this.processObjectSchema(type, this.getName(type, nameHint));
|
|
1396
|
-
}
|
|
1397
|
-
case "EnumMember":
|
|
1398
|
-
// e.g. "type: TypeEnum.EnumValue1"
|
|
1399
|
-
return this.processConstantSchemaForEnumMember(type, this.getName(type));
|
|
1400
|
-
case "UnionVariant":
|
|
1401
|
-
// e.g. "type: Union.Variant1"
|
|
1402
|
-
if (type.type.kind === "String" || type.type.kind === "Number" || type.type.kind === "Boolean") {
|
|
1403
|
-
return this.processConstantSchemaForUnionVariant(type, this.getName(type));
|
|
1404
|
-
}
|
|
1405
|
-
else {
|
|
1406
|
-
throw new Error(`Unsupported type reference to UnionVariant.`);
|
|
1407
|
-
}
|
|
1408
1355
|
}
|
|
1409
1356
|
throw new Error(`Unrecognized type: '${type.kind}'.`);
|
|
1410
1357
|
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
if (
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1358
|
+
processBuiltInFromSdkType(type, nameHint) {
|
|
1359
|
+
nameHint = nameHint || type.kind;
|
|
1360
|
+
if (isSdkIntKind(type.kind)) {
|
|
1361
|
+
const integerSize = type.kind === "safeint" || type.kind.includes("int64") ? 64 : 32;
|
|
1362
|
+
return this.processIntegerSchemaFromSdkType(type, nameHint, integerSize);
|
|
1363
|
+
}
|
|
1364
|
+
else {
|
|
1365
|
+
switch (type.kind) {
|
|
1366
|
+
case "any":
|
|
1367
|
+
return this.processAnySchemaFromSdkType();
|
|
1368
|
+
case "string":
|
|
1369
|
+
case "password":
|
|
1370
|
+
case "guid":
|
|
1371
|
+
case "ipAddress":
|
|
1372
|
+
case "uuid":
|
|
1373
|
+
case "ipV4Address":
|
|
1374
|
+
case "ipV6Address":
|
|
1375
|
+
case "eTag":
|
|
1376
|
+
case "armId":
|
|
1377
|
+
case "azureLocation":
|
|
1378
|
+
return this.processStringSchemaFromSdkType(type, type.kind);
|
|
1379
|
+
case "float":
|
|
1380
|
+
case "float32":
|
|
1381
|
+
case "float64":
|
|
1382
|
+
return this.processNumberSchemaFromSdkType(type, nameHint);
|
|
1383
|
+
case "decimal":
|
|
1384
|
+
case "decimal128":
|
|
1385
|
+
return this.processDecimalSchemaFromSdkType(type, nameHint);
|
|
1423
1386
|
case "bytes":
|
|
1424
|
-
return this.
|
|
1387
|
+
return this.processByteArraySchemaFromSdkType(type, nameHint);
|
|
1425
1388
|
case "boolean":
|
|
1426
|
-
return this.
|
|
1389
|
+
return this.processBooleanSchemaFromSdkType(type, nameHint);
|
|
1427
1390
|
case "plainTime":
|
|
1428
|
-
return this.
|
|
1391
|
+
return this.processTimeSchemaFromSdkType(type, nameHint);
|
|
1429
1392
|
case "plainDate":
|
|
1430
|
-
return this.
|
|
1431
|
-
case "utcDateTime":
|
|
1432
|
-
case "offsetDateTime":
|
|
1433
|
-
return this.processDateTimeSchema(type, nameHint, false);
|
|
1434
|
-
case "duration":
|
|
1435
|
-
return this.processDurationSchema(type, nameHint);
|
|
1393
|
+
return this.processDateSchemaFromSdkType(type, nameHint);
|
|
1436
1394
|
case "url":
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
if (scalarName.startsWith("decimal")) {
|
|
1440
|
-
// decimal
|
|
1441
|
-
return this.processDecimalSchema(type, nameHint);
|
|
1442
|
-
}
|
|
1443
|
-
else if (scalarName.startsWith("int") || scalarName.startsWith("uint") || scalarName === "safeint") {
|
|
1444
|
-
// integer
|
|
1445
|
-
const integerSize = scalarName === "safeint" || scalarName.includes("int64") ? 64 : 32;
|
|
1446
|
-
return this.processIntegerSchema(type, nameHint, integerSize);
|
|
1447
|
-
}
|
|
1448
|
-
else if (scalarName.startsWith("float")) {
|
|
1449
|
-
// float point
|
|
1450
|
-
return this.processNumberSchema(type, nameHint);
|
|
1451
|
-
}
|
|
1452
|
-
else {
|
|
1453
|
-
throw new Error(`Unrecognized scalar type: '${scalarName}'.`);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
else {
|
|
1457
|
-
const knownValues = getKnownValues(this.program, type);
|
|
1458
|
-
if (knownValues) {
|
|
1459
|
-
// use it for extensible enum
|
|
1460
|
-
return this.processChoiceSchema(knownValues, this.getName(type), false);
|
|
1461
|
-
}
|
|
1462
|
-
else {
|
|
1463
|
-
const encode = getEncode(this.program, type);
|
|
1464
|
-
if (encode) {
|
|
1465
|
-
// process as encode
|
|
1466
|
-
if (encode.encoding === "seconds" && hasScalarAsBase(type, "duration")) {
|
|
1467
|
-
return this.processDurationSchema(type, nameHint, getDurationFormat(encode));
|
|
1468
|
-
}
|
|
1469
|
-
else if ((encode.encoding === "rfc3339" || encode.encoding === "rfc7231" || encode.encoding === "unixTimestamp") &&
|
|
1470
|
-
(hasScalarAsBase(type, "utcDateTime") || hasScalarAsBase(type, "offsetDateTime"))) {
|
|
1471
|
-
if (encode.encoding === "unixTimestamp") {
|
|
1472
|
-
return this.processUnixTimeSchema(type, nameHint);
|
|
1473
|
-
}
|
|
1474
|
-
else {
|
|
1475
|
-
return this.processDateTimeSchema(type, nameHint, encode.encoding === "rfc7231");
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
else if (encode.encoding === "base64url" && hasScalarAsBase(type, "bytes")) {
|
|
1479
|
-
return this.processByteArraySchema(type, nameHint, true);
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
if (type.baseScalar) {
|
|
1483
|
-
// fallback to baseScalar
|
|
1484
|
-
const schema = this.processScalar(type.baseScalar, getFormat(this.program, type), nameHint);
|
|
1485
|
-
const doc = getDoc(this.program, type);
|
|
1486
|
-
const summary = getSummary(this.program, type);
|
|
1487
|
-
if (doc) {
|
|
1488
|
-
schema.language.default.description = doc;
|
|
1489
|
-
}
|
|
1490
|
-
if (summary) {
|
|
1491
|
-
schema.summary = summary;
|
|
1492
|
-
}
|
|
1493
|
-
return schema;
|
|
1494
|
-
}
|
|
1495
|
-
else {
|
|
1496
|
-
throw new Error(`Unrecognized scalar type: '${scalarName}'.`);
|
|
1497
|
-
}
|
|
1395
|
+
case "uri":
|
|
1396
|
+
return this.processUrlSchemaFromSdkType(type, nameHint);
|
|
1498
1397
|
}
|
|
1499
1398
|
}
|
|
1500
1399
|
}
|
|
1501
|
-
|
|
1400
|
+
processAnySchemaFromSdkType() {
|
|
1502
1401
|
return this.anySchema;
|
|
1503
1402
|
}
|
|
1504
|
-
|
|
1505
|
-
return this.codeModel.schemas.add(new StringSchema(name, this.getDoc(type), {
|
|
1506
|
-
summary: this.getSummary(type),
|
|
1403
|
+
processStringSchemaFromSdkType(type, name) {
|
|
1404
|
+
return this.codeModel.schemas.add(new StringSchema(name, this.getDoc(type.__raw), {
|
|
1405
|
+
summary: this.getSummary(type.__raw),
|
|
1507
1406
|
}));
|
|
1508
1407
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1408
|
+
processByteArraySchemaFromSdkType(type, name) {
|
|
1409
|
+
const base64Encoded = type.encode === "base64url";
|
|
1410
|
+
return this.codeModel.schemas.add(new ByteArraySchema(name, this.getDoc(type.__raw), {
|
|
1411
|
+
summary: this.getSummary(type.__raw),
|
|
1512
1412
|
format: base64Encoded ? "base64url" : "byte",
|
|
1513
1413
|
}));
|
|
1514
1414
|
}
|
|
1515
|
-
|
|
1516
|
-
return this.codeModel.schemas.add(new NumberSchema(name, this.getDoc(type), SchemaType.Integer, precision, {
|
|
1517
|
-
summary: this.getSummary(type),
|
|
1415
|
+
processIntegerSchemaFromSdkType(type, name, precision) {
|
|
1416
|
+
return this.codeModel.schemas.add(new NumberSchema(name, this.getDoc(type.__raw), SchemaType.Integer, precision, {
|
|
1417
|
+
summary: this.getSummary(type.__raw),
|
|
1518
1418
|
}));
|
|
1519
1419
|
}
|
|
1520
|
-
|
|
1521
|
-
return this.codeModel.schemas.add(new NumberSchema(name, this.getDoc(type), SchemaType.Number, 64, {
|
|
1522
|
-
summary: this.getSummary(type),
|
|
1420
|
+
processNumberSchemaFromSdkType(type, name) {
|
|
1421
|
+
return this.codeModel.schemas.add(new NumberSchema(name, this.getDoc(type.__raw), SchemaType.Number, 64, {
|
|
1422
|
+
summary: this.getSummary(type.__raw),
|
|
1523
1423
|
}));
|
|
1524
1424
|
}
|
|
1525
|
-
|
|
1425
|
+
processDecimalSchemaFromSdkType(type, name) {
|
|
1526
1426
|
// "Infinity" maps to "BigDecimal" in Java
|
|
1527
|
-
return this.codeModel.schemas.add(new NumberSchema(name, this.getDoc(type), SchemaType.Number, Infinity, {
|
|
1528
|
-
summary: this.getSummary(type),
|
|
1427
|
+
return this.codeModel.schemas.add(new NumberSchema(name, this.getDoc(type.__raw), SchemaType.Number, Infinity, {
|
|
1428
|
+
summary: this.getSummary(type.__raw),
|
|
1529
1429
|
}));
|
|
1530
1430
|
}
|
|
1531
|
-
|
|
1532
|
-
return this.codeModel.schemas.add(new BooleanSchema(name, this.getDoc(type), {
|
|
1533
|
-
summary: this.getSummary(type),
|
|
1431
|
+
processBooleanSchemaFromSdkType(type, name) {
|
|
1432
|
+
return this.codeModel.schemas.add(new BooleanSchema(name, this.getDoc(type.__raw), {
|
|
1433
|
+
summary: this.getSummary(type.__raw),
|
|
1534
1434
|
}));
|
|
1535
1435
|
}
|
|
1536
|
-
|
|
1537
|
-
const elementSchema = this.
|
|
1538
|
-
return this.codeModel.schemas.add(new ArraySchema(name, this.getDoc(type), elementSchema, {
|
|
1539
|
-
summary: this.getSummary(type),
|
|
1436
|
+
processArraySchemaFromSdkType(type, name) {
|
|
1437
|
+
const elementSchema = this.processSchemaFromSdkType(type.valueType, name);
|
|
1438
|
+
return this.codeModel.schemas.add(new ArraySchema(name, this.getDoc(type.__raw), elementSchema, {
|
|
1439
|
+
summary: this.getSummary(type.__raw),
|
|
1540
1440
|
}));
|
|
1541
1441
|
}
|
|
1542
|
-
|
|
1543
|
-
const dictSchema = new DictionarySchema(name,
|
|
1544
|
-
summary:
|
|
1442
|
+
processDictionarySchemaFromSdkType(type, name) {
|
|
1443
|
+
const dictSchema = new DictionarySchema(name, type.details ? type.details : "", null, {
|
|
1444
|
+
summary: type.description,
|
|
1545
1445
|
});
|
|
1546
1446
|
// cache this now before we accidentally recurse on this type.
|
|
1547
1447
|
if (!this.schemaCache.has(type)) {
|
|
1548
1448
|
this.schemaCache.set(type, dictSchema);
|
|
1549
1449
|
}
|
|
1550
|
-
const elementSchema = this.
|
|
1450
|
+
const elementSchema = this.processSchemaFromSdkType(type.valueType, name);
|
|
1551
1451
|
dictSchema.elementType = elementSchema;
|
|
1552
|
-
|
|
1553
|
-
dictSchema.nullableItems =
|
|
1554
|
-
Array.from(type.indexer.value.variants.values()).findIndex((it) => isNullType(it.type)) >= 0;
|
|
1555
|
-
}
|
|
1452
|
+
dictSchema.nullableItems = type.nullableValues;
|
|
1556
1453
|
return this.codeModel.schemas.add(dictSchema);
|
|
1557
1454
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
: this.doubleSchema
|
|
1564
|
-
: this.stringSchema;
|
|
1455
|
+
processChoiceSchemaFromSdkType(type, name) {
|
|
1456
|
+
var _a;
|
|
1457
|
+
const rawEnumType = type.__raw;
|
|
1458
|
+
const namespace = getNamespace(rawEnumType);
|
|
1459
|
+
const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind);
|
|
1565
1460
|
const choices = [];
|
|
1566
|
-
type.
|
|
1567
|
-
const schemaType =
|
|
1568
|
-
const schema = new schemaType(name,
|
|
1569
|
-
summary: this.getSummary(
|
|
1461
|
+
type.values.forEach((it) => { var _a, _b; return choices.push(new ChoiceValue(it.name, (_a = it.description) !== null && _a !== void 0 ? _a : "", (_b = it.value) !== null && _b !== void 0 ? _b : it.name)); });
|
|
1462
|
+
const schemaType = type.isFixed ? SealedChoiceSchema : ChoiceSchema;
|
|
1463
|
+
const schema = new schemaType(type.name ? type.name : name, (_a = type.description) !== null && _a !== void 0 ? _a : "", {
|
|
1464
|
+
summary: this.getSummary(rawEnumType),
|
|
1570
1465
|
choiceType: valueType,
|
|
1571
1466
|
choices: choices,
|
|
1572
1467
|
language: {
|
|
@@ -1578,118 +1473,64 @@ export class CodeModelBuilder {
|
|
|
1578
1473
|
},
|
|
1579
1474
|
},
|
|
1580
1475
|
});
|
|
1581
|
-
schema.crossLanguageDefinitionId =
|
|
1476
|
+
schema.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1582
1477
|
return this.codeModel.schemas.add(schema);
|
|
1583
1478
|
}
|
|
1584
|
-
|
|
1585
|
-
const valueType = type.kind
|
|
1586
|
-
|
|
1587
|
-
: type.
|
|
1588
|
-
? this.booleanSchema
|
|
1589
|
-
: isAllValueInteger([type.value])
|
|
1590
|
-
? this.integerSchema
|
|
1591
|
-
: this.doubleSchema;
|
|
1592
|
-
return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
|
|
1593
|
-
summary: this.getSummary(type),
|
|
1479
|
+
processConstantSchemaFromSdkType(type, name) {
|
|
1480
|
+
const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind);
|
|
1481
|
+
return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type.__raw), {
|
|
1482
|
+
summary: this.getSummary(type.__raw),
|
|
1594
1483
|
valueType: valueType,
|
|
1595
1484
|
value: new ConstantValue(type.value),
|
|
1596
1485
|
}));
|
|
1597
1486
|
}
|
|
1598
|
-
|
|
1487
|
+
processConstantSchemaFromEnumValueFromSdkType(type, name) {
|
|
1599
1488
|
var _a;
|
|
1600
|
-
const valueType = this.
|
|
1601
|
-
return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
|
|
1602
|
-
summary: this.getSummary(type),
|
|
1489
|
+
const valueType = this.processSchemaFromSdkType(type.enumType, type.enumType.name);
|
|
1490
|
+
return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type.__raw), {
|
|
1491
|
+
summary: this.getSummary(type.__raw),
|
|
1603
1492
|
valueType: valueType,
|
|
1604
1493
|
value: new ConstantValue((_a = type.value) !== null && _a !== void 0 ? _a : type.name),
|
|
1605
1494
|
}));
|
|
1606
1495
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
return this.codeModel.schemas.add(new ConstantSchema(name, this.getDoc(type), {
|
|
1611
|
-
summary: this.getSummary(type),
|
|
1612
|
-
valueType: valueType,
|
|
1613
|
-
value: new ConstantValue((_a = type.type.value) !== null && _a !== void 0 ? _a : type.name),
|
|
1614
|
-
}));
|
|
1615
|
-
}
|
|
1616
|
-
processChoiceSchemaForUnion(type, unionEnum, name) {
|
|
1617
|
-
// variants is Literal
|
|
1618
|
-
const sealed = !unionEnum.open;
|
|
1619
|
-
const variants = [...unionEnum.flattenedMembers.values()];
|
|
1620
|
-
const kindIsString = typeof variants[0].value === "string";
|
|
1621
|
-
const valueType = kindIsString
|
|
1622
|
-
? this.stringSchema
|
|
1623
|
-
: isAllValueInteger(variants.map((it) => it.value))
|
|
1624
|
-
? this.integerSchema
|
|
1625
|
-
: this.doubleSchema;
|
|
1626
|
-
const choices = [];
|
|
1627
|
-
for (const [name, member] of unionEnum.flattenedMembers.entries()) {
|
|
1628
|
-
// get name from "UnionVariant | EnumMember"
|
|
1629
|
-
let valueName = this.getName(member.type);
|
|
1630
|
-
const valueDoc = this.getDoc(member.type);
|
|
1631
|
-
if (!valueName) {
|
|
1632
|
-
// fallback the name to the dict
|
|
1633
|
-
valueName = typeof name === "string" ? name : `${member.value}`;
|
|
1634
|
-
}
|
|
1635
|
-
// TODO: may need to use getWireName on "member.value"
|
|
1636
|
-
choices.push(new ChoiceValue(valueName, valueDoc, member.value));
|
|
1637
|
-
}
|
|
1638
|
-
const namespace = getNamespace(type);
|
|
1639
|
-
const schemaType = sealed ? SealedChoiceSchema : ChoiceSchema;
|
|
1640
|
-
const schema = new schemaType(name, this.getDoc(type), {
|
|
1641
|
-
summary: this.getSummary(type),
|
|
1642
|
-
choiceType: valueType,
|
|
1643
|
-
choices: choices,
|
|
1644
|
-
language: {
|
|
1645
|
-
default: {
|
|
1646
|
-
namespace: namespace,
|
|
1647
|
-
},
|
|
1648
|
-
java: {
|
|
1649
|
-
namespace: getJavaNamespace(namespace),
|
|
1650
|
-
},
|
|
1651
|
-
},
|
|
1652
|
-
});
|
|
1653
|
-
schema.crossLanguageDefinitionId = getCrossLanguageDefinitionId(type);
|
|
1654
|
-
return this.codeModel.schemas.add(schema);
|
|
1655
|
-
}
|
|
1656
|
-
processUnixTimeSchema(type, name) {
|
|
1657
|
-
return this.codeModel.schemas.add(new UnixTimeSchema(name, this.getDoc(type), {
|
|
1658
|
-
summary: this.getSummary(type),
|
|
1496
|
+
processUnixTimeSchemaFromSdkType(type, name) {
|
|
1497
|
+
return this.codeModel.schemas.add(new UnixTimeSchema(name, this.getDoc(type.__raw), {
|
|
1498
|
+
summary: this.getSummary(type.__raw),
|
|
1659
1499
|
}));
|
|
1660
1500
|
}
|
|
1661
|
-
|
|
1662
|
-
return this.codeModel.schemas.add(new DateTimeSchema(name, this.getDoc(type), {
|
|
1663
|
-
summary: this.getSummary(type),
|
|
1501
|
+
processDateTimeSchemaFromSdkType(type, name, rfc1123) {
|
|
1502
|
+
return this.codeModel.schemas.add(new DateTimeSchema(name, this.getDoc(type.__raw), {
|
|
1503
|
+
summary: this.getSummary(type.__raw),
|
|
1664
1504
|
format: rfc1123 ? "date-time-rfc1123" : "date-time",
|
|
1665
1505
|
}));
|
|
1666
1506
|
}
|
|
1667
|
-
|
|
1668
|
-
return this.codeModel.schemas.add(new DateSchema(name, this.getDoc(type), {
|
|
1669
|
-
summary: this.getSummary(type),
|
|
1507
|
+
processDateSchemaFromSdkType(type, name) {
|
|
1508
|
+
return this.codeModel.schemas.add(new DateSchema(name, this.getDoc(type.__raw), {
|
|
1509
|
+
summary: this.getSummary(type.__raw),
|
|
1670
1510
|
}));
|
|
1671
1511
|
}
|
|
1672
|
-
|
|
1673
|
-
return this.codeModel.schemas.add(new TimeSchema(name, this.getDoc(type), {
|
|
1674
|
-
summary: this.getSummary(type),
|
|
1512
|
+
processTimeSchemaFromSdkType(type, name) {
|
|
1513
|
+
return this.codeModel.schemas.add(new TimeSchema(name, this.getDoc(type.__raw), {
|
|
1514
|
+
summary: this.getSummary(type.__raw),
|
|
1675
1515
|
}));
|
|
1676
1516
|
}
|
|
1677
|
-
|
|
1678
|
-
return this.codeModel.schemas.add(new DurationSchema(name, this.getDoc(type), {
|
|
1679
|
-
summary: this.getSummary(type),
|
|
1517
|
+
processDurationSchemaFromSdkType(type, name, format = "duration-rfc3339") {
|
|
1518
|
+
return this.codeModel.schemas.add(new DurationSchema(name, this.getDoc(type.__raw), {
|
|
1519
|
+
summary: this.getSummary(type.__raw),
|
|
1680
1520
|
format: format,
|
|
1681
1521
|
}));
|
|
1682
1522
|
}
|
|
1683
|
-
|
|
1684
|
-
return this.codeModel.schemas.add(new UriSchema(name, this.getDoc(type), {
|
|
1685
|
-
summary: this.getSummary(type),
|
|
1523
|
+
processUrlSchemaFromSdkType(type, name) {
|
|
1524
|
+
return this.codeModel.schemas.add(new UriSchema(name, this.getDoc(type.__raw), {
|
|
1525
|
+
summary: this.getSummary(type.__raw),
|
|
1686
1526
|
}));
|
|
1687
1527
|
}
|
|
1688
|
-
|
|
1689
|
-
var _a
|
|
1690
|
-
const
|
|
1691
|
-
const
|
|
1692
|
-
|
|
1528
|
+
processObjectSchemaFromSdkType(type, name) {
|
|
1529
|
+
var _a;
|
|
1530
|
+
const rawModelType = type.__raw;
|
|
1531
|
+
const namespace = getNamespace(rawModelType);
|
|
1532
|
+
const objectSchema = new ObjectScheme(name, this.getDoc(rawModelType), {
|
|
1533
|
+
summary: this.getSummary(rawModelType),
|
|
1693
1534
|
language: {
|
|
1694
1535
|
default: {
|
|
1695
1536
|
namespace: namespace,
|
|
@@ -1699,47 +1540,23 @@ export class CodeModelBuilder {
|
|
|
1699
1540
|
},
|
|
1700
1541
|
},
|
|
1701
1542
|
});
|
|
1702
|
-
objectSchema.crossLanguageDefinitionId =
|
|
1543
|
+
objectSchema.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1703
1544
|
this.codeModel.schemas.add(objectSchema);
|
|
1704
1545
|
// cache this now before we accidentally recurse on this type.
|
|
1705
1546
|
if (!this.schemaCache.has(type)) {
|
|
1706
1547
|
this.schemaCache.set(type, objectSchema);
|
|
1707
1548
|
}
|
|
1708
1549
|
// discriminator
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
// the property is required for getting its serializedName
|
|
1715
|
-
let discriminatorProperty = Array.from(type.properties.values()).find((it) => it.name === discriminatorPropertyName);
|
|
1716
|
-
if (!discriminatorProperty) {
|
|
1717
|
-
// try find the discriminator property from any of its derived models
|
|
1718
|
-
for (const deriveModel of type.derivedModels) {
|
|
1719
|
-
discriminatorProperty = Array.from(deriveModel.properties.values()).find((it) => it.name === discriminatorPropertyName);
|
|
1720
|
-
if (discriminatorProperty) {
|
|
1721
|
-
// found
|
|
1722
|
-
break;
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
if (discriminatorProperty) {
|
|
1727
|
-
objectSchema.discriminator = new Discriminator(this.processModelProperty(discriminatorProperty));
|
|
1728
|
-
objectSchema.discriminator.property.isDiscriminator = true;
|
|
1729
|
-
}
|
|
1730
|
-
else {
|
|
1731
|
-
// fallback to property name, if cannot find the discriminator property
|
|
1732
|
-
objectSchema.discriminator = new Discriminator(new Property(discriminatorPropertyName, discriminatorPropertyName, this.stringSchema, {
|
|
1733
|
-
isDiscriminator: true,
|
|
1734
|
-
required: true,
|
|
1735
|
-
serializedName: discriminatorPropertyName,
|
|
1736
|
-
}));
|
|
1550
|
+
if (type.discriminatedSubtypes && type.discriminatorProperty) {
|
|
1551
|
+
objectSchema.discriminator = new Discriminator(this.processModelPropertyFromSdkType(type.discriminatorProperty));
|
|
1552
|
+
for (const discriminatorValue in type.discriminatedSubtypes) {
|
|
1553
|
+
const subType = type.discriminatedSubtypes[discriminatorValue];
|
|
1554
|
+
this.processSchemaFromSdkType(subType, subType.name);
|
|
1737
1555
|
}
|
|
1738
|
-
objectSchema.discriminator.propertyName = discriminatorPropertyName;
|
|
1739
1556
|
}
|
|
1740
|
-
//
|
|
1557
|
+
// type is a subtype
|
|
1741
1558
|
if (type.baseModel) {
|
|
1742
|
-
const parentSchema = this.
|
|
1559
|
+
const parentSchema = this.processSchemaFromSdkType(type.baseModel, type.baseModel.name);
|
|
1743
1560
|
objectSchema.parents = new Relations();
|
|
1744
1561
|
objectSchema.parents.immediate.push(parentSchema);
|
|
1745
1562
|
if (parentSchema instanceof ObjectSchema) {
|
|
@@ -1756,69 +1573,34 @@ export class CodeModelBuilder {
|
|
|
1756
1573
|
});
|
|
1757
1574
|
}
|
|
1758
1575
|
}
|
|
1759
|
-
|
|
1760
|
-
// parentSchema could be DictionarySchema, which means the model is "additionalProperties"
|
|
1761
|
-
pushDistinct(objectSchema.parents.all, parentSchema);
|
|
1762
|
-
}
|
|
1576
|
+
objectSchema.discriminatorValue = type.discriminatorValue;
|
|
1763
1577
|
}
|
|
1764
|
-
|
|
1765
|
-
//
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
:
|
|
1775
|
-
|
|
1776
|
-
|
|
1578
|
+
if (type.additionalProperties) {
|
|
1579
|
+
// model has additional property
|
|
1580
|
+
const sdkDictType = {
|
|
1581
|
+
kind: "dict",
|
|
1582
|
+
keyType: {
|
|
1583
|
+
kind: "string",
|
|
1584
|
+
encode: "string",
|
|
1585
|
+
nullable: false,
|
|
1586
|
+
},
|
|
1587
|
+
description: type.description,
|
|
1588
|
+
nullableValues: false,
|
|
1589
|
+
nullable: false,
|
|
1590
|
+
valueType: type.additionalProperties,
|
|
1591
|
+
};
|
|
1592
|
+
const parentSchema = this.processSchemaFromSdkType(sdkDictType, "Record");
|
|
1593
|
+
objectSchema.parents = (_a = objectSchema.parents) !== null && _a !== void 0 ? _a : new Relations();
|
|
1777
1594
|
objectSchema.parents.immediate.push(parentSchema);
|
|
1778
1595
|
pushDistinct(objectSchema.parents.all, parentSchema);
|
|
1779
|
-
|
|
1780
|
-
// value of the discriminator property
|
|
1781
|
-
if (objectSchema.parents) {
|
|
1782
|
-
const parentWithDiscriminator = objectSchema.parents.all.find((it) => it instanceof ObjectSchema && it.discriminator);
|
|
1783
|
-
if (parentWithDiscriminator) {
|
|
1784
|
-
discriminatorPropertyName = parentWithDiscriminator.discriminator.propertyName;
|
|
1785
|
-
const discriminatorProperty = Array.from(type.properties.values()).find((it) => it.name === discriminatorPropertyName &&
|
|
1786
|
-
(it.type.kind === "String" || it.type.kind === "EnumMember" || it.type.kind === "UnionVariant"));
|
|
1787
|
-
if (discriminatorProperty) {
|
|
1788
|
-
if (discriminatorProperty.type.kind === "String") {
|
|
1789
|
-
// value as StringLiteral
|
|
1790
|
-
objectSchema.discriminatorValue = discriminatorProperty.type.value;
|
|
1791
|
-
}
|
|
1792
|
-
else if (discriminatorProperty.type.kind === "EnumMember") {
|
|
1793
|
-
// value as EnumMember
|
|
1794
|
-
// lint requires value be string
|
|
1795
|
-
objectSchema.discriminatorValue =
|
|
1796
|
-
(_a = discriminatorProperty.type.value) !== null && _a !== void 0 ? _a : discriminatorProperty.type.name;
|
|
1797
|
-
}
|
|
1798
|
-
else if (discriminatorProperty.type.kind === "UnionVariant") {
|
|
1799
|
-
// value as UnionVariant
|
|
1800
|
-
objectSchema.discriminatorValue =
|
|
1801
|
-
(_b = discriminatorProperty.type.type.value) !== null && _b !== void 0 ? _b : discriminatorProperty.type.name;
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
else {
|
|
1805
|
-
// it is possible that the property is Union, e.g. 'kind: "type1" | "type2"'; but such Type appears not to be a concrete model.
|
|
1806
|
-
// fallback to name of the Model
|
|
1807
|
-
objectSchema.discriminatorValue = name;
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1596
|
+
objectSchema.discriminatorValue = type.discriminatorValue;
|
|
1810
1597
|
}
|
|
1811
1598
|
// properties
|
|
1812
|
-
for (const prop of type.properties
|
|
1813
|
-
if (prop.
|
|
1814
|
-
|
|
1815
|
-
!isPayloadProperty(this.program, prop)) {
|
|
1816
|
-
continue;
|
|
1599
|
+
for (const prop of type.properties) {
|
|
1600
|
+
if (prop.kind === "property" && !prop.discriminator) {
|
|
1601
|
+
objectSchema.addProperty(this.processModelPropertyFromSdkType(prop));
|
|
1817
1602
|
}
|
|
1818
|
-
objectSchema.addProperty(this.processModelProperty(prop));
|
|
1819
1603
|
}
|
|
1820
|
-
// process all children
|
|
1821
|
-
(_c = type.derivedModels) === null || _c === void 0 ? void 0 : _c.filter(modelContainsDerivedModel).forEach((it) => this.processSchema(it, this.getName(it)));
|
|
1822
1604
|
return objectSchema;
|
|
1823
1605
|
}
|
|
1824
1606
|
getEffectiveSchemaType(type) {
|
|
@@ -1839,81 +1621,12 @@ export class CodeModelBuilder {
|
|
|
1839
1621
|
}
|
|
1840
1622
|
return type;
|
|
1841
1623
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
//
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
// };
|
|
1849
|
-
// if (Object.values(decorators).some((it) => it !== undefined)) {
|
|
1850
|
-
// schema = new StringSchema(schema.language.default.name, schema.language.default.description, {
|
|
1851
|
-
// language: schema.language,
|
|
1852
|
-
// summary: schema.summary,
|
|
1853
|
-
// extensions: schema.extensions,
|
|
1854
|
-
// ...decorators,
|
|
1855
|
-
// });
|
|
1856
|
-
// }
|
|
1857
|
-
// } else if (schema instanceof NumberSchema) {
|
|
1858
|
-
// const decorators = {
|
|
1859
|
-
// minimum: getMinValue(this.program, prop),
|
|
1860
|
-
// maximum: getMaxValue(this.program, prop),
|
|
1861
|
-
// };
|
|
1862
|
-
// if (Object.values(decorators).some((it) => it !== undefined)) {
|
|
1863
|
-
// schema = new NumberSchema(
|
|
1864
|
-
// schema.language.default.name,
|
|
1865
|
-
// schema.language.default.description,
|
|
1866
|
-
// schema.type,
|
|
1867
|
-
// schema.precision,
|
|
1868
|
-
// {
|
|
1869
|
-
// language: schema.language,
|
|
1870
|
-
// summary: schema.summary,
|
|
1871
|
-
// extensions: schema.extensions,
|
|
1872
|
-
// ...decorators,
|
|
1873
|
-
// },
|
|
1874
|
-
// );
|
|
1875
|
-
// }
|
|
1876
|
-
// }
|
|
1877
|
-
const format = getFormat(this.program, prop);
|
|
1878
|
-
if (format) {
|
|
1879
|
-
// TODO: deprecate format
|
|
1880
|
-
if (prop.type.kind === "Scalar" && schema instanceof StringSchema) {
|
|
1881
|
-
schema = this.processFormatString(prop.type, format, nameHint);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
else {
|
|
1885
|
-
// encode
|
|
1886
|
-
const encode = getEncode(this.program, prop);
|
|
1887
|
-
if (encode) {
|
|
1888
|
-
let type = prop.type;
|
|
1889
|
-
if (prop.type.kind === "Union" && isNullableType(prop.type)) {
|
|
1890
|
-
const nonNullVariants = Array.from(prop.type.variants.values()).filter((it) => !isNullType(it.type));
|
|
1891
|
-
type = nonNullVariants[0].type;
|
|
1892
|
-
}
|
|
1893
|
-
if (type && type.kind === "Scalar") {
|
|
1894
|
-
if (encode.encoding === "seconds" && hasScalarAsBase(type, "duration")) {
|
|
1895
|
-
schema = this.processDurationSchema(type, nameHint, getDurationFormat(encode));
|
|
1896
|
-
}
|
|
1897
|
-
else if ((encode.encoding === "rfc3339" || encode.encoding === "rfc7231" || encode.encoding === "unixTimestamp") &&
|
|
1898
|
-
(hasScalarAsBase(type, "utcDateTime") || hasScalarAsBase(type, "offsetDateTime"))) {
|
|
1899
|
-
if (encode.encoding === "unixTimestamp") {
|
|
1900
|
-
return this.processUnixTimeSchema(type, nameHint);
|
|
1901
|
-
}
|
|
1902
|
-
else {
|
|
1903
|
-
return this.processDateTimeSchema(type, nameHint, encode.encoding === "rfc7231");
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
else if (encode.encoding === "base64url" && hasScalarAsBase(type, "bytes")) {
|
|
1907
|
-
return this.processByteArraySchema(type, nameHint, true);
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
return schema;
|
|
1913
|
-
}
|
|
1914
|
-
processModelProperty(prop) {
|
|
1915
|
-
const schema = this.processSchema(prop, prop.name);
|
|
1916
|
-
let nullable = isNullableType(prop.type);
|
|
1624
|
+
processModelPropertyFromSdkType(prop) {
|
|
1625
|
+
const rawModelPropertyType = prop.__raw;
|
|
1626
|
+
// TODO: This case is related with literal.tsp, once TCGC supports giving a name, we can use TCGC generatedName
|
|
1627
|
+
const schemaNameHint = pascalCase(getNamePrefixForProperty(rawModelPropertyType)) + pascalCase(prop.name);
|
|
1628
|
+
let schema = this.processSchemaFromSdkType(prop.type, schemaNameHint);
|
|
1629
|
+
let nullable = prop.nullable;
|
|
1917
1630
|
let extensions = undefined;
|
|
1918
1631
|
if (this.isSecret(prop)) {
|
|
1919
1632
|
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
@@ -1921,66 +1634,43 @@ export class CodeModelBuilder {
|
|
|
1921
1634
|
// if the property does not return in response, it had to be nullable
|
|
1922
1635
|
nullable = true;
|
|
1923
1636
|
}
|
|
1924
|
-
if (
|
|
1637
|
+
if (prop.kind === "property" && prop.flatten) {
|
|
1925
1638
|
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
1926
1639
|
extensions["x-ms-client-flatten"] = true;
|
|
1927
1640
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1641
|
+
if (prop.kind === "property" && prop.isMultipartFileInput) {
|
|
1642
|
+
schema = this.processMultipartFormDataFilePropertySchemaFromSdkType(prop, this.namespace);
|
|
1643
|
+
}
|
|
1644
|
+
return new Property(prop.name, this.getDoc(rawModelPropertyType), schema, {
|
|
1645
|
+
summary: this.getSummary(rawModelPropertyType),
|
|
1930
1646
|
required: !prop.optional,
|
|
1931
1647
|
nullable: nullable,
|
|
1932
1648
|
readOnly: this.isReadOnly(prop),
|
|
1933
|
-
|
|
1934
|
-
serializedName: this.getSerializedName(prop),
|
|
1649
|
+
serializedName: prop.kind === "property" ? prop.serializedName : undefined,
|
|
1935
1650
|
extensions: extensions,
|
|
1936
1651
|
});
|
|
1937
1652
|
}
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
case "binary":
|
|
1943
|
-
return this.processByteArraySchema(type, nameHint, false);
|
|
1944
|
-
case "date-time":
|
|
1945
|
-
return this.processDateTimeSchema(type, nameHint, false);
|
|
1946
|
-
case "date-time-rfc1123":
|
|
1947
|
-
return this.processDateTimeSchema(type, nameHint, true);
|
|
1948
|
-
case "password":
|
|
1949
|
-
case "url":
|
|
1950
|
-
case "uuid":
|
|
1951
|
-
case "eTag":
|
|
1952
|
-
return this.processStringSchema(type, nameHint);
|
|
1953
|
-
default:
|
|
1954
|
-
this.logWarning(`Unrecognized string format: '${format}'.`);
|
|
1955
|
-
return this.processStringSchema(type, nameHint);
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
processUnionSchema(type, name) {
|
|
1959
|
-
const nonNullVariants = Array.from(type.variants.values()).filter((it) => !isNullType(it.type));
|
|
1960
|
-
if (nonNullVariants.length === 1) {
|
|
1961
|
-
// nullable
|
|
1962
|
-
return this.processSchema(nonNullVariants[0].type, name);
|
|
1963
|
-
}
|
|
1964
|
-
const unionEnum = ignoreDiagnostics(getUnionAsEnum(type));
|
|
1965
|
-
if (unionEnum) {
|
|
1966
|
-
// enum
|
|
1967
|
-
return this.processChoiceSchemaForUnion(type, unionEnum, name);
|
|
1653
|
+
processUnionSchemaFromSdkType(type, name) {
|
|
1654
|
+
var _a;
|
|
1655
|
+
if (!(type.__raw && type.__raw.kind === "Union")) {
|
|
1656
|
+
throw new Error(`Invalid type for union: '${type.kind}'.`);
|
|
1968
1657
|
}
|
|
1658
|
+
const rawUnionType = type.__raw;
|
|
1969
1659
|
// TODO: name from typespec-client-generator-core
|
|
1970
|
-
const namespace = getNamespace(
|
|
1971
|
-
const baseName = pascalCase(name) + "Model";
|
|
1972
|
-
this.logWarning(`Convert TypeSpec Union '${getUnionDescription(
|
|
1973
|
-
const unionSchema = new OrSchema(baseName + "Base", this.getDoc(
|
|
1974
|
-
summary: this.getSummary(
|
|
1660
|
+
const namespace = getNamespace(rawUnionType);
|
|
1661
|
+
const baseName = (_a = type.name) !== null && _a !== void 0 ? _a : pascalCase(name) + "Model";
|
|
1662
|
+
this.logWarning(`Convert TypeSpec Union '${getUnionDescription(rawUnionType, this.typeNameOptions)}' to Class '${baseName}'`);
|
|
1663
|
+
const unionSchema = new OrSchema(baseName + "Base", this.getDoc(rawUnionType), {
|
|
1664
|
+
summary: this.getSummary(rawUnionType),
|
|
1975
1665
|
});
|
|
1976
1666
|
unionSchema.anyOf = [];
|
|
1977
|
-
|
|
1978
|
-
const variantName = this.getUnionVariantName(it.
|
|
1667
|
+
type.values.forEach((it) => {
|
|
1668
|
+
const variantName = this.getUnionVariantName(it.__raw, { depth: 0 });
|
|
1979
1669
|
const modelName = variantName + baseName;
|
|
1980
1670
|
const propertyName = "value";
|
|
1981
1671
|
// these ObjectSchema is not added to codeModel.schemas
|
|
1982
|
-
const objectSchema = new ObjectSchema(modelName, this.getDoc(
|
|
1983
|
-
summary: this.getSummary(
|
|
1672
|
+
const objectSchema = new ObjectSchema(modelName, this.getDoc(rawUnionType), {
|
|
1673
|
+
summary: this.getSummary(rawUnionType),
|
|
1984
1674
|
language: {
|
|
1985
1675
|
default: {
|
|
1986
1676
|
namespace: namespace,
|
|
@@ -1990,11 +1680,10 @@ export class CodeModelBuilder {
|
|
|
1990
1680
|
},
|
|
1991
1681
|
},
|
|
1992
1682
|
});
|
|
1993
|
-
const variantSchema = this.
|
|
1994
|
-
objectSchema.addProperty(new Property(propertyName, this.getDoc(
|
|
1995
|
-
summary: this.getSummary(
|
|
1683
|
+
const variantSchema = this.processSchemaFromSdkType(it, variantName);
|
|
1684
|
+
objectSchema.addProperty(new Property(propertyName, this.getDoc(rawUnionType), variantSchema, {
|
|
1685
|
+
summary: this.getSummary(rawUnionType),
|
|
1996
1686
|
required: true,
|
|
1997
|
-
nullable: true,
|
|
1998
1687
|
readOnly: false,
|
|
1999
1688
|
}));
|
|
2000
1689
|
unionSchema.anyOf.push(objectSchema);
|
|
@@ -2008,6 +1697,9 @@ export class CodeModelBuilder {
|
|
|
2008
1697
|
}
|
|
2009
1698
|
getUnionVariantName(type, option) {
|
|
2010
1699
|
var _a;
|
|
1700
|
+
if (type === undefined) {
|
|
1701
|
+
throw new Error("type is undefined.");
|
|
1702
|
+
}
|
|
2011
1703
|
switch (type.kind) {
|
|
2012
1704
|
case "Scalar": {
|
|
2013
1705
|
const scalarName = type.name;
|
|
@@ -2062,40 +1754,26 @@ export class CodeModelBuilder {
|
|
|
2062
1754
|
throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
|
|
2063
1755
|
}
|
|
2064
1756
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
property.schema = getFileDetailsSchema(property.language.default.name, schema.language.default.namespace, this.codeModel.schemas, this.binarySchema, this.stringSchema);
|
|
2070
|
-
}
|
|
2071
|
-
else if (property.schema instanceof ArraySchema && property.schema.elementType instanceof ByteArraySchema) {
|
|
2072
|
-
property.schema = new ArraySchema(property.language.default.name, property.language.default.description, getFileDetailsSchema(property.language.default.name, schema.language.default.namespace, this.codeModel.schemas, this.binarySchema, this.stringSchema));
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
1757
|
+
processMultipartFormDataFilePropertySchemaFromSdkType(property, namespace) {
|
|
1758
|
+
var _a;
|
|
1759
|
+
if (property.type.kind === "bytes") {
|
|
1760
|
+
return getFileDetailsSchema(property.name, namespace, this.codeModel.schemas, this.binarySchema, this.stringSchema);
|
|
2075
1761
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
if (type) {
|
|
2079
|
-
switch (type.kind) {
|
|
2080
|
-
case "String":
|
|
2081
|
-
return type.value;
|
|
2082
|
-
case "Number":
|
|
2083
|
-
return type.value;
|
|
2084
|
-
case "Boolean":
|
|
2085
|
-
return type.value;
|
|
2086
|
-
// case "Tuple":
|
|
2087
|
-
// return type.values.map(getDefaultValue);
|
|
2088
|
-
}
|
|
1762
|
+
else if (property.type.kind === "array" && property.type.valueType.kind === "bytes") {
|
|
1763
|
+
return new ArraySchema(property.name, (_a = property.description) !== null && _a !== void 0 ? _a : "", getFileDetailsSchema(property.name, namespace, this.codeModel.schemas, this.binarySchema, this.stringSchema));
|
|
2089
1764
|
}
|
|
2090
|
-
|
|
1765
|
+
throw new Error(`Invalid type for multipart form data: '${property.type.kind}'.`);
|
|
2091
1766
|
}
|
|
2092
1767
|
getDoc(target) {
|
|
2093
|
-
return getDoc(this.program, target) || "";
|
|
1768
|
+
return target ? getDoc(this.program, target) || "" : "";
|
|
2094
1769
|
}
|
|
2095
1770
|
getSummary(target) {
|
|
2096
|
-
return getSummary(this.program, target);
|
|
1771
|
+
return target ? getSummary(this.program, target) : undefined;
|
|
2097
1772
|
}
|
|
2098
1773
|
getName(target, nameHint = undefined) {
|
|
1774
|
+
if (!target) {
|
|
1775
|
+
return nameHint || "";
|
|
1776
|
+
}
|
|
2099
1777
|
// TODO: once getLibraryName API in typespec-client-generator-core can get projected name from language and client, as well as can handle template case, use getLibraryName API
|
|
2100
1778
|
const emitterClientName = getClientNameOverride(this.sdkContext, target);
|
|
2101
1779
|
if (emitterClientName && typeof emitterClientName === "string") {
|
|
@@ -2139,13 +1817,12 @@ export class CodeModelBuilder {
|
|
|
2139
1817
|
return getWireName(this.sdkContext, target);
|
|
2140
1818
|
}
|
|
2141
1819
|
isReadOnly(target) {
|
|
2142
|
-
|
|
2143
|
-
const segment = getSegment(this.program, target) !== undefined;
|
|
1820
|
+
const segment = target.__raw ? getSegment(this.program, target.__raw) !== undefined : false;
|
|
2144
1821
|
if (segment) {
|
|
2145
1822
|
return true;
|
|
2146
1823
|
}
|
|
2147
1824
|
else {
|
|
2148
|
-
const visibility = getVisibility(this.program, target);
|
|
1825
|
+
const visibility = target.__raw ? getVisibility(this.program, target.__raw) : undefined;
|
|
2149
1826
|
if (visibility) {
|
|
2150
1827
|
return (!visibility.includes("write") &&
|
|
2151
1828
|
!visibility.includes("create") &&
|
|
@@ -2159,9 +1836,8 @@ export class CodeModelBuilder {
|
|
|
2159
1836
|
}
|
|
2160
1837
|
}
|
|
2161
1838
|
isSecret(target) {
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
return !visibility.includes("read");
|
|
1839
|
+
if (target.kind === "property" && target.visibility) {
|
|
1840
|
+
return !target.visibility.includes(Visibility.Read);
|
|
2165
1841
|
}
|
|
2166
1842
|
else {
|
|
2167
1843
|
return false;
|
|
@@ -2352,22 +2028,5 @@ export class CodeModelBuilder {
|
|
|
2352
2028
|
isArm() {
|
|
2353
2029
|
return Boolean(this.codeModel.arm);
|
|
2354
2030
|
}
|
|
2355
|
-
isSchemaUsageEmpty(schema) {
|
|
2356
|
-
if (schema instanceof ObjectSchema ||
|
|
2357
|
-
schema instanceof GroupSchema ||
|
|
2358
|
-
schema instanceof ChoiceSchema ||
|
|
2359
|
-
schema instanceof SealedChoiceSchema ||
|
|
2360
|
-
schema instanceof OrSchema ||
|
|
2361
|
-
schema instanceof ConstantSchema) {
|
|
2362
|
-
return !(schema.usage && schema.usage.length > 0);
|
|
2363
|
-
}
|
|
2364
|
-
else if (schema instanceof DictionarySchema) {
|
|
2365
|
-
return this.isSchemaUsageEmpty(schema.elementType);
|
|
2366
|
-
}
|
|
2367
|
-
else if (schema instanceof ArraySchema) {
|
|
2368
|
-
return this.isSchemaUsageEmpty(schema.elementType);
|
|
2369
|
-
}
|
|
2370
|
-
return false;
|
|
2371
|
-
}
|
|
2372
2031
|
}
|
|
2373
2032
|
//# sourceMappingURL=code-model-builder.js.map
|