@azure-tools/typespec-java 0.27.3 → 0.27.4

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.
@@ -1,4 +1,4 @@
1
- import { AnySchema, BinarySchema, BooleanSchema, NumberSchema, ObjectSchema, Parameter, Schema, StringSchema } from "@autorest/codemodel";
1
+ import { AnySchema, BinarySchema, BooleanSchema, NumberSchema, ObjectSchema, Schema, StringSchema } from "@autorest/codemodel";
2
2
  import { SdkType } from "@azure-tools/typespec-client-generator-core";
3
3
  import { EmitContext, Program, Type, Union } from "@typespec/compiler";
4
4
  import { CodeModel } from "./common/code-model.js";
@@ -50,8 +50,11 @@ export declare class CodeModelBuilder {
50
50
  private processRouteForPaged;
51
51
  private processLroMetadata;
52
52
  private processRouteForLongRunning;
53
- private _armApiVersionParameter?;
54
53
  private processParameter;
54
+ private processParameterGrouping;
55
+ private processSdkMethodOverride;
56
+ private processGroupSchema;
57
+ private checkGroupingAfterBodyParameterFlatten;
55
58
  private processEtagHeaderParameters;
56
59
  private processParameterBody;
57
60
  private addParameterOrBodyPropertyToCodeModelRequest;
@@ -109,9 +112,10 @@ export declare class CodeModelBuilder {
109
112
  get pollResultSchema(): ObjectSchema;
110
113
  private createApiVersionParameter;
111
114
  private _apiVersionParameter?;
112
- get apiVersionParameter(): Parameter;
113
115
  private _apiVersionParameterInPath?;
114
- get apiVersionParameterInPath(): Parameter;
116
+ private _apiVersionParameterInHeader?;
117
+ private _armApiVersionParameter?;
118
+ private getApiVersionParameter;
115
119
  private isSubscriptionId;
116
120
  private subscriptionIdParameter;
117
121
  private _subscriptionParameter?;
@@ -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,qBAA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oiceValue, 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
2
  import { KnownMediaType } from "@azure-tools/codegen";
3
- import { createSdkContext, getAllModels, isApiVersion, isSdkBuiltInKind, isSdkIntKind, } from "@azure-tools/typespec-client-generator-core";
3
+ import { createSdkContext, getAllModels, getHttpOperationParameter, isSdkBuiltInKind, isSdkIntKind, } from "@azure-tools/typespec-client-generator-core";
4
4
  import { NoTarget, getDoc, getNamespaceFullName, getOverloadedOperation, getSummary, isArrayModelType, isRecordModelType, listServices, } from "@typespec/compiler";
5
5
  import { Visibility, getAuthentication, } from "@typespec/http";
6
6
  import { getSegment } from "@typespec/rest";
@@ -17,7 +17,7 @@ import { OrSchema } from "./common/schemas/relationship.js";
17
17
  import { DurationSchema } from "./common/schemas/time.js";
18
18
  import { SchemaContext } from "./common/schemas/usage.js";
19
19
  import { createPollOperationDetailsSchema, getFileDetailsSchema } from "./external-schemas.js";
20
- import { createDiagnostic, reportDiagnostic } from "./lib.js";
20
+ import { LIB_NAME, createDiagnostic, reportDiagnostic } from "./lib.js";
21
21
  import { ClientContext } from "./models.js";
22
22
  import { CONTENT_TYPE_KEY, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, cloneOperationParameter, getServiceVersion, isKnownContentType, isLroNewPollingStrategy, operationIsJsonMergePatch, operationIsMultipart, operationIsMultipleContentTypes, } from "./operation-utils.js";
23
23
  import { ProcessingCache, getAccess, getDurationFormat, getNonNullSdkType, getPropertySerializedName, getUnionDescription, getUsage, modelIs, pushDistinct, } from "./type-utils.js";
@@ -73,7 +73,8 @@ export class CodeModelBuilder {
73
73
  if (this.program.hasError()) {
74
74
  return this.codeModel;
75
75
  }
76
- this.sdkContext = await createSdkContext(this.emitterContext, "@azure-tools/typespec-java", {
76
+ this.sdkContext = await createSdkContext(this.emitterContext, LIB_NAME, {
77
+ additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@override"],
77
78
  versioning: { previewStringRegex: /$/ },
78
79
  }); // include all versions and do the filter by ourselves
79
80
  // java namespace
@@ -684,12 +685,12 @@ export class CodeModelBuilder {
684
685
  this.processParameter(codeModelOperation, param, clientContext);
685
686
  }
686
687
  // body
688
+ let bodyParameterFlattened = false;
687
689
  if (httpOperation.bodyParam && httpOperation.__raw && httpOperation.bodyParam.type.__raw) {
688
- this.processParameterBody(codeModelOperation, httpOperation.__raw, httpOperation, httpOperation.bodyParam);
690
+ bodyParameterFlattened = this.processParameterBody(codeModelOperation, sdkMethod, httpOperation.bodyParam);
689
691
  }
690
- // group ETag header parameters, if exists
691
- if (this.options["group-etag-headers"]) {
692
- this.processEtagHeaderParameters(codeModelOperation, sdkMethod.operation);
692
+ if (generateConvenienceApi) {
693
+ this.processParameterGrouping(codeModelOperation, sdkMethod, bodyParameterFlattened);
693
694
  }
694
695
  // lro metadata
695
696
  let lroMetadata = new LongRunningMetadata(false);
@@ -755,7 +756,6 @@ export class CodeModelBuilder {
755
756
  }
756
757
  }
757
758
  processLroMetadata(op, sdkMethod) {
758
- var _a;
759
759
  const trackConvenienceApi = Boolean(op.convenienceApi);
760
760
  const lroMetadata = sdkMethod.lroMetadata;
761
761
  if (lroMetadata && lroMetadata.pollingStep) {
@@ -799,21 +799,9 @@ export class CodeModelBuilder {
799
799
  if (useNewPollStrategy &&
800
800
  lroMetadata.finalStep &&
801
801
  lroMetadata.finalStep.kind === "pollingSuccessProperty" &&
802
- lroMetadata.finalResponse.resultPath) {
803
- const finalResultPropertyClientName = lroMetadata.finalResponse.resultPath;
804
- // find serializedName for lro result
805
- if (finalResultPropertyClientName) {
806
- (_a = lroMetadata.finalResponse.envelopeResult.properties) === null || _a === void 0 ? void 0 : _a.forEach((p) => {
807
- var _a, _b, _c;
808
- // TODO: "p.__raw?.name" should be "p.name", after TCGC fix https://github.com/Azure/typespec-azure/issues/2072
809
- if (!finalResultPropertySerializedName &&
810
- p.kind === "property" &&
811
- ((_a = p.serializationOptions.json) === null || _a === void 0 ? void 0 : _a.name) &&
812
- ((_b = p.__raw) === null || _b === void 0 ? void 0 : _b.name) === finalResultPropertyClientName) {
813
- finalResultPropertySerializedName = (_c = p.serializationOptions.json) === null || _c === void 0 ? void 0 : _c.name;
814
- }
815
- });
816
- }
802
+ lroMetadata.finalResponse.resultSegments &&
803
+ lroMetadata.finalResponse.resultSegments[0].kind === "property") {
804
+ finalResultPropertySerializedName = getPropertySerializedName(lroMetadata.finalResponse.resultSegments[0]);
817
805
  }
818
806
  }
819
807
  // track usage
@@ -848,7 +836,7 @@ export class CodeModelBuilder {
848
836
  }
849
837
  processParameter(op, param, clientContext) {
850
838
  var _a, _b, _c;
851
- if (clientContext.apiVersions && isApiVersion(this.sdkContext, param)) {
839
+ if (clientContext.apiVersions && param.isApiVersionParam && param.kind !== "cookie") {
852
840
  // pre-condition for "isApiVersion": the client supports ApiVersions
853
841
  if (this.isArm()) {
854
842
  // Currently we assume ARM tsp only have one client and one api-version.
@@ -861,7 +849,7 @@ export class CodeModelBuilder {
861
849
  op.addParameter(this._armApiVersionParameter);
862
850
  }
863
851
  else {
864
- const parameter = param.kind === "query" ? this.apiVersionParameter : this.apiVersionParameterInPath;
852
+ const parameter = this.getApiVersionParameter(param);
865
853
  op.addParameter(parameter);
866
854
  clientContext.addGlobalParameter(parameter);
867
855
  }
@@ -988,6 +976,182 @@ export class CodeModelBuilder {
988
976
  }
989
977
  }
990
978
  }
979
+ processParameterGrouping(op, sdkMethod, bodyParameterFlattened) {
980
+ const httpOperation = sdkMethod.operation;
981
+ const methodSignatureOverridden = sdkMethod.decorators.some((it) => it.name === "Azure.ClientGenerator.Core.@override");
982
+ if (methodSignatureOverridden) {
983
+ // limit the effect of "SdkServiceMethod"
984
+ // only process it and its parameters, when the "@override" is defined on the operation
985
+ this.processSdkMethodOverride(op, sdkMethod);
986
+ }
987
+ else if (bodyParameterFlattened) {
988
+ // only do this, if no explicit method override via "@override"
989
+ this.checkGroupingAfterBodyParameterFlatten(op);
990
+ }
991
+ // group ETag header parameters, if exists
992
+ if (this.options["group-etag-headers"]) {
993
+ // TODO: unsure what happens, if the etag headers is already processed by override
994
+ this.processEtagHeaderParameters(op, httpOperation);
995
+ }
996
+ }
997
+ processSdkMethodOverride(op, sdkMethod) {
998
+ var _a, _b, _c;
999
+ // method be called, only if "op.convenienceApi"
1000
+ let request = (_b = (_a = op.convenienceApi) === null || _a === void 0 ? void 0 : _a.requests) === null || _b === void 0 ? void 0 : _b[0];
1001
+ let requestParameters;
1002
+ if (request) {
1003
+ requestParameters = request.parameters;
1004
+ }
1005
+ else {
1006
+ op.convenienceApi.requests = [];
1007
+ request = new Request({
1008
+ protocol: op.requests[0].protocol,
1009
+ });
1010
+ op.convenienceApi.requests.push(request);
1011
+ requestParameters = op.parameters;
1012
+ }
1013
+ request.parameters = [];
1014
+ request.signatureParameters = [];
1015
+ function findOperationParameter(parameter) {
1016
+ let opParameter;
1017
+ // ignore constant parameter, usually the "accept" and "content-type" header
1018
+ if (parameter.type.kind !== "constant") {
1019
+ if (parameter.kind === "body") {
1020
+ // there should be only 1 body parameter
1021
+ opParameter = requestParameters.find((it) => { var _a; return ((_a = it.protocol.http) === null || _a === void 0 ? void 0 : _a.in) === "body"; });
1022
+ }
1023
+ else if (parameter.kind === "property") {
1024
+ // body property
1025
+ // if body property appears on method signature, it should already be flattened, hence the check on VirtualParameter
1026
+ opParameter = requestParameters.find((it) => it instanceof VirtualParameter &&
1027
+ it.language.default.serializedName === getPropertySerializedName(parameter));
1028
+ }
1029
+ else {
1030
+ // query, path, header
1031
+ opParameter = requestParameters.find((it) => {
1032
+ var _a;
1033
+ return ((_a = it.protocol.http) === null || _a === void 0 ? void 0 : _a.in) === parameter.kind &&
1034
+ it.language.default.serializedName === parameter.serializedName;
1035
+ });
1036
+ }
1037
+ }
1038
+ return opParameter;
1039
+ }
1040
+ for (const sdkMethodParameter of sdkMethod.parameters) {
1041
+ let httpOperationParameter = getHttpOperationParameter(sdkMethod, sdkMethodParameter);
1042
+ if (httpOperationParameter) {
1043
+ const opParameter = findOperationParameter(httpOperationParameter);
1044
+ if (opParameter) {
1045
+ request.signatureParameters.push(opParameter);
1046
+ request.parameters.push(opParameter);
1047
+ }
1048
+ }
1049
+ else {
1050
+ // sdkMethodParameter is a grouping parameter
1051
+ if (sdkMethodParameter.type.kind === "model") {
1052
+ const opParameters = [];
1053
+ for (const property of sdkMethodParameter.type.properties) {
1054
+ httpOperationParameter = getHttpOperationParameter(sdkMethod, property);
1055
+ if (httpOperationParameter) {
1056
+ const opParameter = findOperationParameter(httpOperationParameter);
1057
+ if (opParameter) {
1058
+ if (opParameter instanceof VirtualParameter) {
1059
+ opParameters.push(opParameter);
1060
+ }
1061
+ else {
1062
+ opParameters.push(opParameter);
1063
+ }
1064
+ }
1065
+ }
1066
+ }
1067
+ // group schema
1068
+ const groupSchema = this.processGroupSchema(sdkMethodParameter.type, opParameters, sdkMethodParameter.type.name);
1069
+ this.trackSchemaUsage(groupSchema, { usage: [SchemaContext.Input] });
1070
+ if (op.convenienceApi) {
1071
+ this.trackSchemaUsage(groupSchema, {
1072
+ usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
1073
+ });
1074
+ }
1075
+ // group parameter
1076
+ const groupParameter = new Parameter(sdkMethodParameter.name, (_c = sdkMethodParameter.doc) !== null && _c !== void 0 ? _c : "", groupSchema, {
1077
+ summary: sdkMethodParameter.summary,
1078
+ implementation: ImplementationLocation.Method,
1079
+ required: !sdkMethodParameter.optional,
1080
+ nullable: false,
1081
+ });
1082
+ request.signatureParameters.push(groupParameter);
1083
+ request.parameters.push(...opParameters);
1084
+ request.parameters.push(groupParameter);
1085
+ opParameters.forEach((it) => {
1086
+ it.groupedBy = groupParameter;
1087
+ });
1088
+ }
1089
+ }
1090
+ }
1091
+ }
1092
+ processGroupSchema(type, parameters, name, description = undefined) {
1093
+ // the "GroupSchema" is simliar to "ObjectSchema", but the process is different
1094
+ var _a, _b;
1095
+ if (type && this.schemaCache.has(type)) {
1096
+ return this.schemaCache.get(type);
1097
+ }
1098
+ // option bag schema
1099
+ const optionBagSchema = this.codeModel.schemas.add(new GroupSchema(name, (_b = (_a = type === null || type === void 0 ? void 0 : type.doc) !== null && _a !== void 0 ? _a : description) !== null && _b !== void 0 ? _b : "", {
1100
+ summary: type === null || type === void 0 ? void 0 : type.summary,
1101
+ language: {
1102
+ default: {
1103
+ namespace: type ? getNamespace(type.__raw) : this.namespace,
1104
+ },
1105
+ java: {
1106
+ namespace: this.getJavaNamespace(type),
1107
+ },
1108
+ },
1109
+ }));
1110
+ parameters.forEach((it) => {
1111
+ optionBagSchema.add(new GroupProperty(it.language.default.name, it.language.default.description, it.schema, {
1112
+ originalParameter: [it],
1113
+ summary: it.summary,
1114
+ required: it.required,
1115
+ nullable: it.nullable,
1116
+ readOnly: false,
1117
+ serializedName: it.language.default.serializedName,
1118
+ }));
1119
+ });
1120
+ if (type) {
1121
+ // on cache: the GroupProperty actually has a reference to "originalParameter" (though on same type, the parameter should be identical)
1122
+ this.schemaCache.set(type, optionBagSchema);
1123
+ }
1124
+ return optionBagSchema;
1125
+ }
1126
+ checkGroupingAfterBodyParameterFlatten(op) {
1127
+ var _a, _b;
1128
+ // method be called, only if "op.convenienceApi" is defined
1129
+ // method signature of the convenience API after body parameter flatten
1130
+ const request = (_b = (_a = op.convenienceApi) === null || _a === void 0 ? void 0 : _a.requests) === null || _b === void 0 ? void 0 : _b[0];
1131
+ if (request &&
1132
+ request.signatureParameters &&
1133
+ request.parameters &&
1134
+ request.signatureParameters.length > 6) {
1135
+ // create an option bag
1136
+ const name = op.language.default.name + "Options";
1137
+ const optionBagSchema = this.processGroupSchema(undefined, request.parameters, name, `Options for ${op.language.default.name} API`);
1138
+ this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Input] });
1139
+ if (op.convenienceApi) {
1140
+ this.trackSchemaUsage(optionBagSchema, {
1141
+ usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
1142
+ });
1143
+ }
1144
+ // option bag parameter
1145
+ const optionBagParameter = new Parameter("options", optionBagSchema.language.default.description, optionBagSchema, {
1146
+ implementation: ImplementationLocation.Method,
1147
+ required: true,
1148
+ nullable: false,
1149
+ });
1150
+ request.signatureParameters = [optionBagParameter];
1151
+ request.parameters.forEach((it) => (it.groupedBy = optionBagParameter));
1152
+ request.parameters.push(optionBagParameter);
1153
+ }
1154
+ }
991
1155
  processEtagHeaderParameters(op, httpOperation) {
992
1156
  if (op.convenienceApi && op.parameters && op.signatureParameters) {
993
1157
  const etagHeadersNames = new Set([
@@ -1090,8 +1254,10 @@ export class CodeModelBuilder {
1090
1254
  }
1091
1255
  }
1092
1256
  }
1093
- processParameterBody(op, rawHttpOperation, sdkHttpOperation, sdkBody) {
1257
+ processParameterBody(op, sdkMethod, sdkBody) {
1094
1258
  var _a, _b, _c;
1259
+ let bodyParameterFlattened = false;
1260
+ const sdkHttpOperation = sdkMethod.operation;
1095
1261
  // set contentTypes to mediaTypes
1096
1262
  op.requests[0].protocol.http.mediaTypes = sdkBody.contentTypes;
1097
1263
  const unknownRequestBody = op.requests[0].protocol.http.mediaTypes &&
@@ -1133,13 +1299,19 @@ export class CodeModelBuilder {
1133
1299
  this.trackSchemaUsage(schema, { serializationFormats: [KnownMediaType.Multipart] });
1134
1300
  }
1135
1301
  if (op.convenienceApi) {
1136
- // Explicit body parameter @body or @bodyRoot would result to the existence of rawHttpOperation.parameters.body.property
1137
- // Implicit body parameter would result to rawHttpOperation.parameters.body.property be undefined
1138
- // see https://typespec.io/docs/libraries/http/cheat-sheet#data-types
1139
- const bodyParameterFlatten = schema instanceof ObjectSchema &&
1302
+ /**
1303
+ * Explicit body parameter @body or @bodyRoot would result to the existence of rawHttpOperation.parameters.body.property
1304
+ * Implicit body parameter would result to rawHttpOperation.parameters.body.property be undefined
1305
+ * see https://typespec.io/docs/libraries/http/cheat-sheet#data-types
1306
+ */
1307
+ /**
1308
+ * In TCGC, the condition is 'sdkType.kind === "model" && sdkBody.type !== sdkBody.correspondingMethodParams[0]?.type'.
1309
+ * Basically, it means that the model of the SDK method parameters (typically, more than 1) be different from the model of this single HTTP body parameter.
1310
+ */
1311
+ const bodyParameterFlatten = !this.isArm() &&
1312
+ schema instanceof ObjectSchema &&
1140
1313
  sdkType.kind === "model" &&
1141
- !((_c = rawHttpOperation.parameters.body) === null || _c === void 0 ? void 0 : _c.property) &&
1142
- !this.isArm();
1314
+ sdkBody.type !== ((_c = sdkBody.correspondingMethodParams[0]) === null || _c === void 0 ? void 0 : _c.type);
1143
1315
  if (schema instanceof ObjectSchema && bodyParameterFlatten) {
1144
1316
  // flatten body parameter
1145
1317
  const parameters = sdkHttpOperation.parameters;
@@ -1153,8 +1325,10 @@ export class CodeModelBuilder {
1153
1325
  if (sdkType.isGeneratedName) {
1154
1326
  schema.language.default.name = pascalCase(op.language.default.name) + "PatchRequest";
1155
1327
  }
1156
- return;
1328
+ return bodyParameterFlattened;
1157
1329
  }
1330
+ // flatten body parameter
1331
+ bodyParameterFlattened = true;
1158
1332
  const schemaUsage = schema.usage;
1159
1333
  if (!schemaIsPublicBeforeProcess && (schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.includes(SchemaContext.Public))) {
1160
1334
  // Public added in this op, change it to PublicSpread
@@ -1162,72 +1336,30 @@ export class CodeModelBuilder {
1162
1336
  schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.splice(schemaUsage === null || schemaUsage === void 0 ? void 0 : schemaUsage.indexOf(SchemaContext.Public), 1);
1163
1337
  this.trackSchemaUsage(schema, { usage: [SchemaContext.PublicSpread] });
1164
1338
  }
1165
- if (op.convenienceApi && op.parameters) {
1166
- op.convenienceApi.requests = [];
1167
- const request = new Request({
1168
- protocol: op.requests[0].protocol,
1169
- });
1170
- request.parameters = [];
1171
- op.convenienceApi.requests.push(request);
1172
- // header/query/path params
1173
- for (const opParameter of parameters) {
1174
- this.addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, parameter);
1175
- }
1176
- // body param
1177
- if (bodyParameter) {
1178
- if (bodyParameter.type.kind === "model") {
1179
- for (const bodyProperty of bodyParameter.type.properties) {
1180
- if (bodyProperty.kind === "property") {
1181
- this.addParameterOrBodyPropertyToCodeModelRequest(bodyProperty, op, request, schema, parameter);
1182
- }
1339
+ op.convenienceApi.requests = [];
1340
+ const request = new Request({
1341
+ protocol: op.requests[0].protocol,
1342
+ });
1343
+ request.parameters = [];
1344
+ op.convenienceApi.requests.push(request);
1345
+ // header/query/path params
1346
+ for (const opParameter of parameters) {
1347
+ this.addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, parameter);
1348
+ }
1349
+ // body param
1350
+ if (bodyParameter) {
1351
+ if (bodyParameter.type.kind === "model") {
1352
+ for (const bodyProperty of bodyParameter.type.properties) {
1353
+ if (bodyProperty.kind === "property") {
1354
+ this.addParameterOrBodyPropertyToCodeModelRequest(bodyProperty, op, request, schema, parameter);
1183
1355
  }
1184
1356
  }
1185
1357
  }
1186
- request.signatureParameters = request.parameters;
1187
- if (request.signatureParameters.length > 6) {
1188
- // create an option bag
1189
- const name = op.language.default.name + "Options";
1190
- const namespace = getNamespace(rawHttpOperation.operation);
1191
- // option bag schema
1192
- const optionBagSchema = this.codeModel.schemas.add(new GroupSchema(name, `Options for ${op.language.default.name} API`, {
1193
- language: {
1194
- default: {
1195
- namespace: namespace,
1196
- },
1197
- java: {
1198
- namespace: this.getJavaNamespace(),
1199
- },
1200
- },
1201
- }));
1202
- request.parameters.forEach((it) => {
1203
- optionBagSchema.add(new GroupProperty(it.language.default.name, it.language.default.description, it.schema, {
1204
- originalParameter: [it],
1205
- summary: it.summary,
1206
- required: it.required,
1207
- nullable: it.nullable,
1208
- readOnly: false,
1209
- serializedName: it.language.default.serializedName,
1210
- }));
1211
- });
1212
- this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Input] });
1213
- if (op.convenienceApi) {
1214
- this.trackSchemaUsage(optionBagSchema, {
1215
- usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
1216
- });
1217
- }
1218
- // option bag parameter
1219
- const optionBagParameter = new Parameter("options", optionBagSchema.language.default.description, optionBagSchema, {
1220
- implementation: ImplementationLocation.Method,
1221
- required: true,
1222
- nullable: false,
1223
- });
1224
- request.signatureParameters = [optionBagParameter];
1225
- request.parameters.forEach((it) => (it.groupedBy = optionBagParameter));
1226
- request.parameters.push(optionBagParameter);
1227
- }
1228
1358
  }
1359
+ request.signatureParameters = request.parameters;
1229
1360
  }
1230
1361
  }
1362
+ return bodyParameterFlattened;
1231
1363
  }
1232
1364
  addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, originalParameter) {
1233
1365
  var _a, _b, _c, _d, _e;
@@ -2092,14 +2224,22 @@ export class CodeModelBuilder {
2092
2224
  },
2093
2225
  });
2094
2226
  }
2095
- get apiVersionParameter() {
2096
- return (this._apiVersionParameter ||
2097
- (this._apiVersionParameter = this.createApiVersionParameter("api-version", ParameterLocation.Query)));
2098
- }
2099
- get apiVersionParameterInPath() {
2100
- return (this._apiVersionParameterInPath ||
2101
- // TODO: hardcode as "apiVersion", as it is what we get from compiler
2102
- (this._apiVersionParameterInPath = this.createApiVersionParameter("apiVersion", ParameterLocation.Path)));
2227
+ getApiVersionParameter(param) {
2228
+ // apiVersionParameter is cached by param.kind
2229
+ // we didn't expect Azure service have more than 1 type of api-version, and certainly not more than 1 of each kind.
2230
+ if (param.kind === "query") {
2231
+ return (this._apiVersionParameter ||
2232
+ (this._apiVersionParameter = this.createApiVersionParameter(param.serializedName, ParameterLocation.Query)));
2233
+ }
2234
+ else if (param.kind === "path") {
2235
+ return (this._apiVersionParameterInPath ||
2236
+ (this._apiVersionParameterInPath = this.createApiVersionParameter(param.serializedName, ParameterLocation.Path)));
2237
+ }
2238
+ else {
2239
+ // param.kind === "header"
2240
+ return (this._apiVersionParameterInHeader ||
2241
+ (this._apiVersionParameterInHeader = this.createApiVersionParameter(param.serializedName, ParameterLocation.Header)));
2242
+ }
2103
2243
  }
2104
2244
  isSubscriptionId(param) {
2105
2245
  return "subscriptionId".toLocaleLowerCase() === param.serializedName.toLocaleLowerCase();