@azure-tools/typespec-java 0.20.2 → 0.21.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 +26 -26
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +170 -159
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/models.d.ts +0 -2
- package/dist/src/models.d.ts.map +1 -1
- package/dist/src/models.js +2 -29
- package/dist/src/models.js.map +1 -1
- package/dist/src/type-utils.d.ts +5 -5
- package/dist/src/type-utils.d.ts.map +1 -1
- package/dist/src/type-utils.js +32 -8
- package/dist/src/type-utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/generator/http-client-generator/target/emitter.jar +0 -0
- package/package.json +27 -27
- package/readme.md +2 -2
|
@@ -19,14 +19,14 @@ import { SchemaContext } from "./common/schemas/usage.js";
|
|
|
19
19
|
import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./external-schemas.js";
|
|
20
20
|
import { ClientContext } from "./models.js";
|
|
21
21
|
import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, getServiceVersion, isKnownContentType, isLroNewPollingStrategy, isPayloadProperty, operationIsJsonMergePatch, operationIsMultipart, operationIsMultipleContentTypes, } from "./operation-utils.js";
|
|
22
|
-
import { ProcessingCache, getAccess,
|
|
22
|
+
import { ProcessingCache, getAccess, getDurationFormat, getNonNullSdkType, getUnionDescription, getUsage, isStable, modelIs, pushDistinct, } from "./type-utils.js";
|
|
23
23
|
import { getNamespace, logWarning, pascalCase, removeClientSuffix, stringArrayContainsIgnoreCase, trace, } from "./utils.js";
|
|
24
24
|
const { isEqual } = pkg;
|
|
25
25
|
export class CodeModelBuilder {
|
|
26
26
|
constructor(program1, context) {
|
|
27
27
|
var _a, _b;
|
|
28
28
|
this.loggingEnabled = false;
|
|
29
|
-
this.schemaCache = new ProcessingCache((type, name) => this.
|
|
29
|
+
this.schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
|
|
30
30
|
this.typeUnionRefCache = new Map(); // Union means it ref a Union type, null means it does not ref any Union, undefined means type visited but not completed
|
|
31
31
|
this.options = context.options;
|
|
32
32
|
this.program = program1;
|
|
@@ -103,11 +103,11 @@ export class CodeModelBuilder {
|
|
|
103
103
|
parameter = this.createApiVersionParameter(arg.name, ParameterLocation.Uri);
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
|
-
const schema = this.
|
|
106
|
+
const schema = this.processSchema(arg.type, arg.name);
|
|
107
107
|
this.trackSchemaUsage(schema, {
|
|
108
108
|
usage: [SchemaContext.Input, SchemaContext.Output /*SchemaContext.Public*/],
|
|
109
109
|
});
|
|
110
|
-
parameter = new Parameter(arg.name, (_a = arg.
|
|
110
|
+
parameter = new Parameter(arg.name, (_a = arg.doc) !== null && _a !== void 0 ? _a : "", schema, {
|
|
111
111
|
implementation: ImplementationLocation.Client,
|
|
112
112
|
origin: "modelerfour:synthesized/host",
|
|
113
113
|
required: true,
|
|
@@ -160,7 +160,7 @@ export class CodeModelBuilder {
|
|
|
160
160
|
schemeOrApiKeyPrefix = pascalCase(schemeOrApiKeyPrefix);
|
|
161
161
|
if (this.isBranded()) {
|
|
162
162
|
// Azure would not allow BasicAuth or BearerAuth
|
|
163
|
-
this.logWarning(
|
|
163
|
+
this.logWarning(`${scheme.scheme} auth method is currently not supported.`);
|
|
164
164
|
continue;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -185,30 +185,31 @@ export class CodeModelBuilder {
|
|
|
185
185
|
}
|
|
186
186
|
processModels() {
|
|
187
187
|
const processedSdkModels = new Set();
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
};
|
|
188
|
+
// cache resolved value of access/usage for the namespace
|
|
189
|
+
// the value can be set as undefined
|
|
190
|
+
// it resolves the value from that namespace and its parent namespaces
|
|
191
|
+
const accessCache = new Map();
|
|
192
|
+
const usageCache = new Map();
|
|
195
193
|
const sdkModels = getAllModels(this.sdkContext);
|
|
196
194
|
// process sdk models
|
|
197
195
|
for (const model of sdkModels) {
|
|
198
196
|
if (!processedSdkModels.has(model)) {
|
|
199
|
-
const access = getAccess(model.__raw);
|
|
197
|
+
const access = getAccess(model.__raw, accessCache);
|
|
200
198
|
if (access === "public") {
|
|
201
|
-
|
|
199
|
+
const schema = this.processSchema(model, "");
|
|
200
|
+
this.trackSchemaUsage(schema, {
|
|
201
|
+
usage: [SchemaContext.Public],
|
|
202
|
+
});
|
|
202
203
|
}
|
|
203
204
|
else if (access === "internal") {
|
|
204
|
-
const schema = this.
|
|
205
|
+
const schema = this.processSchema(model, model.name);
|
|
205
206
|
this.trackSchemaUsage(schema, {
|
|
206
207
|
usage: [SchemaContext.Internal],
|
|
207
208
|
});
|
|
208
209
|
}
|
|
209
|
-
const usage = getUsage(model.__raw);
|
|
210
|
+
const usage = getUsage(model.__raw, usageCache);
|
|
210
211
|
if (usage) {
|
|
211
|
-
const schema = this.
|
|
212
|
+
const schema = this.processSchema(model, "");
|
|
212
213
|
this.trackSchemaUsage(schema, {
|
|
213
214
|
usage: usage,
|
|
214
215
|
});
|
|
@@ -298,8 +299,8 @@ export class CodeModelBuilder {
|
|
|
298
299
|
const clientSubNamespace = clientNameSegments.slice(0, -1).join(".");
|
|
299
300
|
javaNamespace = this.getJavaNamespace(this.namespace + "." + clientSubNamespace);
|
|
300
301
|
}
|
|
301
|
-
const codeModelClient = new CodeModelClient(clientName, (_b = client.
|
|
302
|
-
summary: client.
|
|
302
|
+
const codeModelClient = new CodeModelClient(clientName, (_b = client.doc) !== null && _b !== void 0 ? _b : "", {
|
|
303
|
+
summary: client.summary,
|
|
303
304
|
language: {
|
|
304
305
|
default: {
|
|
305
306
|
namespace: this.namespace,
|
|
@@ -338,16 +339,16 @@ export class CodeModelBuilder {
|
|
|
338
339
|
if (initializationProperty.kind === "endpoint") {
|
|
339
340
|
let sdkPathParameters = [];
|
|
340
341
|
if (initializationProperty.type.kind === "union") {
|
|
341
|
-
if (initializationProperty.type.
|
|
342
|
+
if (initializationProperty.type.variantTypes.length === 2) {
|
|
342
343
|
// only get the sdkPathParameters from the endpoint whose serverUrl is not {"endpoint"}
|
|
343
|
-
for (const endpointType of initializationProperty.type.
|
|
344
|
+
for (const endpointType of initializationProperty.type.variantTypes) {
|
|
344
345
|
if (endpointType.kind === "endpoint" && endpointType.serverUrl !== "{endpoint}") {
|
|
345
346
|
sdkPathParameters = endpointType.templateArguments;
|
|
346
347
|
baseUri = endpointType.serverUrl;
|
|
347
348
|
}
|
|
348
349
|
}
|
|
349
350
|
}
|
|
350
|
-
else if (initializationProperty.type.
|
|
351
|
+
else if (initializationProperty.type.variantTypes.length > 2) {
|
|
351
352
|
throw new Error("Multiple server url defined for one client is not supported yet.");
|
|
352
353
|
}
|
|
353
354
|
}
|
|
@@ -512,9 +513,9 @@ export class CodeModelBuilder {
|
|
|
512
513
|
const operationId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
|
|
513
514
|
const operationGroup = this.codeModel.getOperationGroup(groupName);
|
|
514
515
|
const operationExamples = this.getOperationExample(sdkMethod);
|
|
515
|
-
const codeModelOperation = new CodeModelOperation(operationName, (_a = sdkMethod.
|
|
516
|
+
const codeModelOperation = new CodeModelOperation(operationName, (_a = sdkMethod.doc) !== null && _a !== void 0 ? _a : "", {
|
|
516
517
|
operationId: operationId,
|
|
517
|
-
summary: sdkMethod.
|
|
518
|
+
summary: sdkMethod.summary,
|
|
518
519
|
extensions: {
|
|
519
520
|
"x-ms-examples": operationExamples,
|
|
520
521
|
},
|
|
@@ -602,24 +603,24 @@ export class CodeModelBuilder {
|
|
|
602
603
|
lroMetadata = this.processLroMetadata(codeModelOperation, sdkMethod);
|
|
603
604
|
}
|
|
604
605
|
// responses
|
|
605
|
-
for (const
|
|
606
|
-
this.processResponse(codeModelOperation,
|
|
606
|
+
for (const response of sdkMethod.operation.responses) {
|
|
607
|
+
this.processResponse(codeModelOperation, response.statusCodes, response, lroMetadata.longRunning, false);
|
|
607
608
|
}
|
|
608
609
|
// exception
|
|
609
|
-
for (const
|
|
610
|
-
this.processResponse(codeModelOperation,
|
|
610
|
+
for (const response of sdkMethod.operation.exceptions) {
|
|
611
|
+
this.processResponse(codeModelOperation, response.statusCodes, response, lroMetadata.longRunning, true);
|
|
611
612
|
}
|
|
612
613
|
// check for paged
|
|
613
614
|
this.processRouteForPaged(codeModelOperation, sdkMethod.operation.responses, sdkMethod);
|
|
614
615
|
// check for long-running operation
|
|
615
|
-
this.processRouteForLongRunning(codeModelOperation,
|
|
616
|
+
this.processRouteForLongRunning(codeModelOperation, lroMetadata);
|
|
616
617
|
operationGroup.addOperation(codeModelOperation);
|
|
617
618
|
return codeModelOperation;
|
|
618
619
|
}
|
|
619
620
|
processRouteForPaged(op, responses, sdkMethod) {
|
|
620
621
|
var _a, _b;
|
|
621
622
|
if (sdkMethod.kind === "paging" || sdkMethod.kind === "lropaging") {
|
|
622
|
-
for (const
|
|
623
|
+
for (const response of responses) {
|
|
623
624
|
const bodyType = response.type;
|
|
624
625
|
if (bodyType && bodyType.kind === "model") {
|
|
625
626
|
const itemName = sdkMethod.response.resultPath;
|
|
@@ -670,7 +671,7 @@ export class CodeModelBuilder {
|
|
|
670
671
|
else {
|
|
671
672
|
const pollType = this.findResponseBody(lroMetadata.pollingInfo.responseModel);
|
|
672
673
|
const sdkType = getClientType(this.sdkContext, pollType);
|
|
673
|
-
pollingSchema = this.
|
|
674
|
+
pollingSchema = this.processSchema(sdkType, "pollResult");
|
|
674
675
|
}
|
|
675
676
|
// finalSchema
|
|
676
677
|
if (verb !== "delete" &&
|
|
@@ -683,7 +684,7 @@ export class CodeModelBuilder {
|
|
|
683
684
|
: lroMetadata.finalEnvelopeResult;
|
|
684
685
|
const finalType = this.findResponseBody(finalResult);
|
|
685
686
|
const sdkType = getClientType(this.sdkContext, finalType);
|
|
686
|
-
finalSchema = this.
|
|
687
|
+
finalSchema = this.processSchema(sdkType, "finalResult");
|
|
687
688
|
if (useNewPollStrategy &&
|
|
688
689
|
lroMetadata.finalStep &&
|
|
689
690
|
lroMetadata.finalStep.kind === "pollingSuccessProperty" &&
|
|
@@ -714,7 +715,7 @@ export class CodeModelBuilder {
|
|
|
714
715
|
}
|
|
715
716
|
return new LongRunningMetadata(false);
|
|
716
717
|
}
|
|
717
|
-
processRouteForLongRunning(op,
|
|
718
|
+
processRouteForLongRunning(op, lroMetadata) {
|
|
718
719
|
var _a;
|
|
719
720
|
if (lroMetadata.longRunning) {
|
|
720
721
|
op.extensions = (_a = op.extensions) !== null && _a !== void 0 ? _a : {};
|
|
@@ -758,7 +759,7 @@ export class CodeModelBuilder {
|
|
|
758
759
|
else {
|
|
759
760
|
// schema
|
|
760
761
|
const sdkType = getNonNullSdkType(param.type);
|
|
761
|
-
const schema = this.
|
|
762
|
+
const schema = this.processSchema(sdkType, param.name);
|
|
762
763
|
let extensions = undefined;
|
|
763
764
|
if (param.kind === "path") {
|
|
764
765
|
if (param.allowReserved) {
|
|
@@ -826,10 +827,17 @@ export class CodeModelBuilder {
|
|
|
826
827
|
}
|
|
827
828
|
}
|
|
828
829
|
}
|
|
830
|
+
// TODO: use param.onClient after TCGC fix
|
|
831
|
+
const parameterOnClient = !isApiVersion(this.sdkContext, param) &&
|
|
832
|
+
param.correspondingMethodParams &&
|
|
833
|
+
param.correspondingMethodParams.length > 0 &&
|
|
834
|
+
param.correspondingMethodParams[0].onClient;
|
|
829
835
|
const nullable = param.type.kind === "nullable";
|
|
830
|
-
const parameter = new Parameter(param.name, (_b = param.
|
|
831
|
-
summary: param.
|
|
832
|
-
implementation:
|
|
836
|
+
const parameter = new Parameter(param.name, (_b = param.doc) !== null && _b !== void 0 ? _b : "", schema, {
|
|
837
|
+
summary: param.summary,
|
|
838
|
+
implementation: parameterOnClient
|
|
839
|
+
? ImplementationLocation.Client
|
|
840
|
+
: ImplementationLocation.Method,
|
|
833
841
|
required: !param.optional,
|
|
834
842
|
nullable: nullable,
|
|
835
843
|
protocol: {
|
|
@@ -846,6 +854,9 @@ export class CodeModelBuilder {
|
|
|
846
854
|
extensions: extensions,
|
|
847
855
|
});
|
|
848
856
|
op.addParameter(parameter);
|
|
857
|
+
if (parameterOnClient) {
|
|
858
|
+
clientContext.addGlobalParameter(parameter);
|
|
859
|
+
}
|
|
849
860
|
this.trackSchemaUsage(schema, { usage: [SchemaContext.Input] });
|
|
850
861
|
if (op.convenienceApi) {
|
|
851
862
|
this.trackSchemaUsage(schema, {
|
|
@@ -967,14 +978,14 @@ export class CodeModelBuilder {
|
|
|
967
978
|
let schema;
|
|
968
979
|
if (unknownRequestBody && sdkType.kind === "bytes") {
|
|
969
980
|
// if it's unknown request body, handle binary request body
|
|
970
|
-
schema = this.
|
|
981
|
+
schema = this.processBinarySchema(sdkType);
|
|
971
982
|
}
|
|
972
983
|
else {
|
|
973
|
-
schema = this.
|
|
984
|
+
schema = this.processSchema(getNonNullSdkType(sdkType), sdkBody.name);
|
|
974
985
|
}
|
|
975
986
|
const parameterName = sdkBody.name;
|
|
976
|
-
const parameter = new Parameter(parameterName, (_a = sdkBody.
|
|
977
|
-
summary: sdkBody.
|
|
987
|
+
const parameter = new Parameter(parameterName, (_a = sdkBody.doc) !== null && _a !== void 0 ? _a : "", schema, {
|
|
988
|
+
summary: sdkBody.summary,
|
|
978
989
|
implementation: ImplementationLocation.Method,
|
|
979
990
|
required: !sdkBody.optional,
|
|
980
991
|
protocol: {
|
|
@@ -1153,12 +1164,12 @@ export class CodeModelBuilder {
|
|
|
1153
1164
|
headers = [];
|
|
1154
1165
|
if (sdkResponse.headers) {
|
|
1155
1166
|
for (const header of sdkResponse.headers) {
|
|
1156
|
-
const schema = this.
|
|
1167
|
+
const schema = this.processSchema(header.type, header.serializedName);
|
|
1157
1168
|
headers.push(new HttpHeader(header.serializedName, schema, {
|
|
1158
1169
|
language: {
|
|
1159
1170
|
default: {
|
|
1160
1171
|
name: header.serializedName,
|
|
1161
|
-
description: (_a = header.
|
|
1172
|
+
description: (_a = header.summary) !== null && _a !== void 0 ? _a : header.doc,
|
|
1162
1173
|
},
|
|
1163
1174
|
},
|
|
1164
1175
|
}));
|
|
@@ -1197,7 +1208,7 @@ export class CodeModelBuilder {
|
|
|
1197
1208
|
trackConvenienceApi = false;
|
|
1198
1209
|
}
|
|
1199
1210
|
if (!schema) {
|
|
1200
|
-
schema = this.
|
|
1211
|
+
schema = this.processSchema(bodyType, op.language.default.name + "Response");
|
|
1201
1212
|
}
|
|
1202
1213
|
response = new SchemaResponse(schema, {
|
|
1203
1214
|
protocol: {
|
|
@@ -1266,122 +1277,122 @@ export class CodeModelBuilder {
|
|
|
1266
1277
|
.map((it) => it.toString());
|
|
1267
1278
|
}
|
|
1268
1279
|
}
|
|
1269
|
-
|
|
1280
|
+
processSchema(type, nameHint) {
|
|
1270
1281
|
return this.schemaCache.process(type, nameHint) || fail("Unable to process schema.");
|
|
1271
1282
|
}
|
|
1272
|
-
|
|
1283
|
+
processSchemaImpl(type, nameHint) {
|
|
1273
1284
|
if (isSdkBuiltInKind(type.kind)) {
|
|
1274
|
-
return this.
|
|
1285
|
+
return this.processBuiltInType(type, nameHint);
|
|
1275
1286
|
}
|
|
1276
1287
|
else {
|
|
1277
1288
|
switch (type.kind) {
|
|
1278
1289
|
case "enum":
|
|
1279
|
-
return this.
|
|
1290
|
+
return this.processChoiceSchema(type, type.name);
|
|
1280
1291
|
case "enumvalue":
|
|
1281
|
-
return this.
|
|
1292
|
+
return this.processConstantSchemaFromEnumValue(type, nameHint);
|
|
1282
1293
|
case "union":
|
|
1283
|
-
return this.
|
|
1294
|
+
return this.processUnionSchema(type, type.name);
|
|
1284
1295
|
case "model":
|
|
1285
|
-
return this.
|
|
1296
|
+
return this.processObjectSchema(type, type.name);
|
|
1286
1297
|
case "dict":
|
|
1287
|
-
return this.
|
|
1298
|
+
return this.processDictionarySchema(type, nameHint);
|
|
1288
1299
|
case "array":
|
|
1289
|
-
return this.
|
|
1300
|
+
return this.processArraySchema(type, nameHint);
|
|
1290
1301
|
case "duration":
|
|
1291
|
-
return this.
|
|
1302
|
+
return this.processDurationSchema(type, nameHint, getDurationFormat(type));
|
|
1292
1303
|
case "constant":
|
|
1293
|
-
return this.
|
|
1304
|
+
return this.processConstantSchema(type, nameHint);
|
|
1294
1305
|
case "utcDateTime":
|
|
1295
1306
|
case "offsetDateTime":
|
|
1296
1307
|
if (type.encode === "unixTimestamp") {
|
|
1297
|
-
return this.
|
|
1308
|
+
return this.processUnixTimeSchema(type, nameHint);
|
|
1298
1309
|
}
|
|
1299
1310
|
else {
|
|
1300
|
-
return this.
|
|
1311
|
+
return this.processDateTimeSchema(type, nameHint, type.encode === "rfc7231");
|
|
1301
1312
|
}
|
|
1302
1313
|
}
|
|
1303
1314
|
}
|
|
1304
1315
|
throw new Error(`Unrecognized type: '${type.kind}'.`);
|
|
1305
1316
|
}
|
|
1306
|
-
|
|
1317
|
+
processBuiltInType(type, nameHint) {
|
|
1307
1318
|
nameHint = nameHint || type.kind;
|
|
1308
1319
|
if (isSdkIntKind(type.kind)) {
|
|
1309
1320
|
const integerSize = type.kind === "safeint" || type.kind.includes("int64") ? 64 : 32;
|
|
1310
|
-
return this.
|
|
1321
|
+
return this.processIntegerSchema(type, nameHint, integerSize);
|
|
1311
1322
|
}
|
|
1312
1323
|
else {
|
|
1313
1324
|
switch (type.kind) {
|
|
1314
|
-
case "
|
|
1315
|
-
return this.
|
|
1325
|
+
case "unknown":
|
|
1326
|
+
return this.processAnySchema();
|
|
1316
1327
|
case "string":
|
|
1317
|
-
return this.
|
|
1328
|
+
return this.processStringSchema(type, nameHint);
|
|
1318
1329
|
case "float":
|
|
1319
1330
|
case "float32":
|
|
1320
1331
|
case "float64":
|
|
1321
|
-
return this.
|
|
1332
|
+
return this.processNumberSchema(type, nameHint);
|
|
1322
1333
|
case "decimal":
|
|
1323
1334
|
case "decimal128":
|
|
1324
|
-
return this.
|
|
1335
|
+
return this.processDecimalSchema(type, nameHint);
|
|
1325
1336
|
case "bytes":
|
|
1326
|
-
return this.
|
|
1337
|
+
return this.processByteArraySchema(type, nameHint);
|
|
1327
1338
|
case "boolean":
|
|
1328
|
-
return this.
|
|
1339
|
+
return this.processBooleanSchema(type, nameHint);
|
|
1329
1340
|
case "plainTime":
|
|
1330
|
-
return this.
|
|
1341
|
+
return this.processTimeSchema(type, nameHint);
|
|
1331
1342
|
case "plainDate":
|
|
1332
|
-
return this.
|
|
1343
|
+
return this.processDateSchema(type, nameHint);
|
|
1333
1344
|
case "url":
|
|
1334
|
-
return this.
|
|
1345
|
+
return this.processUrlSchema(type, nameHint);
|
|
1335
1346
|
}
|
|
1336
1347
|
}
|
|
1337
1348
|
}
|
|
1338
|
-
|
|
1349
|
+
processAnySchema() {
|
|
1339
1350
|
return this.anySchema;
|
|
1340
1351
|
}
|
|
1341
|
-
|
|
1352
|
+
processStringSchema(type, name) {
|
|
1342
1353
|
var _a;
|
|
1343
|
-
return this.codeModel.schemas.add(new StringSchema(name, (_a = type.
|
|
1344
|
-
summary: type.
|
|
1354
|
+
return this.codeModel.schemas.add(new StringSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1355
|
+
summary: type.summary,
|
|
1345
1356
|
}));
|
|
1346
1357
|
}
|
|
1347
|
-
|
|
1358
|
+
processByteArraySchema(type, name) {
|
|
1348
1359
|
var _a;
|
|
1349
1360
|
const base64Encoded = type.encode === "base64url";
|
|
1350
|
-
return this.codeModel.schemas.add(new ByteArraySchema(name, (_a = type.
|
|
1351
|
-
summary: type.
|
|
1361
|
+
return this.codeModel.schemas.add(new ByteArraySchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1362
|
+
summary: type.summary,
|
|
1352
1363
|
format: base64Encoded ? "base64url" : "byte",
|
|
1353
1364
|
}));
|
|
1354
1365
|
}
|
|
1355
|
-
|
|
1366
|
+
processIntegerSchema(type, name, precision) {
|
|
1356
1367
|
var _a;
|
|
1357
|
-
const schema = new NumberSchema(name, (_a = type.
|
|
1358
|
-
summary: type.
|
|
1368
|
+
const schema = new NumberSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", SchemaType.Integer, precision, {
|
|
1369
|
+
summary: type.summary,
|
|
1359
1370
|
});
|
|
1360
1371
|
if (type.encode === "string") {
|
|
1361
1372
|
schema.encode = type.encode;
|
|
1362
1373
|
}
|
|
1363
1374
|
return this.codeModel.schemas.add(schema);
|
|
1364
1375
|
}
|
|
1365
|
-
|
|
1376
|
+
processNumberSchema(type, name) {
|
|
1366
1377
|
var _a;
|
|
1367
|
-
return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.
|
|
1368
|
-
summary: type.
|
|
1378
|
+
return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", SchemaType.Number, 64, {
|
|
1379
|
+
summary: type.summary,
|
|
1369
1380
|
}));
|
|
1370
1381
|
}
|
|
1371
|
-
|
|
1382
|
+
processDecimalSchema(type, name) {
|
|
1372
1383
|
var _a;
|
|
1373
1384
|
// "Infinity" maps to "BigDecimal" in Java
|
|
1374
|
-
return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.
|
|
1375
|
-
summary: type.
|
|
1385
|
+
return this.codeModel.schemas.add(new NumberSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", SchemaType.Number, Infinity, {
|
|
1386
|
+
summary: type.summary,
|
|
1376
1387
|
}));
|
|
1377
1388
|
}
|
|
1378
|
-
|
|
1389
|
+
processBooleanSchema(type, name) {
|
|
1379
1390
|
var _a;
|
|
1380
|
-
return this.codeModel.schemas.add(new BooleanSchema(name, (_a = type.
|
|
1381
|
-
summary: type.
|
|
1391
|
+
return this.codeModel.schemas.add(new BooleanSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1392
|
+
summary: type.summary,
|
|
1382
1393
|
}));
|
|
1383
1394
|
}
|
|
1384
|
-
|
|
1395
|
+
processArraySchema(type, name) {
|
|
1385
1396
|
var _a;
|
|
1386
1397
|
let nullableItems = false;
|
|
1387
1398
|
let elementType = type.valueType;
|
|
@@ -1389,16 +1400,16 @@ export class CodeModelBuilder {
|
|
|
1389
1400
|
nullableItems = true;
|
|
1390
1401
|
elementType = elementType.type;
|
|
1391
1402
|
}
|
|
1392
|
-
const elementSchema = this.
|
|
1393
|
-
return this.codeModel.schemas.add(new ArraySchema(name, (_a = type.
|
|
1394
|
-
summary: type.
|
|
1403
|
+
const elementSchema = this.processSchema(elementType, name);
|
|
1404
|
+
return this.codeModel.schemas.add(new ArraySchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", elementSchema, {
|
|
1405
|
+
summary: type.summary,
|
|
1395
1406
|
nullableItems: nullableItems,
|
|
1396
1407
|
}));
|
|
1397
1408
|
}
|
|
1398
|
-
|
|
1409
|
+
processDictionarySchema(type, name) {
|
|
1399
1410
|
var _a;
|
|
1400
|
-
const dictSchema = new DictionarySchema(name, (_a = type.
|
|
1401
|
-
summary: type.
|
|
1411
|
+
const dictSchema = new DictionarySchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", null, {
|
|
1412
|
+
summary: type.summary,
|
|
1402
1413
|
});
|
|
1403
1414
|
// cache this now before we accidentally recurse on this type.
|
|
1404
1415
|
if (!this.schemaCache.has(type)) {
|
|
@@ -1410,21 +1421,21 @@ export class CodeModelBuilder {
|
|
|
1410
1421
|
nullableItems = true;
|
|
1411
1422
|
elementType = elementType.type;
|
|
1412
1423
|
}
|
|
1413
|
-
const elementSchema = this.
|
|
1424
|
+
const elementSchema = this.processSchema(elementType, name);
|
|
1414
1425
|
dictSchema.elementType = elementSchema;
|
|
1415
1426
|
dictSchema.nullableItems = nullableItems;
|
|
1416
1427
|
return this.codeModel.schemas.add(dictSchema);
|
|
1417
1428
|
}
|
|
1418
|
-
|
|
1429
|
+
processChoiceSchema(type, name) {
|
|
1419
1430
|
var _a, _b;
|
|
1420
1431
|
const rawEnumType = type.__raw;
|
|
1421
1432
|
const namespace = getNamespace(rawEnumType);
|
|
1422
|
-
const valueType = this.
|
|
1433
|
+
const valueType = this.processSchema(type.valueType, type.valueType.kind);
|
|
1423
1434
|
const choices = [];
|
|
1424
|
-
type.values.forEach((it) => { var _a, _b; return choices.push(new ChoiceValue(it.name, (_a = it.
|
|
1435
|
+
type.values.forEach((it) => { var _a, _b; return choices.push(new ChoiceValue(it.name, (_a = it.doc) !== null && _a !== void 0 ? _a : "", (_b = it.value) !== null && _b !== void 0 ? _b : it.name)); });
|
|
1425
1436
|
const schemaType = type.isFixed ? SealedChoiceSchema : ChoiceSchema;
|
|
1426
|
-
const schema = new schemaType((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.
|
|
1427
|
-
summary: type.
|
|
1437
|
+
const schema = new schemaType((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
|
|
1438
|
+
summary: type.summary,
|
|
1428
1439
|
choiceType: valueType,
|
|
1429
1440
|
choices: choices,
|
|
1430
1441
|
language: {
|
|
@@ -1439,68 +1450,68 @@ export class CodeModelBuilder {
|
|
|
1439
1450
|
schema.crossLanguageDefinitionId = type.crossLanguageDefinitionId;
|
|
1440
1451
|
return this.codeModel.schemas.add(schema);
|
|
1441
1452
|
}
|
|
1442
|
-
|
|
1453
|
+
processConstantSchema(type, name) {
|
|
1443
1454
|
var _a, _b;
|
|
1444
|
-
const valueType = this.
|
|
1445
|
-
return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.
|
|
1446
|
-
summary: type.
|
|
1455
|
+
const valueType = this.processSchema(type.valueType, type.valueType.kind);
|
|
1456
|
+
return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
|
|
1457
|
+
summary: type.summary,
|
|
1447
1458
|
valueType: valueType,
|
|
1448
1459
|
value: new ConstantValue(type.value),
|
|
1449
1460
|
}));
|
|
1450
1461
|
}
|
|
1451
|
-
|
|
1462
|
+
processConstantSchemaFromEnumValue(type, name) {
|
|
1452
1463
|
var _a, _b, _c;
|
|
1453
|
-
const valueType = this.
|
|
1454
|
-
return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.
|
|
1455
|
-
summary: type.
|
|
1464
|
+
const valueType = this.processSchema(type.enumType, type.enumType.name);
|
|
1465
|
+
return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
|
|
1466
|
+
summary: type.summary,
|
|
1456
1467
|
valueType: valueType,
|
|
1457
1468
|
value: new ConstantValue((_c = type.value) !== null && _c !== void 0 ? _c : type.name),
|
|
1458
1469
|
}));
|
|
1459
1470
|
}
|
|
1460
|
-
|
|
1471
|
+
processUnixTimeSchema(type, name) {
|
|
1461
1472
|
var _a;
|
|
1462
|
-
return this.codeModel.schemas.add(new UnixTimeSchema(name, (_a = type.
|
|
1463
|
-
summary: type.
|
|
1473
|
+
return this.codeModel.schemas.add(new UnixTimeSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1474
|
+
summary: type.summary,
|
|
1464
1475
|
}));
|
|
1465
1476
|
}
|
|
1466
|
-
|
|
1477
|
+
processDateTimeSchema(type, name, rfc1123) {
|
|
1467
1478
|
var _a;
|
|
1468
|
-
return this.codeModel.schemas.add(new DateTimeSchema(name, (_a = type.
|
|
1469
|
-
summary: type.
|
|
1479
|
+
return this.codeModel.schemas.add(new DateTimeSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1480
|
+
summary: type.summary,
|
|
1470
1481
|
format: rfc1123 ? "date-time-rfc1123" : "date-time",
|
|
1471
1482
|
}));
|
|
1472
1483
|
}
|
|
1473
|
-
|
|
1484
|
+
processDateSchema(type, name) {
|
|
1474
1485
|
var _a;
|
|
1475
|
-
return this.codeModel.schemas.add(new DateSchema(name, (_a = type.
|
|
1476
|
-
summary: type.
|
|
1486
|
+
return this.codeModel.schemas.add(new DateSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1487
|
+
summary: type.summary,
|
|
1477
1488
|
}));
|
|
1478
1489
|
}
|
|
1479
|
-
|
|
1490
|
+
processTimeSchema(type, name) {
|
|
1480
1491
|
var _a;
|
|
1481
|
-
return this.codeModel.schemas.add(new TimeSchema(name, (_a = type.
|
|
1482
|
-
summary: type.
|
|
1492
|
+
return this.codeModel.schemas.add(new TimeSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1493
|
+
summary: type.summary,
|
|
1483
1494
|
}));
|
|
1484
1495
|
}
|
|
1485
|
-
|
|
1496
|
+
processDurationSchema(type, name, format = "duration-rfc3339") {
|
|
1486
1497
|
var _a;
|
|
1487
|
-
return this.codeModel.schemas.add(new DurationSchema(name, (_a = type.
|
|
1488
|
-
summary: type.
|
|
1498
|
+
return this.codeModel.schemas.add(new DurationSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1499
|
+
summary: type.summary,
|
|
1489
1500
|
format: format,
|
|
1490
1501
|
}));
|
|
1491
1502
|
}
|
|
1492
|
-
|
|
1503
|
+
processUrlSchema(type, name) {
|
|
1493
1504
|
var _a;
|
|
1494
|
-
return this.codeModel.schemas.add(new UriSchema(name, (_a = type.
|
|
1495
|
-
summary: type.
|
|
1505
|
+
return this.codeModel.schemas.add(new UriSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1506
|
+
summary: type.summary,
|
|
1496
1507
|
}));
|
|
1497
1508
|
}
|
|
1498
|
-
|
|
1509
|
+
processObjectSchema(type, name) {
|
|
1499
1510
|
var _a, _b;
|
|
1500
1511
|
const rawModelType = type.__raw;
|
|
1501
1512
|
const namespace = getNamespace(rawModelType);
|
|
1502
|
-
const objectSchema = new ObjectSchema(name, (_a = type.
|
|
1503
|
-
summary: type.
|
|
1513
|
+
const objectSchema = new ObjectSchema(name, (_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1514
|
+
summary: type.summary,
|
|
1504
1515
|
language: {
|
|
1505
1516
|
default: {
|
|
1506
1517
|
namespace: namespace,
|
|
@@ -1519,15 +1530,15 @@ export class CodeModelBuilder {
|
|
|
1519
1530
|
}
|
|
1520
1531
|
// discriminator
|
|
1521
1532
|
if (type.discriminatedSubtypes && type.discriminatorProperty) {
|
|
1522
|
-
objectSchema.discriminator = new Discriminator(this.
|
|
1533
|
+
objectSchema.discriminator = new Discriminator(this.processModelProperty(type.discriminatorProperty));
|
|
1523
1534
|
for (const discriminatorValue in type.discriminatedSubtypes) {
|
|
1524
1535
|
const subType = type.discriminatedSubtypes[discriminatorValue];
|
|
1525
|
-
this.
|
|
1536
|
+
this.processSchema(subType, subType.name);
|
|
1526
1537
|
}
|
|
1527
1538
|
}
|
|
1528
1539
|
// type is a subtype
|
|
1529
1540
|
if (type.baseModel) {
|
|
1530
|
-
const parentSchema = this.
|
|
1541
|
+
const parentSchema = this.processSchema(type.baseModel, type.baseModel.name);
|
|
1531
1542
|
objectSchema.parents = new Relations();
|
|
1532
1543
|
objectSchema.parents.immediate.push(parentSchema);
|
|
1533
1544
|
if (parentSchema instanceof ObjectSchema) {
|
|
@@ -1557,11 +1568,11 @@ export class CodeModelBuilder {
|
|
|
1557
1568
|
name: "string",
|
|
1558
1569
|
crossLanguageDefinitionId: type.crossLanguageDefinitionId,
|
|
1559
1570
|
},
|
|
1560
|
-
description: type.
|
|
1571
|
+
description: type.doc,
|
|
1561
1572
|
valueType: type.additionalProperties,
|
|
1562
1573
|
decorators: [],
|
|
1563
1574
|
};
|
|
1564
|
-
const parentSchema = this.
|
|
1575
|
+
const parentSchema = this.processSchema(sdkDictType, "Record");
|
|
1565
1576
|
objectSchema.parents = (_b = objectSchema.parents) !== null && _b !== void 0 ? _b : new Relations();
|
|
1566
1577
|
objectSchema.parents.immediate.push(parentSchema);
|
|
1567
1578
|
pushDistinct(objectSchema.parents.all, parentSchema);
|
|
@@ -1570,7 +1581,7 @@ export class CodeModelBuilder {
|
|
|
1570
1581
|
// properties
|
|
1571
1582
|
for (const prop of type.properties) {
|
|
1572
1583
|
if (prop.kind === "property" && !prop.discriminator) {
|
|
1573
|
-
objectSchema.addProperty(this.
|
|
1584
|
+
objectSchema.addProperty(this.processModelProperty(prop));
|
|
1574
1585
|
}
|
|
1575
1586
|
}
|
|
1576
1587
|
return objectSchema;
|
|
@@ -1593,7 +1604,7 @@ export class CodeModelBuilder {
|
|
|
1593
1604
|
}
|
|
1594
1605
|
return type;
|
|
1595
1606
|
}
|
|
1596
|
-
|
|
1607
|
+
processModelProperty(prop) {
|
|
1597
1608
|
var _a;
|
|
1598
1609
|
let nullable = false;
|
|
1599
1610
|
let nonNullType = prop.type;
|
|
@@ -1621,22 +1632,22 @@ export class CodeModelBuilder {
|
|
|
1621
1632
|
if (prop.kind === "property" && prop.multipartOptions) {
|
|
1622
1633
|
// TODO: handle MultipartOptions.isMulti
|
|
1623
1634
|
if (prop.multipartOptions.isFilePart) {
|
|
1624
|
-
schema = this.
|
|
1635
|
+
schema = this.processMultipartFormDataFilePropertySchema(prop);
|
|
1625
1636
|
}
|
|
1626
1637
|
else if (prop.type.kind === "model" &&
|
|
1627
1638
|
prop.type.properties.some((it) => it.kind === "body")) {
|
|
1628
1639
|
// TODO: this is HttpPart of non-File. TCGC should help handle this.
|
|
1629
|
-
schema = this.
|
|
1640
|
+
schema = this.processSchema(prop.type.properties.find((it) => it.kind === "body").type, "");
|
|
1630
1641
|
}
|
|
1631
1642
|
else {
|
|
1632
|
-
schema = this.
|
|
1643
|
+
schema = this.processSchema(nonNullType, "");
|
|
1633
1644
|
}
|
|
1634
1645
|
}
|
|
1635
1646
|
else {
|
|
1636
|
-
schema = this.
|
|
1647
|
+
schema = this.processSchema(nonNullType, "");
|
|
1637
1648
|
}
|
|
1638
|
-
return new Property(prop.name, (_a = prop.
|
|
1639
|
-
summary: prop.
|
|
1649
|
+
return new Property(prop.name, (_a = prop.doc) !== null && _a !== void 0 ? _a : "", schema, {
|
|
1650
|
+
summary: prop.summary,
|
|
1640
1651
|
required: !prop.optional,
|
|
1641
1652
|
nullable: nullable,
|
|
1642
1653
|
readOnly: this.isReadOnly(prop),
|
|
@@ -1644,7 +1655,7 @@ export class CodeModelBuilder {
|
|
|
1644
1655
|
extensions: extensions,
|
|
1645
1656
|
});
|
|
1646
1657
|
}
|
|
1647
|
-
|
|
1658
|
+
processUnionSchema(type, name) {
|
|
1648
1659
|
var _a, _b;
|
|
1649
1660
|
if (!(type.__raw && type.__raw.kind === "Union")) {
|
|
1650
1661
|
throw new Error(`Invalid type for union: '${type.kind}'.`);
|
|
@@ -1653,18 +1664,18 @@ export class CodeModelBuilder {
|
|
|
1653
1664
|
const namespace = getNamespace(rawUnionType);
|
|
1654
1665
|
const baseName = (_a = type.name) !== null && _a !== void 0 ? _a : pascalCase(name) + "Model";
|
|
1655
1666
|
this.logWarning(`Convert TypeSpec Union '${getUnionDescription(rawUnionType, this.typeNameOptions)}' to Class '${baseName}'`);
|
|
1656
|
-
const unionSchema = new OrSchema(baseName + "Base", (_b = type.
|
|
1657
|
-
summary: type.
|
|
1667
|
+
const unionSchema = new OrSchema(baseName + "Base", (_b = type.doc) !== null && _b !== void 0 ? _b : "", {
|
|
1668
|
+
summary: type.summary,
|
|
1658
1669
|
});
|
|
1659
1670
|
unionSchema.anyOf = [];
|
|
1660
|
-
type.
|
|
1671
|
+
type.variantTypes.forEach((it) => {
|
|
1661
1672
|
var _a, _b;
|
|
1662
1673
|
const variantName = this.getUnionVariantName(it.__raw, { depth: 0 });
|
|
1663
1674
|
const modelName = variantName + baseName;
|
|
1664
1675
|
const propertyName = "value";
|
|
1665
1676
|
// these ObjectSchema is not added to codeModel.schemas
|
|
1666
|
-
const objectSchema = new ObjectSchema(modelName, (_a = it.
|
|
1667
|
-
summary: it.
|
|
1677
|
+
const objectSchema = new ObjectSchema(modelName, (_a = it.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1678
|
+
summary: it.summary,
|
|
1668
1679
|
language: {
|
|
1669
1680
|
default: {
|
|
1670
1681
|
namespace: namespace,
|
|
@@ -1674,9 +1685,9 @@ export class CodeModelBuilder {
|
|
|
1674
1685
|
},
|
|
1675
1686
|
},
|
|
1676
1687
|
});
|
|
1677
|
-
const variantSchema = this.
|
|
1678
|
-
objectSchema.addProperty(new Property(propertyName, (_b = type.
|
|
1679
|
-
summary: type.
|
|
1688
|
+
const variantSchema = this.processSchema(it, variantName);
|
|
1689
|
+
objectSchema.addProperty(new Property(propertyName, (_b = type.doc) !== null && _b !== void 0 ? _b : "", variantSchema, {
|
|
1690
|
+
summary: type.summary,
|
|
1680
1691
|
required: true,
|
|
1681
1692
|
readOnly: false,
|
|
1682
1693
|
}));
|
|
@@ -1684,10 +1695,10 @@ export class CodeModelBuilder {
|
|
|
1684
1695
|
});
|
|
1685
1696
|
return this.codeModel.schemas.add(unionSchema);
|
|
1686
1697
|
}
|
|
1687
|
-
|
|
1698
|
+
processBinarySchema(type) {
|
|
1688
1699
|
var _a;
|
|
1689
|
-
return this.codeModel.schemas.add(new BinarySchema((_a = type.
|
|
1690
|
-
summary: type.
|
|
1700
|
+
return this.codeModel.schemas.add(new BinarySchema((_a = type.doc) !== null && _a !== void 0 ? _a : "", {
|
|
1701
|
+
summary: type.summary,
|
|
1691
1702
|
}));
|
|
1692
1703
|
}
|
|
1693
1704
|
getUnionVariantName(type, option) {
|
|
@@ -1751,9 +1762,9 @@ export class CodeModelBuilder {
|
|
|
1751
1762
|
throw new Error(`Unrecognized type for union variable: '${type.kind}'.`);
|
|
1752
1763
|
}
|
|
1753
1764
|
}
|
|
1754
|
-
|
|
1765
|
+
processMultipartFormDataFilePropertySchema(property) {
|
|
1755
1766
|
var _a, _b, _c, _d;
|
|
1756
|
-
const processSchemaFunc = (type) => this.
|
|
1767
|
+
const processSchemaFunc = (type) => this.processSchema(type, "");
|
|
1757
1768
|
if (property.type.kind === "bytes" || property.type.kind === "model") {
|
|
1758
1769
|
const namespace = property.type.kind === "model"
|
|
1759
1770
|
? ((_a = getNamespace(property.type.__raw)) !== null && _a !== void 0 ? _a : this.namespace)
|
|
@@ -1766,7 +1777,7 @@ export class CodeModelBuilder {
|
|
|
1766
1777
|
? ((_c = getNamespace(property.type.valueType.__raw)) !== null && _c !== void 0 ? _c : this.namespace)
|
|
1767
1778
|
: this.namespace;
|
|
1768
1779
|
return new ArraySchema(property.name, (_d = property.details) !== null && _d !== void 0 ? _d : "", getFileDetailsSchema(property, namespace, this.getJavaNamespace(namespace), this.codeModel.schemas, this.binarySchema, this.stringSchema, processSchemaFunc), {
|
|
1769
|
-
summary: property.
|
|
1780
|
+
summary: property.summary,
|
|
1770
1781
|
});
|
|
1771
1782
|
}
|
|
1772
1783
|
else {
|
|
@@ -1936,7 +1947,7 @@ export class CodeModelBuilder {
|
|
|
1936
1947
|
}
|
|
1937
1948
|
subscriptionIdParameter(parameter) {
|
|
1938
1949
|
if (!this._subscriptionParameter) {
|
|
1939
|
-
const description = parameter.
|
|
1950
|
+
const description = parameter.doc;
|
|
1940
1951
|
this._subscriptionParameter = new Parameter("subscriptionId", description ? description : "The ID of the target subscription.", this.stringSchema, {
|
|
1941
1952
|
implementation: ImplementationLocation.Client,
|
|
1942
1953
|
required: true,
|