@azure-tools/typespec-java 0.11.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/code-model-builder.d.ts +2 -0
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +117 -70
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/common/client.d.ts +6 -1
- package/dist/src/common/client.d.ts.map +1 -1
- package/dist/src/common/client.js +6 -1
- package/dist/src/common/client.js.map +1 -1
- package/dist/src/common/code-model.js.map +1 -1
- package/dist/src/common/operation.d.ts +1 -0
- package/dist/src/common/operation.d.ts.map +1 -1
- package/dist/src/common/operation.js.map +1 -1
- package/dist/src/common/schemas/choice.d.ts +2 -0
- package/dist/src/common/schemas/choice.d.ts.map +1 -1
- package/dist/src/common/schemas/choice.js +1 -0
- package/dist/src/common/schemas/choice.js.map +1 -1
- package/dist/src/common/schemas/usage.d.ts +3 -1
- package/dist/src/common/schemas/usage.d.ts.map +1 -1
- package/dist/src/common/schemas/usage.js +2 -0
- package/dist/src/common/schemas/usage.js.map +1 -1
- package/dist/src/emitter.js +2 -2
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/models.d.ts.map +1 -1
- package/dist/src/models.js +9 -2
- package/dist/src/models.js.map +1 -1
- package/dist/src/operation-utils.js.map +1 -1
- package/dist/src/prenamer/formatter.js.map +1 -1
- package/dist/src/prenamer/naming-utils.js.map +1 -1
- package/dist/src/prenamer/prenamer.js.map +1 -1
- package/dist/src/type-utils.js.map +1 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -18
- package/readme.md +1 -1
- package/target/{azure-typespec-extension-jar-with-dependencies.jar → emitter.jar} +0 -0
|
@@ -20,6 +20,7 @@ export declare class CodeModelBuilder {
|
|
|
20
20
|
private isInternal;
|
|
21
21
|
private processModels;
|
|
22
22
|
private processSchemaUsage;
|
|
23
|
+
private deduplicateSchemaName;
|
|
23
24
|
private resolveSchemaUsage;
|
|
24
25
|
private processClients;
|
|
25
26
|
private needToSkipProcessingOperation;
|
|
@@ -43,6 +44,7 @@ export declare class CodeModelBuilder {
|
|
|
43
44
|
private processByteArraySchema;
|
|
44
45
|
private processIntegerSchema;
|
|
45
46
|
private processNumberSchema;
|
|
47
|
+
private processDecimalSchema;
|
|
46
48
|
private processBooleanSchema;
|
|
47
49
|
private processArraySchema;
|
|
48
50
|
private processDictionarySchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAoBL,OAAO,EAGP,IAAI,EAEJ,KAAK,EASL,WAAW,EAOZ,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAoBL,OAAO,EAGP,IAAI,EAEJ,KAAK,EASL,WAAW,EAOZ,MAAM,oBAAoB,CAAC;AAgC5B,OAAO,EACL,SAAS,EAIT,aAAa,EAUb,YAAY,EACZ,YAAY,EACZ,SAAS,EAKT,MAAM,EAIN,YAAY,EAeb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAUnD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAW9C,OAAO,EACL,eAAe,EAehB,MAAM,iBAAiB,CAAC;AAoBzB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAa;IAE/B,OAAO,CAAC,OAAO,CAAiB;IAEhC,OAAO,CAAC,SAAS,CAAY;IAE7B,QAAQ,CAAC,WAAW,gCAAyF;IAC7G,QAAQ,CAAC,iBAAiB,sC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;IAED,OAAO,CAAC,oBAAoB;IA+D5B,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,yBAAyB;IAIjC,OAAO,CAAC,kBAAkB;CAiB3B"}
|
|
@@ -3,11 +3,11 @@ import { getResourceOperation, getSegment } from "@typespec/rest";
|
|
|
3
3
|
import { getAuthentication, getServers, getStatusCodeDescription, getHttpOperation, getQueryParamOptions, getHeaderFieldOptions, } from "@typespec/http";
|
|
4
4
|
import { getAddedOnVersions, getVersion } from "@typespec/versioning";
|
|
5
5
|
import { isPollingLocation, getPagedResult, isFixed, getLroMetadata } from "@azure-tools/typespec-azure-core";
|
|
6
|
-
import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, } from "@azure-tools/typespec-client-generator-core";
|
|
6
|
+
import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, getCrossLanguageDefinitionId, } from "@azure-tools/typespec-client-generator-core";
|
|
7
7
|
import { fail } from "assert";
|
|
8
8
|
import { AnySchema, ArraySchema, BinaryResponse, BinarySchema, BooleanSchema, ByteArraySchema, ChoiceValue, DateTimeSchema, DateSchema, DictionarySchema, Discriminator, HttpHeader, HttpParameter, ImplementationLocation, NumberSchema, ObjectSchema, Parameter, ParameterLocation, Property, Relations, Response, SchemaResponse, SchemaType, StringSchema, TimeSchema, Security, OAuth2SecurityScheme, KeySecurityScheme, OperationGroup, UriSchema, VirtualParameter, GroupSchema, GroupProperty, ApiVersion, SerializationStyle, Metadata, UnixTimeSchema, Language, } from "@autorest/codemodel";
|
|
9
9
|
import { CodeModel } from "./common/code-model.js";
|
|
10
|
-
import { Client as CodeModelClient } from "./common/client.js";
|
|
10
|
+
import { Client as CodeModelClient, ObjectScheme } from "./common/client.js";
|
|
11
11
|
import { ConvenienceApi, Operation as CodeModelOperation, Request } from "./common/operation.js";
|
|
12
12
|
import { SchemaContext } from "./common/schemas/usage.js";
|
|
13
13
|
import { ChoiceSchema, SealedChoiceSchema } from "./common/schemas/choice.js";
|
|
@@ -86,6 +86,7 @@ export class CodeModelBuilder {
|
|
|
86
86
|
if (this.options.namer) {
|
|
87
87
|
this.codeModel = new PreNamer(this.codeModel).init().process();
|
|
88
88
|
}
|
|
89
|
+
this.deduplicateSchemaName();
|
|
89
90
|
return this.codeModel;
|
|
90
91
|
}
|
|
91
92
|
processHost(server) {
|
|
@@ -180,7 +181,7 @@ export class CodeModelBuilder {
|
|
|
180
181
|
const keyScheme = new KeySecurityScheme({
|
|
181
182
|
name: "authorization",
|
|
182
183
|
});
|
|
183
|
-
keyScheme.prefix = schemeOrApiKeyPrefix; // TODO
|
|
184
|
+
keyScheme.prefix = schemeOrApiKeyPrefix; // TODO: modify KeySecurityScheme, after design stable
|
|
184
185
|
securitySchemes.push(keyScheme);
|
|
185
186
|
}
|
|
186
187
|
break;
|
|
@@ -250,7 +251,7 @@ export class CodeModelBuilder {
|
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
processSchemaUsage() {
|
|
253
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
254
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
254
255
|
(_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => this.propagateSchemaUsage(it));
|
|
255
256
|
// post process for schema usage
|
|
256
257
|
(_b = this.codeModel.schemas.objects) === null || _b === void 0 ? void 0 : _b.forEach((it) => this.resolveSchemaUsage(it));
|
|
@@ -259,13 +260,16 @@ export class CodeModelBuilder {
|
|
|
259
260
|
(_e = this.codeModel.schemas.sealedChoices) === null || _e === void 0 ? void 0 : _e.forEach((it) => this.resolveSchemaUsage(it));
|
|
260
261
|
(_f = this.codeModel.schemas.ors) === null || _f === void 0 ? void 0 : _f.forEach((it) => this.resolveSchemaUsage(it));
|
|
261
262
|
(_g = this.codeModel.schemas.constants) === null || _g === void 0 ? void 0 : _g.forEach((it) => this.resolveSchemaUsage(it));
|
|
263
|
+
}
|
|
264
|
+
deduplicateSchemaName() {
|
|
265
|
+
var _a, _b, _c, _d, _e, _f;
|
|
262
266
|
// deduplicate model name
|
|
263
267
|
const nameCount = new Map();
|
|
264
268
|
const deduplicateName = (schema) => {
|
|
265
|
-
var _a;
|
|
269
|
+
var _a, _b;
|
|
266
270
|
const name = schema.language.default.name;
|
|
267
271
|
// skip models under "com.azure.core."
|
|
268
|
-
if (
|
|
272
|
+
if (name && !((_b = (_a = schema.language.java) === null || _a === void 0 ? void 0 : _a.namespace) === null || _b === void 0 ? void 0 : _b.startsWith("com.azure.core."))) {
|
|
269
273
|
if (!nameCount.has(name)) {
|
|
270
274
|
nameCount.set(name, 1);
|
|
271
275
|
}
|
|
@@ -276,11 +280,12 @@ export class CodeModelBuilder {
|
|
|
276
280
|
}
|
|
277
281
|
}
|
|
278
282
|
};
|
|
279
|
-
(
|
|
280
|
-
(
|
|
281
|
-
(
|
|
282
|
-
(
|
|
283
|
-
(
|
|
283
|
+
(_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => deduplicateName(it));
|
|
284
|
+
(_b = this.codeModel.schemas.groups) === null || _b === void 0 ? void 0 : _b.forEach((it) => deduplicateName(it)); // it may contain RequestConditions under "com.azure.core."
|
|
285
|
+
(_c = this.codeModel.schemas.choices) === null || _c === void 0 ? void 0 : _c.forEach((it) => deduplicateName(it));
|
|
286
|
+
(_d = this.codeModel.schemas.sealedChoices) === null || _d === void 0 ? void 0 : _d.forEach((it) => deduplicateName(it));
|
|
287
|
+
(_e = this.codeModel.schemas.ors) === null || _e === void 0 ? void 0 : _e.forEach((it) => deduplicateName(it));
|
|
288
|
+
(_f = this.codeModel.schemas.constants) === null || _f === void 0 ? void 0 : _f.forEach((it) => deduplicateName(it));
|
|
284
289
|
}
|
|
285
290
|
resolveSchemaUsage(schema) {
|
|
286
291
|
if (schema instanceof ObjectSchema ||
|
|
@@ -311,6 +316,7 @@ export class CodeModelBuilder {
|
|
|
311
316
|
// at present, use global security definition
|
|
312
317
|
security: this.codeModel.security,
|
|
313
318
|
});
|
|
319
|
+
codeModelClient.crossLanguageDefinitionId = client.crossLanguageDefinitionId;
|
|
314
320
|
// versioning
|
|
315
321
|
const versioning = getVersion(this.program, client.service);
|
|
316
322
|
if (versioning && versioning.getVersions()) {
|
|
@@ -345,7 +351,7 @@ export class CodeModelBuilder {
|
|
|
345
351
|
codeModelClient.addGlobalParameters(hostParameters);
|
|
346
352
|
const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters, codeModelClient.apiVersions);
|
|
347
353
|
clientContext.preProcessOperations(this.sdkContext, client);
|
|
348
|
-
const operationGroups = listOperationGroups(this.sdkContext, client);
|
|
354
|
+
const operationGroups = listOperationGroups(this.sdkContext, client, true);
|
|
349
355
|
const operationWithoutGroup = listOperationsInOperationGroup(this.sdkContext, client);
|
|
350
356
|
let codeModelGroup = new OperationGroup("");
|
|
351
357
|
for (const operation of operationWithoutGroup) {
|
|
@@ -358,13 +364,26 @@ export class CodeModelBuilder {
|
|
|
358
364
|
}
|
|
359
365
|
for (const operationGroup of operationGroups) {
|
|
360
366
|
const operations = listOperationsInOperationGroup(this.sdkContext, operationGroup);
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
367
|
+
// operation group with no operation is skipped
|
|
368
|
+
if (operations.length > 0) {
|
|
369
|
+
const groupPath = operationGroup.groupPath.split(".");
|
|
370
|
+
let oprationGroupName;
|
|
371
|
+
if (groupPath.length > 1) {
|
|
372
|
+
// groupPath should be in format of "OpenAIClient.Chat.Completions"
|
|
373
|
+
oprationGroupName = groupPath.slice(1).join("");
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
// protection
|
|
377
|
+
oprationGroupName = operationGroup.type.name;
|
|
365
378
|
}
|
|
379
|
+
codeModelGroup = new OperationGroup(oprationGroupName);
|
|
380
|
+
for (const operation of operations) {
|
|
381
|
+
if (!this.needToSkipProcessingOperation(operation, clientContext)) {
|
|
382
|
+
codeModelGroup.addOperation(this.processOperation(oprationGroupName, operation, clientContext));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
codeModelClient.operationGroups.push(codeModelGroup);
|
|
366
386
|
}
|
|
367
|
-
codeModelClient.operationGroups.push(codeModelGroup);
|
|
368
387
|
}
|
|
369
388
|
this.codeModel.clients.push(codeModelClient);
|
|
370
389
|
}
|
|
@@ -411,10 +430,6 @@ export class CodeModelBuilder {
|
|
|
411
430
|
this.trace(`Operation '${operation.name}' is temporary skipped, as it is an overloaded operation`);
|
|
412
431
|
return true;
|
|
413
432
|
}
|
|
414
|
-
else if (clientContext.ignoredOperations.has(operation)) {
|
|
415
|
-
this.trace(`Operation '${operation.name}' is skipped, as it is used in '@pollingOperation' of a long running operation`);
|
|
416
|
-
return true;
|
|
417
|
-
}
|
|
418
433
|
return false;
|
|
419
434
|
}
|
|
420
435
|
processOperation(groupName, operation, clientContext) {
|
|
@@ -433,9 +448,11 @@ export class CodeModelBuilder {
|
|
|
433
448
|
: undefined,
|
|
434
449
|
},
|
|
435
450
|
});
|
|
451
|
+
codeModelOperation.crossLanguageDefinitionId = getCrossLanguageDefinitionId(operation);
|
|
436
452
|
codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
|
|
437
453
|
const convenienceApiName = this.getConvenienceApiName(operation);
|
|
438
454
|
let generateConvenienceApi = Boolean(convenienceApiName);
|
|
455
|
+
const generateProtocolApi = shouldGenerateProtocol(this.sdkContext, operation);
|
|
439
456
|
let apiComment = undefined;
|
|
440
457
|
if (generateConvenienceApi) {
|
|
441
458
|
// check if the convenience API need to be disabled for some special cases
|
|
@@ -446,10 +463,9 @@ export class CodeModelBuilder {
|
|
|
446
463
|
this.logWarning(apiComment);
|
|
447
464
|
}
|
|
448
465
|
else if (operationIsMultipart(op)) {
|
|
449
|
-
// do not generate
|
|
450
|
-
generateConvenienceApi = false;
|
|
451
|
-
// make it internal
|
|
466
|
+
// do not generate protocol method for multipart/form-data, as it be very hard for user to prepare the request body as BinaryData
|
|
452
467
|
codeModelOperation.internalApi = true;
|
|
468
|
+
generateConvenienceApi = false;
|
|
453
469
|
apiComment = `Protocol API requires serialization of parts with content-disposition and data, as operation '${op.operation.name}' is 'multipart/form-data'`;
|
|
454
470
|
this.logWarning(apiComment);
|
|
455
471
|
}
|
|
@@ -480,8 +496,7 @@ export class CodeModelBuilder {
|
|
|
480
496
|
codeModelOperation.language.java.comment = apiComment;
|
|
481
497
|
}
|
|
482
498
|
// check for generating protocol api or not
|
|
483
|
-
codeModelOperation.generateProtocolApi =
|
|
484
|
-
shouldGenerateProtocol(this.sdkContext, operation) && !codeModelOperation.internalApi;
|
|
499
|
+
codeModelOperation.generateProtocolApi = generateProtocolApi && !codeModelOperation.internalApi;
|
|
485
500
|
codeModelOperation.addRequest(new Request({
|
|
486
501
|
protocol: {
|
|
487
502
|
http: {
|
|
@@ -597,8 +612,12 @@ export class CodeModelBuilder {
|
|
|
597
612
|
}
|
|
598
613
|
}
|
|
599
614
|
// finalSchema
|
|
600
|
-
if (verb !== "delete" &&
|
|
601
|
-
|
|
615
|
+
if (verb !== "delete" &&
|
|
616
|
+
lroMetadata.finalResult &&
|
|
617
|
+
lroMetadata.finalEnvelopeResult &&
|
|
618
|
+
lroMetadata.finalResult !== "void" &&
|
|
619
|
+
lroMetadata.finalEnvelopeResult !== "void") {
|
|
620
|
+
const finalResult = useNewPollStrategy ? lroMetadata.finalResult : lroMetadata.finalEnvelopeResult;
|
|
602
621
|
const finalType = this.findResponseBody(finalResult);
|
|
603
622
|
finalSchema = this.processSchema(finalType, "finalResult");
|
|
604
623
|
}
|
|
@@ -948,6 +967,9 @@ export class CodeModelBuilder {
|
|
|
948
967
|
if (operationIsJsonMergePatch(httpOperation)) {
|
|
949
968
|
this.trackSchemaUsage(schema, { usage: [SchemaContext.JsonMergePatch] });
|
|
950
969
|
}
|
|
970
|
+
if (op.convenienceApi && operationIsMultipart(httpOperation)) {
|
|
971
|
+
this.trackSchemaUsage(schema, { usage: [SchemaContext.MultipartFormData] });
|
|
972
|
+
}
|
|
951
973
|
if (!schema.language.default.name && schema instanceof ObjectSchema) {
|
|
952
974
|
// anonymous model
|
|
953
975
|
// name the schema for documentation
|
|
@@ -962,8 +984,9 @@ export class CodeModelBuilder {
|
|
|
962
984
|
const request = new Request();
|
|
963
985
|
request.parameters = [];
|
|
964
986
|
op.convenienceApi.requests.push(request);
|
|
965
|
-
for (const [
|
|
966
|
-
const
|
|
987
|
+
for (const [_, opParameter] of parameters.properties) {
|
|
988
|
+
const serializedName = this.getSerializedName(opParameter);
|
|
989
|
+
const existParameter = op.parameters.find((it) => it.language.default.serializedName === serializedName);
|
|
967
990
|
if (existParameter) {
|
|
968
991
|
// parameter
|
|
969
992
|
if (existParameter.implementation === ImplementationLocation.Method &&
|
|
@@ -973,7 +996,7 @@ export class CodeModelBuilder {
|
|
|
973
996
|
}
|
|
974
997
|
else {
|
|
975
998
|
// property from anonymous model
|
|
976
|
-
const existBodyProperty = (_c = schema.properties) === null || _c === void 0 ? void 0 : _c.find((it) => it.serializedName ===
|
|
999
|
+
const existBodyProperty = (_c = schema.properties) === null || _c === void 0 ? void 0 : _c.find((it) => it.serializedName === serializedName);
|
|
977
1000
|
if (existBodyProperty) {
|
|
978
1001
|
request.parameters.push(new VirtualParameter(existBodyProperty.language.default.name, existBodyProperty.language.default.description, existBodyProperty.schema, {
|
|
979
1002
|
originalParameter: parameter,
|
|
@@ -1291,7 +1314,7 @@ export class CodeModelBuilder {
|
|
|
1291
1314
|
}
|
|
1292
1315
|
if (scalarName.startsWith("decimal")) {
|
|
1293
1316
|
// decimal
|
|
1294
|
-
return this.
|
|
1317
|
+
return this.processDecimalSchema(type, nameHint);
|
|
1295
1318
|
}
|
|
1296
1319
|
else if (scalarName.startsWith("int") || scalarName.startsWith("uint") || scalarName === "safeint") {
|
|
1297
1320
|
// integer
|
|
@@ -1375,6 +1398,12 @@ export class CodeModelBuilder {
|
|
|
1375
1398
|
summary: this.getSummary(type),
|
|
1376
1399
|
}));
|
|
1377
1400
|
}
|
|
1401
|
+
processDecimalSchema(type, name) {
|
|
1402
|
+
// "Infinity" maps to "BigDecimal" in Java
|
|
1403
|
+
return this.codeModel.schemas.add(new NumberSchema(name, this.getDoc(type), SchemaType.Number, Infinity, {
|
|
1404
|
+
summary: this.getSummary(type),
|
|
1405
|
+
}));
|
|
1406
|
+
}
|
|
1378
1407
|
processBooleanSchema(type, name) {
|
|
1379
1408
|
return this.codeModel.schemas.add(new BooleanSchema(name, this.getDoc(type), {
|
|
1380
1409
|
summary: this.getSummary(type),
|
|
@@ -1409,36 +1438,22 @@ export class CodeModelBuilder {
|
|
|
1409
1438
|
: this.stringSchema;
|
|
1410
1439
|
const choices = [];
|
|
1411
1440
|
type.members.forEach((it) => { var _a; return choices.push(new ChoiceValue(it.name, this.getDoc(it), (_a = it.value) !== null && _a !== void 0 ? _a : it.name)); });
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
},
|
|
1421
|
-
java: {
|
|
1422
|
-
namespace: getJavaNamespace(namespace),
|
|
1423
|
-
},
|
|
1441
|
+
const schemaType = sealed ? SealedChoiceSchema : ChoiceSchema;
|
|
1442
|
+
const schema = new schemaType(name, this.getDoc(type), {
|
|
1443
|
+
summary: this.getSummary(type),
|
|
1444
|
+
choiceType: valueType,
|
|
1445
|
+
choices: choices,
|
|
1446
|
+
language: {
|
|
1447
|
+
default: {
|
|
1448
|
+
namespace: namespace,
|
|
1424
1449
|
},
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
else {
|
|
1428
|
-
return this.codeModel.schemas.add(new ChoiceSchema(name, this.getDoc(type), {
|
|
1429
|
-
summary: this.getSummary(type),
|
|
1430
|
-
choiceType: valueType,
|
|
1431
|
-
choices: choices,
|
|
1432
|
-
language: {
|
|
1433
|
-
default: {
|
|
1434
|
-
namespace: namespace,
|
|
1435
|
-
},
|
|
1436
|
-
java: {
|
|
1437
|
-
namespace: getJavaNamespace(namespace),
|
|
1438
|
-
},
|
|
1450
|
+
java: {
|
|
1451
|
+
namespace: getJavaNamespace(namespace),
|
|
1439
1452
|
},
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1453
|
+
},
|
|
1454
|
+
});
|
|
1455
|
+
schema.crossLanguageDefinitionId = getCrossLanguageDefinitionId(type);
|
|
1456
|
+
return this.codeModel.schemas.add(schema);
|
|
1442
1457
|
}
|
|
1443
1458
|
processConstantSchemaForLiteral(type, name) {
|
|
1444
1459
|
const valueType = type.kind === "String"
|
|
@@ -1465,6 +1480,10 @@ export class CodeModelBuilder {
|
|
|
1465
1480
|
}
|
|
1466
1481
|
processChoiceSchemaForUnion(type, variants, name) {
|
|
1467
1482
|
// variants is Literal
|
|
1483
|
+
const kindSet = new Set(variants.map((it) => it.type.kind));
|
|
1484
|
+
// "choice1" | "choice2" is sealed
|
|
1485
|
+
// "choice1" | "choice2" | string is extensible
|
|
1486
|
+
const sealed = kindSet.size === 1;
|
|
1468
1487
|
variants = variants.filter((it) => it.type.kind === "String" || it.type.kind === "Number" || it.type.kind === "Boolean");
|
|
1469
1488
|
const kind = variants[0].type.kind;
|
|
1470
1489
|
const valueType = kind === "String"
|
|
@@ -1477,7 +1496,8 @@ export class CodeModelBuilder {
|
|
|
1477
1496
|
const choices = [];
|
|
1478
1497
|
variants.forEach((it) => choices.push(new ChoiceValue(it.type.value.toString(), this.getDoc(it), it.type.value)));
|
|
1479
1498
|
const namespace = getNamespace(type);
|
|
1480
|
-
|
|
1499
|
+
const schemaType = sealed ? SealedChoiceSchema : ChoiceSchema;
|
|
1500
|
+
const schema = new schemaType(name, this.getDoc(type), {
|
|
1481
1501
|
summary: this.getSummary(type),
|
|
1482
1502
|
choiceType: valueType,
|
|
1483
1503
|
choices: choices,
|
|
@@ -1489,7 +1509,9 @@ export class CodeModelBuilder {
|
|
|
1489
1509
|
namespace: getJavaNamespace(namespace),
|
|
1490
1510
|
},
|
|
1491
1511
|
},
|
|
1492
|
-
})
|
|
1512
|
+
});
|
|
1513
|
+
// schema.crossLanguageDefinitionId = getCrossLanguageDefinitionId(type);
|
|
1514
|
+
return this.codeModel.schemas.add(schema);
|
|
1493
1515
|
}
|
|
1494
1516
|
processUnixTimeSchema(type, name) {
|
|
1495
1517
|
return this.codeModel.schemas.add(new UnixTimeSchema(name, this.getDoc(type), {
|
|
@@ -1526,7 +1548,7 @@ export class CodeModelBuilder {
|
|
|
1526
1548
|
processObjectSchema(type, name) {
|
|
1527
1549
|
var _a, _b;
|
|
1528
1550
|
const namespace = getNamespace(type);
|
|
1529
|
-
const objectSchema =
|
|
1551
|
+
const objectSchema = new ObjectScheme(name, this.getDoc(type), {
|
|
1530
1552
|
summary: this.getSummary(type),
|
|
1531
1553
|
language: {
|
|
1532
1554
|
default: {
|
|
@@ -1536,7 +1558,9 @@ export class CodeModelBuilder {
|
|
|
1536
1558
|
namespace: getJavaNamespace(namespace),
|
|
1537
1559
|
},
|
|
1538
1560
|
},
|
|
1539
|
-
})
|
|
1561
|
+
});
|
|
1562
|
+
objectSchema.crossLanguageDefinitionId = getCrossLanguageDefinitionId(type);
|
|
1563
|
+
this.codeModel.schemas.add(objectSchema);
|
|
1540
1564
|
// cache this now before we accidentally recurse on this type.
|
|
1541
1565
|
this.schemaCache.set(type, objectSchema);
|
|
1542
1566
|
// discriminator
|
|
@@ -1544,10 +1568,33 @@ export class CodeModelBuilder {
|
|
|
1544
1568
|
const discriminator = getDiscriminator(this.program, type);
|
|
1545
1569
|
if (discriminator) {
|
|
1546
1570
|
discriminatorPropertyName = discriminator.propertyName;
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1571
|
+
// find the discriminator property from model
|
|
1572
|
+
// the property is required for getting its serializedName
|
|
1573
|
+
let discriminatorProperty = Array.from(type.properties.values()).find((it) => it.name === discriminatorPropertyName);
|
|
1574
|
+
if (!discriminatorProperty) {
|
|
1575
|
+
// try find the discriminator property from any of its derived models
|
|
1576
|
+
for (const deriveModel of type.derivedModels) {
|
|
1577
|
+
discriminatorProperty = Array.from(deriveModel.properties.values()).find((it) => it.name === discriminatorPropertyName);
|
|
1578
|
+
if (discriminatorProperty) {
|
|
1579
|
+
// found
|
|
1580
|
+
break;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
if (discriminatorProperty) {
|
|
1585
|
+
objectSchema.discriminator = new Discriminator(this.processModelProperty(discriminatorProperty));
|
|
1586
|
+
// as we do not expose the discriminator property, its schema is fine to be just a string (and we do not want to generate an enum that not used anywhere)
|
|
1587
|
+
// TODO: support enum schema, if we expose the discriminator property
|
|
1588
|
+
objectSchema.discriminator.property.schema = this.stringSchema;
|
|
1589
|
+
}
|
|
1590
|
+
else {
|
|
1591
|
+
// fallback to property name, if cannot find the discriminator property
|
|
1592
|
+
objectSchema.discriminator = new Discriminator(new Property(discriminatorPropertyName, discriminatorPropertyName, this.stringSchema, {
|
|
1593
|
+
required: true,
|
|
1594
|
+
serializedName: discriminatorPropertyName,
|
|
1595
|
+
}));
|
|
1596
|
+
}
|
|
1597
|
+
objectSchema.discriminator.propertyName = discriminatorPropertyName;
|
|
1551
1598
|
}
|
|
1552
1599
|
// parent
|
|
1553
1600
|
if (type.baseModel) {
|
|
@@ -1585,7 +1632,7 @@ export class CodeModelBuilder {
|
|
|
1585
1632
|
if (objectSchema.parents) {
|
|
1586
1633
|
const parentWithDiscriminator = objectSchema.parents.all.find((it) => it instanceof ObjectSchema && it.discriminator);
|
|
1587
1634
|
if (parentWithDiscriminator) {
|
|
1588
|
-
discriminatorPropertyName = parentWithDiscriminator.discriminator.
|
|
1635
|
+
discriminatorPropertyName = parentWithDiscriminator.discriminator.propertyName;
|
|
1589
1636
|
const discriminatorProperty = Array.from(type.properties.values()).find((it) => it.name === discriminatorPropertyName && (it.type.kind === "String" || it.type.kind === "EnumMember"));
|
|
1590
1637
|
if (discriminatorProperty) {
|
|
1591
1638
|
if (discriminatorProperty.type.kind === "String") {
|
|
@@ -2047,7 +2094,7 @@ export class CodeModelBuilder {
|
|
|
2047
2094
|
};
|
|
2048
2095
|
// Exclude context that not to be propagated
|
|
2049
2096
|
const schemaUsage = {
|
|
2050
|
-
usage: (_a = schema.usage) === null || _a === void 0 ? void 0 : _a.filter((it) => it !== SchemaContext.Paged && it !== SchemaContext.Anonymous),
|
|
2097
|
+
usage: (_a = schema.usage) === null || _a === void 0 ? void 0 : _a.filter((it) => it !== SchemaContext.Paged && it !== SchemaContext.Anonymous && it !== SchemaContext.MultipartFormData),
|
|
2051
2098
|
serializationFormats: schema.serializationFormats,
|
|
2052
2099
|
};
|
|
2053
2100
|
// Propagate the usage of the initial schema itself
|