@azure-tools/typespec-java 0.16.2 → 0.17.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 +1 -1
- package/dist/src/code-model-builder.d.ts.map +1 -1
- package/dist/src/code-model-builder.js +54 -96
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/operation-utils.js +2 -2
- package/dist/src/operation-utils.js.map +1 -1
- package/dist/src/type-utils.d.ts +3 -4
- package/dist/src/type-utils.d.ts.map +1 -1
- package/dist/src/type-utils.js +4 -41
- package/dist/src/type-utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -20
- package/target/emitter.jar +0 -0
|
@@ -39,7 +39,7 @@ export declare class CodeModelBuilder {
|
|
|
39
39
|
/**
|
|
40
40
|
* `@armProviderNamespace` currently will add a default server if not defined globally:
|
|
41
41
|
* https://github.com/Azure/typespec-azure/blob/8b8d7c05f168d9305a09691c4fedcb88f4a57652/packages/typespec-azure-resource-manager/src/namespace.ts#L121-L128
|
|
42
|
-
* TODO: if the synthesized server has the right hostParameter, we can use that
|
|
42
|
+
* TODO: if the synthesized server has the right hostParameter, we can use that instead
|
|
43
43
|
*
|
|
44
44
|
* @param server returned by getServers
|
|
45
45
|
* @returns whether it's synthesized by `@armProviderNamespace`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIT,YAAY,EACZ,aAAa,EAeb,YAAY,EAEZ,YAAY,EAEZ,SAAS,EAKT,MAAM,EAMN,YAAY,EAKb,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAaL,OAAO,EAkBR,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts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{ AnySchema, ApiVersion, ArraySchema, BinaryResponse, BinarySchema, Boole
|
|
|
2
2
|
import { KnownMediaType } from "@azure-tools/codegen";
|
|
3
3
|
import { getLroMetadata, getPagedResult, isPollingLocation } from "@azure-tools/typespec-azure-core";
|
|
4
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,
|
|
5
|
+
import { getDoc, getEffectiveModelType, getEncode, getFriendlyName, getNamespaceFullName, getOverloadedOperation, getProjectedName, getSummary, getVisibility, ignoreDiagnostics, isArrayModelType, isErrorModel, isRecordModelType, isVoidType, listServices, } from "@typespec/compiler";
|
|
6
6
|
import { Visibility, getAuthentication, getHeaderFieldOptions, getHttpOperation, getQueryParamOptions, getServers, getStatusCodeDescription, isPathParam, } from "@typespec/http";
|
|
7
7
|
import { getResourceOperation, getSegment } from "@typespec/rest";
|
|
8
8
|
import { getAddedOnVersions, getVersion } from "@typespec/versioning";
|
|
@@ -21,7 +21,7 @@ import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./extern
|
|
|
21
21
|
import { ClientContext } from "./models.js";
|
|
22
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
23
|
import { PreNamer } from "./prenamer/prenamer.js";
|
|
24
|
-
import { ProcessingCache, getAccess, getDurationFormatFromSdkType,
|
|
24
|
+
import { ProcessingCache, getAccess, getDurationFormatFromSdkType, getNonNullSdkType, getUnionDescription, getUsage, hasScalarAsBase, isArmCommonType, isModelReferredInTemplate, isNullableType, isStable, modelIs, pushDistinct, } from "./type-utils.js";
|
|
25
25
|
import { getJavaNamespace, getNamespace, logWarning, pascalCase, stringArrayContainsIgnoreCase, trace, } from "./utils.js";
|
|
26
26
|
const { isEqual } = pkg;
|
|
27
27
|
export class CodeModelBuilder {
|
|
@@ -112,10 +112,10 @@ export class CodeModelBuilder {
|
|
|
112
112
|
this.trackSchemaUsage(schema, {
|
|
113
113
|
usage: [SchemaContext.Input, SchemaContext.Output /*SchemaContext.Public*/],
|
|
114
114
|
});
|
|
115
|
-
parameter = new Parameter(it
|
|
115
|
+
parameter = new Parameter(this.getName(it), this.getDoc(it), schema, {
|
|
116
116
|
implementation: ImplementationLocation.Client,
|
|
117
117
|
origin: "modelerfour:synthesized/host",
|
|
118
|
-
required:
|
|
118
|
+
required: !it.optional,
|
|
119
119
|
protocol: {
|
|
120
120
|
http: new HttpParameter(ParameterLocation.Uri),
|
|
121
121
|
},
|
|
@@ -134,6 +134,7 @@ export class CodeModelBuilder {
|
|
|
134
134
|
return hostParameters;
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
137
|
+
// use "endpoint"
|
|
137
138
|
hostParameters.push(this.codeModel.addGlobalParameter(new Parameter("endpoint", "Server parameter", this.stringSchema, {
|
|
138
139
|
implementation: ImplementationLocation.Client,
|
|
139
140
|
origin: "modelerfour:synthesized/host",
|
|
@@ -445,7 +446,7 @@ export class CodeModelBuilder {
|
|
|
445
446
|
/**
|
|
446
447
|
* `@armProviderNamespace` currently will add a default server if not defined globally:
|
|
447
448
|
* https://github.com/Azure/typespec-azure/blob/8b8d7c05f168d9305a09691c4fedcb88f4a57652/packages/typespec-azure-resource-manager/src/namespace.ts#L121-L128
|
|
448
|
-
* TODO: if the synthesized server has the right hostParameter, we can use that
|
|
449
|
+
* TODO: if the synthesized server has the right hostParameter, we can use that instead
|
|
449
450
|
*
|
|
450
451
|
* @param server returned by getServers
|
|
451
452
|
* @returns whether it's synthesized by `@armProviderNamespace`
|
|
@@ -502,7 +503,7 @@ export class CodeModelBuilder {
|
|
|
502
503
|
: undefined,
|
|
503
504
|
},
|
|
504
505
|
});
|
|
505
|
-
codeModelOperation.crossLanguageDefinitionId = getCrossLanguageDefinitionId(operation);
|
|
506
|
+
codeModelOperation.crossLanguageDefinitionId = getCrossLanguageDefinitionId(this.sdkContext, operation);
|
|
506
507
|
codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
|
|
507
508
|
const convenienceApiName = this.getConvenienceApiName(operation);
|
|
508
509
|
let generateConvenienceApi = Boolean(convenienceApiName);
|
|
@@ -567,9 +568,9 @@ export class CodeModelBuilder {
|
|
|
567
568
|
this.addAcceptHeaderParameter(codeModelOperation, op.responses);
|
|
568
569
|
// body
|
|
569
570
|
if (op.parameters.body) {
|
|
570
|
-
if (op.parameters.body.
|
|
571
|
-
if (!isVoidType(op.parameters.body.
|
|
572
|
-
this.processParameterBody(codeModelOperation, op, op.parameters.body.
|
|
571
|
+
if (op.parameters.body.property) {
|
|
572
|
+
if (!isVoidType(op.parameters.body.property.type)) {
|
|
573
|
+
this.processParameterBody(codeModelOperation, op, op.parameters.body.property);
|
|
573
574
|
}
|
|
574
575
|
}
|
|
575
576
|
else if (op.parameters.body.type) {
|
|
@@ -599,8 +600,7 @@ export class CodeModelBuilder {
|
|
|
599
600
|
// lro metadata
|
|
600
601
|
const lroMetadata = this.processLroMetadata(codeModelOperation, op);
|
|
601
602
|
// responses
|
|
602
|
-
|
|
603
|
-
op.responses.map((it) => this.processResponse(codeModelOperation, it, candidateResponseSchema));
|
|
603
|
+
op.responses.map((it) => this.processResponse(codeModelOperation, it, lroMetadata.longRunning));
|
|
604
604
|
// check for paged
|
|
605
605
|
this.processRouteForPaged(codeModelOperation, op.responses);
|
|
606
606
|
// check for long-running operation
|
|
@@ -635,6 +635,7 @@ export class CodeModelBuilder {
|
|
|
635
635
|
}
|
|
636
636
|
processLroMetadata(op, httpOperation) {
|
|
637
637
|
const operation = httpOperation.operation;
|
|
638
|
+
const trackConvenienceApi = Boolean(op.convenienceApi);
|
|
638
639
|
const lroMetadata = getLroMetadata(this.program, operation);
|
|
639
640
|
// needs lroMetadata.statusMonitorStep, as getLroMetadata would return for @pollingOperation operation
|
|
640
641
|
if (lroMetadata && lroMetadata.pollingInfo && lroMetadata.statusMonitorStep) {
|
|
@@ -685,7 +686,7 @@ export class CodeModelBuilder {
|
|
|
685
686
|
// track usage
|
|
686
687
|
if (pollingSchema) {
|
|
687
688
|
this.trackSchemaUsage(pollingSchema, { usage: [SchemaContext.Output] });
|
|
688
|
-
if (
|
|
689
|
+
if (trackConvenienceApi) {
|
|
689
690
|
this.trackSchemaUsage(pollingSchema, {
|
|
690
691
|
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
|
|
691
692
|
});
|
|
@@ -693,7 +694,7 @@ export class CodeModelBuilder {
|
|
|
693
694
|
}
|
|
694
695
|
if (finalSchema) {
|
|
695
696
|
this.trackSchemaUsage(finalSchema, { usage: [SchemaContext.Output] });
|
|
696
|
-
if (
|
|
697
|
+
if (trackConvenienceApi) {
|
|
697
698
|
this.trackSchemaUsage(finalSchema, {
|
|
698
699
|
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
|
|
699
700
|
});
|
|
@@ -758,7 +759,7 @@ export class CodeModelBuilder {
|
|
|
758
759
|
else {
|
|
759
760
|
// schema
|
|
760
761
|
let schema;
|
|
761
|
-
const sdkType = getClientType(this.sdkContext, param.param);
|
|
762
|
+
const sdkType = getNonNullSdkType(getClientType(this.sdkContext, param.param));
|
|
762
763
|
if (param.type === "header" &&
|
|
763
764
|
param.param.type.kind === "Scalar" &&
|
|
764
765
|
getEncode(this.program, param.param) === undefined &&
|
|
@@ -1023,7 +1024,8 @@ export class CodeModelBuilder {
|
|
|
1023
1024
|
schema = this.processSchemaFromSdkType(sdkType, body.name);
|
|
1024
1025
|
}
|
|
1025
1026
|
const isAnonymousModel = sdkType.kind === "model" && sdkType.isGeneratedName === true;
|
|
1026
|
-
const
|
|
1027
|
+
const parameterName = body.kind === "Model" ? (sdkType.kind === "model" ? sdkType.name : "") : this.getName(body);
|
|
1028
|
+
const parameter = new Parameter(parameterName, this.getDoc(body), schema, {
|
|
1027
1029
|
summary: this.getSummary(body),
|
|
1028
1030
|
implementation: ImplementationLocation.Method,
|
|
1029
1031
|
required: body.kind === "Model" || !body.optional,
|
|
@@ -1145,8 +1147,7 @@ export class CodeModelBuilder {
|
|
|
1145
1147
|
// find a type that possibly without http metadata like @statusCode
|
|
1146
1148
|
return this.getEffectiveSchemaType(bodyType);
|
|
1147
1149
|
}
|
|
1148
|
-
processResponse(op, resp,
|
|
1149
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1150
|
+
processResponse(op, resp, longRunning) {
|
|
1150
1151
|
// TODO: what to do if more than 1 response?
|
|
1151
1152
|
// It happens when the response type is Union, on one status code.
|
|
1152
1153
|
let response;
|
|
@@ -1173,7 +1174,7 @@ export class CodeModelBuilder {
|
|
|
1173
1174
|
}
|
|
1174
1175
|
let responseBody = undefined;
|
|
1175
1176
|
let bodyType = undefined;
|
|
1176
|
-
let trackConvenienceApi = (
|
|
1177
|
+
let trackConvenienceApi = Boolean(op.convenienceApi);
|
|
1177
1178
|
if (resp.responses && resp.responses.length > 0 && resp.responses[0].body) {
|
|
1178
1179
|
responseBody = resp.responses[0].body;
|
|
1179
1180
|
}
|
|
@@ -1202,49 +1203,13 @@ export class CodeModelBuilder {
|
|
|
1202
1203
|
else {
|
|
1203
1204
|
// schema (usually JSON)
|
|
1204
1205
|
let schema = undefined;
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
candidateResponseSchema &&
|
|
1209
|
-
candidateResponseSchema instanceof ObjectSchema &&
|
|
1210
|
-
// bodyType is templated Model
|
|
1211
|
-
bodyType.kind === "Model" &&
|
|
1212
|
-
bodyType.templateMapper &&
|
|
1213
|
-
bodyType.templateMapper.args &&
|
|
1214
|
-
bodyType.templateMapper.args.length > 0) {
|
|
1215
|
-
if (verb === "post") {
|
|
1216
|
-
// for LRO ResourceAction, the standard does not require a final type, hence it can be the same as intermediate type
|
|
1217
|
-
// https://github.com/microsoft/api-guidelines/blob/vNext/azure/ConsiderationsForServiceDesign.md#long-running-action-operations
|
|
1218
|
-
// check if we can use candidateResponseSchema as response schema (instead of the templated Model), for LRO ResourceAction
|
|
1219
|
-
if (((_e = candidateResponseSchema.properties) === null || _e === void 0 ? void 0 : _e.length) === bodyType.properties.size) {
|
|
1220
|
-
let match = true;
|
|
1221
|
-
for (const prop of Array.from(bodyType.properties.values())) {
|
|
1222
|
-
const name = this.getName(prop);
|
|
1223
|
-
if (!((_f = candidateResponseSchema.properties) === null || _f === void 0 ? void 0 : _f.find((it) => it.language.default.name === name))) {
|
|
1224
|
-
match = false;
|
|
1225
|
-
break;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
if (match) {
|
|
1229
|
-
schema = candidateResponseSchema;
|
|
1230
|
-
this.trace(`Replace TypeSpec model '${this.getName(bodyType)}' with '${candidateResponseSchema.language.default.name}'`);
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
else if (verb === "delete") {
|
|
1235
|
-
// for LRO ResourceDelete, final type will be replaced to "Void" in convenience API, hence do not generate the class
|
|
1236
|
-
trackConvenienceApi = false;
|
|
1237
|
-
}
|
|
1206
|
+
if (longRunning) {
|
|
1207
|
+
// LRO uses the LroMetadata for poll/final result, not the response of activation request
|
|
1208
|
+
trackConvenienceApi = false;
|
|
1238
1209
|
}
|
|
1239
1210
|
if (!schema) {
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
schema = op.lroMetadata.pollResultType;
|
|
1243
|
-
}
|
|
1244
|
-
else {
|
|
1245
|
-
const sdkType = getClientType(this.sdkContext, bodyType);
|
|
1246
|
-
schema = this.processSchemaFromSdkType(sdkType, op.language.default.name + "Response");
|
|
1247
|
-
}
|
|
1211
|
+
const sdkType = getClientType(this.sdkContext, bodyType);
|
|
1212
|
+
schema = this.processSchemaFromSdkType(sdkType, op.language.default.name + "Response");
|
|
1248
1213
|
}
|
|
1249
1214
|
response = new SchemaResponse(schema, {
|
|
1250
1215
|
protocol: {
|
|
@@ -1443,9 +1408,16 @@ export class CodeModelBuilder {
|
|
|
1443
1408
|
}
|
|
1444
1409
|
processArraySchemaFromSdkType(type, name) {
|
|
1445
1410
|
var _a;
|
|
1446
|
-
|
|
1411
|
+
let nullableItems = false;
|
|
1412
|
+
let elementType = type.valueType;
|
|
1413
|
+
if (elementType.kind === "nullable") {
|
|
1414
|
+
nullableItems = true;
|
|
1415
|
+
elementType = elementType.type;
|
|
1416
|
+
}
|
|
1417
|
+
const elementSchema = this.processSchemaFromSdkType(elementType, name);
|
|
1447
1418
|
return this.codeModel.schemas.add(new ArraySchema(name, (_a = type.details) !== null && _a !== void 0 ? _a : "", elementSchema, {
|
|
1448
1419
|
summary: type.description,
|
|
1420
|
+
nullableItems: nullableItems,
|
|
1449
1421
|
}));
|
|
1450
1422
|
}
|
|
1451
1423
|
processDictionarySchemaFromSdkType(type, name) {
|
|
@@ -1457,20 +1429,26 @@ export class CodeModelBuilder {
|
|
|
1457
1429
|
if (!this.schemaCache.has(type)) {
|
|
1458
1430
|
this.schemaCache.set(type, dictSchema);
|
|
1459
1431
|
}
|
|
1460
|
-
|
|
1432
|
+
let nullableItems = false;
|
|
1433
|
+
let elementType = type.valueType;
|
|
1434
|
+
if (elementType.kind === "nullable") {
|
|
1435
|
+
nullableItems = true;
|
|
1436
|
+
elementType = elementType.type;
|
|
1437
|
+
}
|
|
1438
|
+
const elementSchema = this.processSchemaFromSdkType(elementType, name);
|
|
1461
1439
|
dictSchema.elementType = elementSchema;
|
|
1462
|
-
dictSchema.nullableItems =
|
|
1440
|
+
dictSchema.nullableItems = nullableItems;
|
|
1463
1441
|
return this.codeModel.schemas.add(dictSchema);
|
|
1464
1442
|
}
|
|
1465
1443
|
processChoiceSchemaFromSdkType(type, name) {
|
|
1466
|
-
var _a;
|
|
1444
|
+
var _a, _b;
|
|
1467
1445
|
const rawEnumType = type.__raw;
|
|
1468
1446
|
const namespace = getNamespace(rawEnumType);
|
|
1469
1447
|
const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind);
|
|
1470
1448
|
const choices = [];
|
|
1471
1449
|
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)); });
|
|
1472
1450
|
const schemaType = type.isFixed ? SealedChoiceSchema : ChoiceSchema;
|
|
1473
|
-
const schema = new schemaType(type.name ?
|
|
1451
|
+
const schema = new schemaType((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.details) !== null && _b !== void 0 ? _b : "", {
|
|
1474
1452
|
summary: type.description,
|
|
1475
1453
|
choiceType: valueType,
|
|
1476
1454
|
choices: choices,
|
|
@@ -1487,21 +1465,21 @@ export class CodeModelBuilder {
|
|
|
1487
1465
|
return this.codeModel.schemas.add(schema);
|
|
1488
1466
|
}
|
|
1489
1467
|
processConstantSchemaFromSdkType(type, name) {
|
|
1490
|
-
var _a;
|
|
1468
|
+
var _a, _b;
|
|
1491
1469
|
const valueType = this.processSchemaFromSdkType(type.valueType, type.valueType.kind);
|
|
1492
|
-
return this.codeModel.schemas.add(new ConstantSchema(name, (
|
|
1470
|
+
return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.details) !== null && _b !== void 0 ? _b : "", {
|
|
1493
1471
|
summary: type.description,
|
|
1494
1472
|
valueType: valueType,
|
|
1495
1473
|
value: new ConstantValue(type.value),
|
|
1496
1474
|
}));
|
|
1497
1475
|
}
|
|
1498
1476
|
processConstantSchemaFromEnumValueFromSdkType(type, name) {
|
|
1499
|
-
var _a, _b;
|
|
1477
|
+
var _a, _b, _c;
|
|
1500
1478
|
const valueType = this.processSchemaFromSdkType(type.enumType, type.enumType.name);
|
|
1501
|
-
return this.codeModel.schemas.add(new ConstantSchema(name, (
|
|
1479
|
+
return this.codeModel.schemas.add(new ConstantSchema((_a = type.name) !== null && _a !== void 0 ? _a : name, (_b = type.details) !== null && _b !== void 0 ? _b : "", {
|
|
1502
1480
|
summary: type.description,
|
|
1503
1481
|
valueType: valueType,
|
|
1504
|
-
value: new ConstantValue((
|
|
1482
|
+
value: new ConstantValue((_c = type.value) !== null && _c !== void 0 ? _c : type.name),
|
|
1505
1483
|
}));
|
|
1506
1484
|
}
|
|
1507
1485
|
processUnixTimeSchemaFromSdkType(type, name) {
|
|
@@ -1599,11 +1577,8 @@ export class CodeModelBuilder {
|
|
|
1599
1577
|
keyType: {
|
|
1600
1578
|
kind: "string",
|
|
1601
1579
|
encode: "string",
|
|
1602
|
-
nullable: false,
|
|
1603
1580
|
},
|
|
1604
1581
|
description: type.description,
|
|
1605
|
-
nullableValues: false,
|
|
1606
|
-
nullable: false,
|
|
1607
1582
|
valueType: type.additionalProperties,
|
|
1608
1583
|
};
|
|
1609
1584
|
const parentSchema = this.processSchemaFromSdkType(sdkDictType, "Record");
|
|
@@ -1640,11 +1615,13 @@ export class CodeModelBuilder {
|
|
|
1640
1615
|
}
|
|
1641
1616
|
processModelPropertyFromSdkType(prop) {
|
|
1642
1617
|
var _a;
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1618
|
+
let nullable = false;
|
|
1619
|
+
let nonNullType = prop.type;
|
|
1620
|
+
if (nonNullType.kind === "nullable") {
|
|
1621
|
+
nullable = true;
|
|
1622
|
+
nonNullType = nonNullType.type;
|
|
1623
|
+
}
|
|
1624
|
+
let schema = this.processSchemaFromSdkType(nonNullType, "");
|
|
1648
1625
|
let extensions = undefined;
|
|
1649
1626
|
if (this.isSecret(prop)) {
|
|
1650
1627
|
extensions = extensions !== null && extensions !== void 0 ? extensions : {};
|
|
@@ -1679,7 +1656,6 @@ export class CodeModelBuilder {
|
|
|
1679
1656
|
throw new Error(`Invalid type for union: '${type.kind}'.`);
|
|
1680
1657
|
}
|
|
1681
1658
|
const rawUnionType = type.__raw;
|
|
1682
|
-
// TODO: name from typespec-client-generator-core
|
|
1683
1659
|
const namespace = getNamespace(rawUnionType);
|
|
1684
1660
|
const baseName = (_a = type.name) !== null && _a !== void 0 ? _a : pascalCase(name) + "Model";
|
|
1685
1661
|
this.logWarning(`Convert TypeSpec Union '${getUnionDescription(rawUnionType, this.typeNameOptions)}' to Class '${baseName}'`);
|
|
@@ -1795,9 +1771,6 @@ export class CodeModelBuilder {
|
|
|
1795
1771
|
return target ? getSummary(this.program, target) : undefined;
|
|
1796
1772
|
}
|
|
1797
1773
|
getName(target, nameHint = undefined) {
|
|
1798
|
-
if (!target) {
|
|
1799
|
-
return nameHint || "";
|
|
1800
|
-
}
|
|
1801
1774
|
// 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
|
|
1802
1775
|
const emitterClientName = getClientNameOverride(this.sdkContext, target);
|
|
1803
1776
|
if (emitterClientName && typeof emitterClientName === "string") {
|
|
@@ -1816,21 +1789,6 @@ export class CodeModelBuilder {
|
|
|
1816
1789
|
if (friendlyName) {
|
|
1817
1790
|
return friendlyName;
|
|
1818
1791
|
}
|
|
1819
|
-
// if no projectedName and friendlyName found, return the name of the target (including special handling for template)
|
|
1820
|
-
if (target.kind === "Model" &&
|
|
1821
|
-
target.templateMapper &&
|
|
1822
|
-
target.templateMapper.args &&
|
|
1823
|
-
target.templateMapper.args.length > 0) {
|
|
1824
|
-
const tspName = getTypeName(target, this.typeNameOptions);
|
|
1825
|
-
const newName = getNameForTemplate(target);
|
|
1826
|
-
this.logWarning(`Rename TypeSpec Model '${tspName}' to '${newName}'`);
|
|
1827
|
-
return newName;
|
|
1828
|
-
}
|
|
1829
|
-
if (!target.name && nameHint) {
|
|
1830
|
-
const newName = nameHint;
|
|
1831
|
-
this.logWarning(`Rename anonymous TypeSpec ${target.kind} to '${newName}'`);
|
|
1832
|
-
return newName;
|
|
1833
|
-
}
|
|
1834
1792
|
if (typeof target.name === "symbol") {
|
|
1835
1793
|
return "";
|
|
1836
1794
|
}
|