@azure-tools/typespec-java 0.15.18 → 0.16.1
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 +29 -33
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +350 -645
- 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 +7 -1
- 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 +5 -5
- 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,158 @@ 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
|
-
|
|
1506
|
-
|
|
1403
|
+
processStringSchemaFromSdkType(type, name) {
|
|
1404
|
+
var _a;
|
|
1405
|
+
return this.codeModel.schemas.add(new StringSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1406
|
+
summary: type.description,
|
|
1507
1407
|
}));
|
|
1508
1408
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1409
|
+
processByteArraySchemaFromSdkType(type, name) {
|
|
1410
|
+
var _a;
|
|
1411
|
+
const base64Encoded = type.encode === "base64url";
|
|
1412
|
+
return this.codeModel.schemas.add(new ByteArraySchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1413
|
+
summary: type.description,
|
|
1512
1414
|
format: base64Encoded ? "base64url" : "byte",
|
|
1513
1415
|
}));
|
|
1514
1416
|
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1417
|
+
processIntegerSchemaFromSdkType(type, name, precision) {
|
|
1418
|
+
var _a;
|
|
1419
|
+
return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", SchemaType.Integer, precision, {
|
|
1420
|
+
summary: type.description,
|
|
1518
1421
|
}));
|
|
1519
1422
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1423
|
+
processNumberSchemaFromSdkType(type, name) {
|
|
1424
|
+
var _a;
|
|
1425
|
+
return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", SchemaType.Number, 64, {
|
|
1426
|
+
summary: type.description,
|
|
1523
1427
|
}));
|
|
1524
1428
|
}
|
|
1525
|
-
|
|
1429
|
+
processDecimalSchemaFromSdkType(type, name) {
|
|
1430
|
+
var _a;
|
|
1526
1431
|
// "Infinity" maps to "BigDecimal" in Java
|
|
1527
|
-
return this.codeModel.schemas.add(new NumberSchema(name,
|
|
1528
|
-
summary:
|
|
1432
|
+
return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", SchemaType.Number, Infinity, {
|
|
1433
|
+
summary: type.description,
|
|
1529
1434
|
}));
|
|
1530
1435
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1436
|
+
processBooleanSchemaFromSdkType(type, name) {
|
|
1437
|
+
var _a;
|
|
1438
|
+
return this.codeModel.schemas.add(new BooleanSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1439
|
+
summary: type.description,
|
|
1534
1440
|
}));
|
|
1535
1441
|
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1442
|
+
processArraySchemaFromSdkType(type, name) {
|
|
1443
|
+
var _a;
|
|
1444
|
+
const elementSchema = this.processSchemaFromSdkType(type.valueType, name);
|
|
1445
|
+
return this.codeModel.schemas.add(new ArraySchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", elementSchema, {
|
|
1446
|
+
summary: type.description,
|
|
1540
1447
|
}));
|
|
1541
1448
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1449
|
+
processDictionarySchemaFromSdkType(type, name) {
|
|
1450
|
+
var _a;
|
|
1451
|
+
const dictSchema = new DictionarySchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", null, {
|
|
1452
|
+
summary: type.description,
|
|
1545
1453
|
});
|
|
1546
1454
|
// cache this now before we accidentally recurse on this type.
|
|
1547
1455
|
if (!this.schemaCache.has(type)) {
|
|
1548
1456
|
this.schemaCache.set(type, dictSchema);
|
|
1549
1457
|
}
|
|
1550
|
-
const elementSchema = this.
|
|
1458
|
+
const elementSchema = this.processSchemaFromSdkType(type.valueType, name);
|
|
1551
1459
|
dictSchema.elementType = elementSchema;
|
|
1552
|
-
|
|
1553
|
-
dictSchema.nullableItems =
|
|
1554
|
-
Array.from(type.indexer.value.variants.values()).findIndex((it) => isNullType(it.type)) >= 0;
|
|
1555
|
-
}
|
|
1460
|
+
dictSchema.nullableItems = type.nullableValues;
|
|
1556
1461
|
return this.codeModel.schemas.add(dictSchema);
|
|
1557
1462
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
: this.doubleSchema
|
|
1564
|
-
: this.stringSchema;
|
|
1463
|
+
processChoiceSchemaFromSdkType(type, name) {
|
|
1464
|
+
var _a;
|
|
1465
|
+
const rawEnumType = type.__raw;
|
|
1466
|
+
const namespace = getNamespace(rawEnumType);
|
|
1467
|
+
const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind);
|
|
1565
1468
|
const choices = [];
|
|
1566
|
-
type.
|
|
1567
|
-
const schemaType =
|
|
1568
|
-
const schema = new schemaType(name,
|
|
1569
|
-
summary:
|
|
1469
|
+
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)); });
|
|
1470
|
+
const schemaType = type.isFixed ? SealedChoiceSchema : ChoiceSchema;
|
|
1471
|
+
const schema = new schemaType(type.name ? type.name : name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1472
|
+
summary: type.description,
|
|
1570
1473
|
choiceType: valueType,
|
|
1571
1474
|
choices: choices,
|
|
1572
1475
|
language: {
|
|
@@ -1578,118 +1481,71 @@ export class CodeModelBuilder {
|
|
|
1578
1481
|
},
|
|
1579
1482
|
},
|
|
1580
1483
|
});
|
|
1581
|
-
schema.crossLanguageDefinitionId =
|
|
1484
|
+
schema.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1582
1485
|
return this.codeModel.schemas.add(schema);
|
|
1583
1486
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
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),
|
|
1487
|
+
processConstantSchemaFromSdkType(type, name) {
|
|
1488
|
+
var _a;
|
|
1489
|
+
const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind);
|
|
1490
|
+
return this.codeModel.schemas.add(new ConstantSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1491
|
+
summary: type.description,
|
|
1594
1492
|
valueType: valueType,
|
|
1595
1493
|
value: new ConstantValue(type.value),
|
|
1596
1494
|
}));
|
|
1597
1495
|
}
|
|
1598
|
-
|
|
1599
|
-
var _a;
|
|
1600
|
-
const valueType = this.
|
|
1601
|
-
return this.codeModel.schemas.add(new ConstantSchema(name,
|
|
1602
|
-
summary:
|
|
1496
|
+
processConstantSchemaFromEnumValueFromSdkType(type, name) {
|
|
1497
|
+
var _a, _b;
|
|
1498
|
+
const valueType = this.processSchemaFromSdkType(type.enumType, type.enumType.name);
|
|
1499
|
+
return this.codeModel.schemas.add(new ConstantSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1500
|
+
summary: type.description,
|
|
1603
1501
|
valueType: valueType,
|
|
1604
|
-
value: new ConstantValue((
|
|
1502
|
+
value: new ConstantValue((_b = type.value) !== null && _b !== void 0 ? _b : type.name),
|
|
1605
1503
|
}));
|
|
1606
1504
|
}
|
|
1607
|
-
|
|
1505
|
+
processUnixTimeSchemaFromSdkType(type, name) {
|
|
1608
1506
|
var _a;
|
|
1609
|
-
|
|
1610
|
-
|
|
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),
|
|
1507
|
+
return this.codeModel.schemas.add(new UnixTimeSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1508
|
+
summary: type.description,
|
|
1659
1509
|
}));
|
|
1660
1510
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1511
|
+
processDateTimeSchemaFromSdkType(type, name, rfc1123) {
|
|
1512
|
+
var _a;
|
|
1513
|
+
return this.codeModel.schemas.add(new DateTimeSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1514
|
+
summary: type.description,
|
|
1664
1515
|
format: rfc1123 ? "date-time-rfc1123" : "date-time",
|
|
1665
1516
|
}));
|
|
1666
1517
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1518
|
+
processDateSchemaFromSdkType(type, name) {
|
|
1519
|
+
var _a;
|
|
1520
|
+
return this.codeModel.schemas.add(new DateSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1521
|
+
summary: type.description,
|
|
1670
1522
|
}));
|
|
1671
1523
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1524
|
+
processTimeSchemaFromSdkType(type, name) {
|
|
1525
|
+
var _a;
|
|
1526
|
+
return this.codeModel.schemas.add(new TimeSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1527
|
+
summary: type.description,
|
|
1675
1528
|
}));
|
|
1676
1529
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1530
|
+
processDurationSchemaFromSdkType(type, name, format = "duration-rfc3339") {
|
|
1531
|
+
var _a;
|
|
1532
|
+
return this.codeModel.schemas.add(new DurationSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1533
|
+
summary: type.description,
|
|
1680
1534
|
format: format,
|
|
1681
1535
|
}));
|
|
1682
1536
|
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1537
|
+
processUrlSchemaFromSdkType(type, name) {
|
|
1538
|
+
var _a;
|
|
1539
|
+
return this.codeModel.schemas.add(new UriSchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1540
|
+
summary: type.description,
|
|
1686
1541
|
}));
|
|
1687
1542
|
}
|
|
1688
|
-
|
|
1689
|
-
var _a, _b
|
|
1690
|
-
const
|
|
1691
|
-
const
|
|
1692
|
-
|
|
1543
|
+
processObjectSchemaFromSdkType(type, name) {
|
|
1544
|
+
var _a, _b;
|
|
1545
|
+
const rawModelType = type.__raw;
|
|
1546
|
+
const namespace = getNamespace(rawModelType);
|
|
1547
|
+
const objectSchema = new ObjectScheme(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", {
|
|
1548
|
+
summary: type.description,
|
|
1693
1549
|
language: {
|
|
1694
1550
|
default: {
|
|
1695
1551
|
namespace: namespace,
|
|
@@ -1699,47 +1555,23 @@ export class CodeModelBuilder {
|
|
|
1699
1555
|
},
|
|
1700
1556
|
},
|
|
1701
1557
|
});
|
|
1702
|
-
objectSchema.crossLanguageDefinitionId =
|
|
1558
|
+
objectSchema.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1703
1559
|
this.codeModel.schemas.add(objectSchema);
|
|
1704
1560
|
// cache this now before we accidentally recurse on this type.
|
|
1705
1561
|
if (!this.schemaCache.has(type)) {
|
|
1706
1562
|
this.schemaCache.set(type, objectSchema);
|
|
1707
1563
|
}
|
|
1708
1564
|
// 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
|
-
}));
|
|
1565
|
+
if (type.discriminatedSubtypes && type.discriminatorProperty) {
|
|
1566
|
+
objectSchema.discriminator = new Discriminator(this.processModelPropertyFromSdkType(type.discriminatorProperty));
|
|
1567
|
+
for (const discriminatorValue in type.discriminatedSubtypes) {
|
|
1568
|
+
const subType = type.discriminatedSubtypes[discriminatorValue];
|
|
1569
|
+
this.processSchemaFromSdkType(subType, subType.name);
|
|
1737
1570
|
}
|
|
1738
|
-
objectSchema.discriminator.propertyName = discriminatorPropertyName;
|
|
1739
1571
|
}
|
|
1740
|
-
//
|
|
1572
|
+
// type is a subtype
|
|
1741
1573
|
if (type.baseModel) {
|
|
1742
|
-
const parentSchema = this.
|
|
1574
|
+
const parentSchema = this.processSchemaFromSdkType(type.baseModel, type.baseModel.name);
|
|
1743
1575
|
objectSchema.parents = new Relations();
|
|
1744
1576
|
objectSchema.parents.immediate.push(parentSchema);
|
|
1745
1577
|
if (parentSchema instanceof ObjectSchema) {
|
|
@@ -1756,69 +1588,34 @@ export class CodeModelBuilder {
|
|
|
1756
1588
|
});
|
|
1757
1589
|
}
|
|
1758
1590
|
}
|
|
1759
|
-
|
|
1760
|
-
// parentSchema could be DictionarySchema, which means the model is "additionalProperties"
|
|
1761
|
-
pushDistinct(objectSchema.parents.all, parentSchema);
|
|
1762
|
-
}
|
|
1591
|
+
objectSchema.discriminatorValue = type.discriminatorValue;
|
|
1763
1592
|
}
|
|
1764
|
-
|
|
1765
|
-
//
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
:
|
|
1775
|
-
|
|
1776
|
-
|
|
1593
|
+
if (type.additionalProperties) {
|
|
1594
|
+
// model has additional property
|
|
1595
|
+
const sdkDictType = {
|
|
1596
|
+
kind: "dict",
|
|
1597
|
+
keyType: {
|
|
1598
|
+
kind: "string",
|
|
1599
|
+
encode: "string",
|
|
1600
|
+
nullable: false,
|
|
1601
|
+
},
|
|
1602
|
+
description: type.description,
|
|
1603
|
+
nullableValues: false,
|
|
1604
|
+
nullable: false,
|
|
1605
|
+
valueType: type.additionalProperties,
|
|
1606
|
+
};
|
|
1607
|
+
const parentSchema = this.processSchemaFromSdkType(sdkDictType, "Record");
|
|
1608
|
+
objectSchema.parents = (_b = objectSchema.parents) !== null && _b !== void 0 ? _b : new Relations();
|
|
1777
1609
|
objectSchema.parents.immediate.push(parentSchema);
|
|
1778
1610
|
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
|
-
}
|
|
1611
|
+
objectSchema.discriminatorValue = type.discriminatorValue;
|
|
1810
1612
|
}
|
|
1811
1613
|
// properties
|
|
1812
|
-
for (const prop of type.properties
|
|
1813
|
-
if (prop.
|
|
1814
|
-
|
|
1815
|
-
!isPayloadProperty(this.program, prop)) {
|
|
1816
|
-
continue;
|
|
1614
|
+
for (const prop of type.properties) {
|
|
1615
|
+
if (prop.kind === "property" && !prop.discriminator) {
|
|
1616
|
+
objectSchema.addProperty(this.processModelPropertyFromSdkType(prop));
|
|
1817
1617
|
}
|
|
1818
|
-
objectSchema.addProperty(this.processModelProperty(prop));
|
|
1819
1618
|
}
|
|
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
1619
|
return objectSchema;
|
|
1823
1620
|
}
|
|
1824
1621
|
getEffectiveSchemaType(type) {
|
|
@@ -1839,81 +1636,13 @@ export class CodeModelBuilder {
|
|
|
1839
1636
|
}
|
|
1840
1637
|
return type;
|
|
1841
1638
|
}
|
|
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);
|
|
1639
|
+
processModelPropertyFromSdkType(prop) {
|
|
1640
|
+
var _a;
|
|
1641
|
+
const rawModelPropertyType = prop.__raw;
|
|
1642
|
+
// TODO: This case is related with literal.tsp, once TCGC supports giving a name, we can use TCGC generatedName
|
|
1643
|
+
const schemaNameHint = pascalCase(getNamePrefixForProperty(rawModelPropertyType)) + pascalCase(prop.name);
|
|
1644
|
+
let schema = this.processSchemaFromSdkType(prop.type, schemaNameHint);
|
|
1645
|
+
let nullable = prop.nullable;
|
|
1917
1646
|
let extensions = undefined;
|
|
1918
1647
|
if (this.isSecret(prop)) {
|
|
1919
1648
|
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
@@ -1921,66 +1650,49 @@ export class CodeModelBuilder {
|
|
|
1921
1650
|
// if the property does not return in response, it had to be nullable
|
|
1922
1651
|
nullable = true;
|
|
1923
1652
|
}
|
|
1924
|
-
if (
|
|
1653
|
+
if (prop.kind === "property" && prop.flatten) {
|
|
1925
1654
|
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
1926
1655
|
extensions["x-ms-client-flatten"] = true;
|
|
1927
1656
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1657
|
+
const mutability = this.getMutability(prop);
|
|
1658
|
+
if (mutability) {
|
|
1659
|
+
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
1660
|
+
extensions["x-ms-mutability"] = mutability;
|
|
1661
|
+
}
|
|
1662
|
+
if (prop.kind === "property" && prop.isMultipartFileInput) {
|
|
1663
|
+
schema = this.processMultipartFormDataFilePropertySchemaFromSdkType(prop, this.namespace);
|
|
1664
|
+
}
|
|
1665
|
+
return new Property(prop.name, (_a = prop.details) !== null && _a !== void 0 ? _a : "", schema, {
|
|
1666
|
+
summary: prop.description,
|
|
1930
1667
|
required: !prop.optional,
|
|
1931
1668
|
nullable: nullable,
|
|
1932
1669
|
readOnly: this.isReadOnly(prop),
|
|
1933
|
-
|
|
1934
|
-
serializedName: this.getSerializedName(prop),
|
|
1670
|
+
serializedName: prop.kind === "property" ? prop.serializedName : undefined,
|
|
1935
1671
|
extensions: extensions,
|
|
1936
1672
|
});
|
|
1937
1673
|
}
|
|
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);
|
|
1674
|
+
processUnionSchemaFromSdkType(type, name) {
|
|
1675
|
+
var _a, _b;
|
|
1676
|
+
if (!(type.__raw && type.__raw.kind === "Union")) {
|
|
1677
|
+
throw new Error(`Invalid type for union: '${type.kind}'.`);
|
|
1968
1678
|
}
|
|
1679
|
+
const rawUnionType = type.__raw;
|
|
1969
1680
|
// 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",
|
|
1974
|
-
summary:
|
|
1681
|
+
const namespace = getNamespace(rawUnionType);
|
|
1682
|
+
const baseName = (_a = type.name) !== null && _a !== void 0 ? _a : pascalCase(name) + "Model";
|
|
1683
|
+
this.logWarning(`Convert TypeSpec Union '${getUnionDescription(rawUnionType, this.typeNameOptions)}' to Class '${baseName}'`);
|
|
1684
|
+
const unionSchema = new OrSchema(baseName + "Base", (_b = type.details) !== null && _b !== void 0 ? _b : "", {
|
|
1685
|
+
summary: type.description,
|
|
1975
1686
|
});
|
|
1976
1687
|
unionSchema.anyOf = [];
|
|
1977
|
-
|
|
1978
|
-
|
|
1688
|
+
type.values.forEach((it) => {
|
|
1689
|
+
var _a, _b;
|
|
1690
|
+
const variantName = this.getUnionVariantName(it.__raw, { depth: 0 });
|
|
1979
1691
|
const modelName = variantName + baseName;
|
|
1980
1692
|
const propertyName = "value";
|
|
1981
1693
|
// these ObjectSchema is not added to codeModel.schemas
|
|
1982
|
-
const objectSchema = new ObjectSchema(modelName,
|
|
1983
|
-
summary:
|
|
1694
|
+
const objectSchema = new ObjectSchema(modelName, (_a = it.details) !== null && _a !== void 0 ? _a : "", {
|
|
1695
|
+
summary: it.description,
|
|
1984
1696
|
language: {
|
|
1985
1697
|
default: {
|
|
1986
1698
|
namespace: namespace,
|
|
@@ -1990,11 +1702,10 @@ export class CodeModelBuilder {
|
|
|
1990
1702
|
},
|
|
1991
1703
|
},
|
|
1992
1704
|
});
|
|
1993
|
-
const variantSchema = this.
|
|
1994
|
-
objectSchema.addProperty(new Property(propertyName,
|
|
1995
|
-
summary:
|
|
1705
|
+
const variantSchema = this.processSchemaFromSdkType(it, variantName);
|
|
1706
|
+
objectSchema.addProperty(new Property(propertyName, (_b = type.details) !== null && _b !== void 0 ? _b : "", variantSchema, {
|
|
1707
|
+
summary: type.description,
|
|
1996
1708
|
required: true,
|
|
1997
|
-
nullable: true,
|
|
1998
1709
|
readOnly: false,
|
|
1999
1710
|
}));
|
|
2000
1711
|
unionSchema.anyOf.push(objectSchema);
|
|
@@ -2008,6 +1719,9 @@ export class CodeModelBuilder {
|
|
|
2008
1719
|
}
|
|
2009
1720
|
getUnionVariantName(type, option) {
|
|
2010
1721
|
var _a;
|
|
1722
|
+
if (type === undefined) {
|
|
1723
|
+
throw new Error("type is undefined.");
|
|
1724
|
+
}
|
|
2011
1725
|
switch (type.kind) {
|
|
2012
1726
|
case "Scalar": {
|
|
2013
1727
|
const scalarName = type.name;
|
|
@@ -2062,40 +1776,26 @@ export class CodeModelBuilder {
|
|
|
2062
1776
|
throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
|
|
2063
1777
|
}
|
|
2064
1778
|
}
|
|
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
|
-
}
|
|
1779
|
+
processMultipartFormDataFilePropertySchemaFromSdkType(property, namespace) {
|
|
1780
|
+
var _a;
|
|
1781
|
+
if (property.type.kind === "bytes") {
|
|
1782
|
+
return getFileDetailsSchema(property.name, namespace, this.codeModel.schemas, this.binarySchema, this.stringSchema);
|
|
2075
1783
|
}
|
|
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
|
-
}
|
|
1784
|
+
else if (property.type.kind === "array" && property.type.valueType.kind === "bytes") {
|
|
1785
|
+
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
1786
|
}
|
|
2090
|
-
|
|
1787
|
+
throw new Error(`Invalid type for multipart form data: '${property.type.kind}'.`);
|
|
2091
1788
|
}
|
|
2092
1789
|
getDoc(target) {
|
|
2093
|
-
return getDoc(this.program, target) || "";
|
|
1790
|
+
return target ? getDoc(this.program, target) || "" : "";
|
|
2094
1791
|
}
|
|
2095
1792
|
getSummary(target) {
|
|
2096
|
-
return getSummary(this.program, target);
|
|
1793
|
+
return target ? getSummary(this.program, target) : undefined;
|
|
2097
1794
|
}
|
|
2098
1795
|
getName(target, nameHint = undefined) {
|
|
1796
|
+
if (!target) {
|
|
1797
|
+
return nameHint || "";
|
|
1798
|
+
}
|
|
2099
1799
|
// 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
1800
|
const emitterClientName = getClientNameOverride(this.sdkContext, target);
|
|
2101
1801
|
if (emitterClientName && typeof emitterClientName === "string") {
|
|
@@ -2139,13 +1839,12 @@ export class CodeModelBuilder {
|
|
|
2139
1839
|
return getWireName(this.sdkContext, target);
|
|
2140
1840
|
}
|
|
2141
1841
|
isReadOnly(target) {
|
|
2142
|
-
|
|
2143
|
-
const segment = getSegment(this.program, target) !== undefined;
|
|
1842
|
+
const segment = target.__raw ? getSegment(this.program, target.__raw) !== undefined : false;
|
|
2144
1843
|
if (segment) {
|
|
2145
1844
|
return true;
|
|
2146
1845
|
}
|
|
2147
1846
|
else {
|
|
2148
|
-
const visibility = getVisibility(this.program, target);
|
|
1847
|
+
const visibility = target.__raw ? getVisibility(this.program, target.__raw) : undefined;
|
|
2149
1848
|
if (visibility) {
|
|
2150
1849
|
return (!visibility.includes("write") &&
|
|
2151
1850
|
!visibility.includes("create") &&
|
|
@@ -2159,14 +1858,37 @@ export class CodeModelBuilder {
|
|
|
2159
1858
|
}
|
|
2160
1859
|
}
|
|
2161
1860
|
isSecret(target) {
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
return !visibility.includes("read");
|
|
1861
|
+
if (target.kind === "property" && target.visibility) {
|
|
1862
|
+
return !target.visibility.includes(Visibility.Read);
|
|
2165
1863
|
}
|
|
2166
1864
|
else {
|
|
2167
1865
|
return false;
|
|
2168
1866
|
}
|
|
2169
1867
|
}
|
|
1868
|
+
getMutability(target) {
|
|
1869
|
+
if (target.kind === "property" && target.visibility) {
|
|
1870
|
+
const mutability = [];
|
|
1871
|
+
if (target.visibility.includes(Visibility.Create)) {
|
|
1872
|
+
mutability.push("create");
|
|
1873
|
+
}
|
|
1874
|
+
if (target.visibility.includes(Visibility.Update)) {
|
|
1875
|
+
mutability.push("update");
|
|
1876
|
+
}
|
|
1877
|
+
if (target.visibility.includes(Visibility.Read)) {
|
|
1878
|
+
mutability.push("read");
|
|
1879
|
+
}
|
|
1880
|
+
if (mutability.length === 3) {
|
|
1881
|
+
// if all 3 (supported) mutability values are present, there is no need to set the x-ms-mutability
|
|
1882
|
+
return undefined;
|
|
1883
|
+
}
|
|
1884
|
+
else {
|
|
1885
|
+
return mutability;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
else {
|
|
1889
|
+
return undefined;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
2170
1892
|
getConvenienceApiName(op) {
|
|
2171
1893
|
// check @convenienceMethod
|
|
2172
1894
|
if (shouldGenerateConvenient(this.sdkContext, op)) {
|
|
@@ -2352,22 +2074,5 @@ export class CodeModelBuilder {
|
|
|
2352
2074
|
isArm() {
|
|
2353
2075
|
return Boolean(this.codeModel.arm);
|
|
2354
2076
|
}
|
|
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
2077
|
}
|
|
2373
2078
|
//# sourceMappingURL=code-model-builder.js.map
|