@azure-tools/typespec-java 0.8.13 → 0.10.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 +80 -39
- package/dist/src/code-model-builder.js.map +1 -1
- package/dist/src/emitter.d.ts +2 -2
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +7 -2
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/operation-utils.d.ts +5 -2
- package/dist/src/operation-utils.d.ts.map +1 -1
- package/dist/src/operation-utils.js +33 -6
- package/dist/src/operation-utils.js.map +1 -1
- package/dist/src/prenamer/formatter.d.ts +11 -0
- package/dist/src/prenamer/formatter.d.ts.map +1 -0
- package/dist/src/prenamer/formatter.js +124 -0
- package/dist/src/prenamer/formatter.js.map +1 -0
- package/dist/src/prenamer/naming-utils.d.ts +1 -1
- package/dist/src/prenamer/naming-utils.d.ts.map +1 -1
- package/dist/src/prenamer/naming-utils.js +2 -1
- package/dist/src/prenamer/naming-utils.js.map +1 -1
- package/dist/src/prenamer/prenamer.d.ts +1 -1
- package/dist/src/prenamer/prenamer.d.ts.map +1 -1
- package/dist/src/prenamer/prenamer.js +2 -1
- package/dist/src/prenamer/prenamer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/target/azure-typespec-extension-jar-with-dependencies.jar +0 -0
|
@@ -33,7 +33,7 @@ export declare class CodeModelBuilder {
|
|
|
33
33
|
private processParameterBody;
|
|
34
34
|
private findResponseBody;
|
|
35
35
|
private processResponse;
|
|
36
|
-
private
|
|
36
|
+
private getStatusCodes;
|
|
37
37
|
private getResponseDescription;
|
|
38
38
|
private processSchema;
|
|
39
39
|
private processSchemaImpl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-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BAAsB;IAe9B,OAAO,CAAC,4BAA4B;IAgEpC,OAAO,CAAC,oBAAoB;IAwB5B,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,kBAAkB;IAkD1B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,mBAAmB;IAyC3B,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,OAAO;IAyCf,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,IAAI,YAAY,IAAI,YAAY,CAK/B;IAED,OAAO,CAAC,cAAc,CAAC,CAAe;IACtC,IAAI,aAAa,IAAI,YAAY,CAOhC;IAED,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,IAAI,aAAa,IAAI,aAAa,CAKjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAY;IAC/B,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED,OAAO,CAAC,iBAAiB,CAAC,CAAe;IACzC,IAAI,gBAAgB,IAAI,YAAY,CAKnC;IAED,OAAO,CAAC,yBAAyB;IA0BjC,OAAO,CAAC,oBAAoB,CAAC,CAAY;IACzC,IAAI,mBAAmB,IAAI,SAAS,CAKnC;IAED,OAAO,CAAC,0BAA0B,CAAC,CAAY;IAC/C,IAAI,yBAAyB,IAAI,SAAS,CAMzC;IAED,OAAO,CAAC,oBAAoB;IA+D5B,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,kBAAkB;CAiB3B"}
|
|
@@ -20,7 +20,7 @@ import { createPollResultSchema } from "./external-schemas.js";
|
|
|
20
20
|
import { ClientContext } from "./models.js";
|
|
21
21
|
import { stringArrayContainsIgnoreCase, getJavaNamespace, getNamespace, pascalCase, logWarning, trace, } from "./utils.js";
|
|
22
22
|
import { ProcessingCache, isModelReferredInTemplate, pushDistinct, modelContainsDerivedModel, getNameForTemplate, getDurationFormat, hasScalarAsBase, isNullableType, isSameLiteralTypes, getAccess, getUsage, unionReferredByType, getUnionName, modelIs, } from "./type-utils.js";
|
|
23
|
-
import { getClientApiVersions, getServiceVersion, operationIsJsonMergePatch, isPayloadProperty,
|
|
23
|
+
import { getClientApiVersions, getServiceVersion, operationIsJsonMergePatch, isPayloadProperty, ORIGIN_API_VERSION, SPECIAL_HEADER_NAMES, loadExamples, isLroNewPollingStrategy, operationIsMultipleContentTypes, cloneOperationParameter, operationRefersUnion, operationIsMultipart, isKnownContentType, CONTENT_TYPE_KEY, } from "./operation-utils.js";
|
|
24
24
|
import pkg from "lodash";
|
|
25
25
|
const { isEqual } = pkg;
|
|
26
26
|
export class CodeModelBuilder {
|
|
@@ -32,7 +32,7 @@ export class CodeModelBuilder {
|
|
|
32
32
|
this.options = context.options;
|
|
33
33
|
this.program = program1;
|
|
34
34
|
if (this.options["skip-special-headers"]) {
|
|
35
|
-
this.options["skip-special-headers"].forEach((it) =>
|
|
35
|
+
this.options["skip-special-headers"].forEach((it) => SPECIAL_HEADER_NAMES.add(it.toLowerCase()));
|
|
36
36
|
}
|
|
37
37
|
this.sdkContext = createSdkContext(context);
|
|
38
38
|
const service = listServices(this.program)[0];
|
|
@@ -194,7 +194,8 @@ export class CodeModelBuilder {
|
|
|
194
194
|
return access === "internal";
|
|
195
195
|
}
|
|
196
196
|
else {
|
|
197
|
-
//
|
|
197
|
+
// TODO: deprecate "internal"
|
|
198
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
198
199
|
return isInternal(context, operation);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
@@ -203,20 +204,24 @@ export class CodeModelBuilder {
|
|
|
203
204
|
for (const client of clients) {
|
|
204
205
|
const models = Array.from(client.service.models.values());
|
|
205
206
|
Array.from(client.service.enums.values()).forEach((it) => models.push(it));
|
|
207
|
+
// lambda to mark model as public
|
|
208
|
+
const modelAsPublic = (model) => {
|
|
209
|
+
// check it does not contain Union
|
|
210
|
+
const union = unionReferredByType(this.program, model, this.typeUnionRefCache);
|
|
211
|
+
if (union) {
|
|
212
|
+
const errorMsg = `Model '${getTypeName(model, this.typeNameOptions)}' cannot be set as access=public, as it refers Union '${getUnionName(union, this.typeNameOptions)}'`;
|
|
213
|
+
throw new Error(errorMsg);
|
|
214
|
+
}
|
|
215
|
+
const schema = this.processSchema(model, model.name);
|
|
216
|
+
this.trackSchemaUsage(schema, {
|
|
217
|
+
usage: [SchemaContext.Public],
|
|
218
|
+
});
|
|
219
|
+
};
|
|
206
220
|
for (const model of models) {
|
|
207
221
|
if (!processedModels.has(model)) {
|
|
208
222
|
const access = getAccess(model);
|
|
209
223
|
if (access === "public") {
|
|
210
|
-
|
|
211
|
-
const union = unionReferredByType(this.program, model, this.typeUnionRefCache);
|
|
212
|
-
if (union) {
|
|
213
|
-
const errorMsg = `Model '${getTypeName(model, this.typeNameOptions)}' cannot be set as access=public, as it refers Union '${getUnionName(union, this.typeNameOptions)}'`;
|
|
214
|
-
throw new Error(errorMsg);
|
|
215
|
-
}
|
|
216
|
-
const schema = this.processSchema(model, model.name);
|
|
217
|
-
this.trackSchemaUsage(schema, {
|
|
218
|
-
usage: [SchemaContext.Public],
|
|
219
|
-
});
|
|
224
|
+
modelAsPublic(model);
|
|
220
225
|
}
|
|
221
226
|
else if (access === "internal") {
|
|
222
227
|
const schema = this.processSchema(model, model.name);
|
|
@@ -395,11 +400,9 @@ export class CodeModelBuilder {
|
|
|
395
400
|
: undefined,
|
|
396
401
|
},
|
|
397
402
|
});
|
|
398
|
-
|
|
399
|
-
// codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
|
|
400
|
-
const internalApi = this.isInternal(this.sdkContext, operation);
|
|
403
|
+
codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
|
|
401
404
|
const convenienceApiName = this.getConvenienceApiName(operation);
|
|
402
|
-
let generateConvenienceApi = !!convenienceApiName
|
|
405
|
+
let generateConvenienceApi = !!convenienceApiName;
|
|
403
406
|
let apiComment = undefined;
|
|
404
407
|
if (generateConvenienceApi) {
|
|
405
408
|
// check if the convenience API need to be disabled for some special cases
|
|
@@ -409,6 +412,14 @@ export class CodeModelBuilder {
|
|
|
409
412
|
apiComment = `Convenience API is not generated, as operation '${op.operation.name}' is 'application/merge-patch+json'`;
|
|
410
413
|
this.logWarning(apiComment);
|
|
411
414
|
}
|
|
415
|
+
else if (operationIsMultipart(op)) {
|
|
416
|
+
// do not generate convenience method for multipart/form-data
|
|
417
|
+
generateConvenienceApi = false;
|
|
418
|
+
// make it internal
|
|
419
|
+
codeModelOperation.internalApi = true;
|
|
420
|
+
apiComment = `Protocol API requires serialization of parts with content-disposition and data, as operation '${op.operation.name}' is 'multipart/form-data'`;
|
|
421
|
+
this.logWarning(apiComment);
|
|
422
|
+
}
|
|
412
423
|
else if (operationIsMultipleContentTypes(op)) {
|
|
413
424
|
// and multiple content types
|
|
414
425
|
// issue link: https://github.com/Azure/autorest.java/issues/1958#issuecomment-1562558219
|
|
@@ -435,7 +446,7 @@ export class CodeModelBuilder {
|
|
|
435
446
|
}
|
|
436
447
|
// check for generating protocol api or not
|
|
437
448
|
codeModelOperation.generateProtocolApi =
|
|
438
|
-
shouldGenerateProtocol(this.sdkContext, operation) && !
|
|
449
|
+
shouldGenerateProtocol(this.sdkContext, operation) && !codeModelOperation.internalApi;
|
|
439
450
|
codeModelOperation.addRequest(new Request({
|
|
440
451
|
protocol: {
|
|
441
452
|
http: {
|
|
@@ -605,7 +616,7 @@ export class CodeModelBuilder {
|
|
|
605
616
|
op.addParameter(parameter);
|
|
606
617
|
clientContext.addGlobalParameter(parameter);
|
|
607
618
|
}
|
|
608
|
-
else if (
|
|
619
|
+
else if (SPECIAL_HEADER_NAMES.has(param.name.toLowerCase())) {
|
|
609
620
|
// special headers
|
|
610
621
|
op.specialHeaders = (_a = op.specialHeaders) !== null && _a !== void 0 ? _a : [];
|
|
611
622
|
if (!stringArrayContainsIgnoreCase(op.specialHeaders, param.name)) {
|
|
@@ -648,7 +659,6 @@ export class CodeModelBuilder {
|
|
|
648
659
|
if (param.param.type.kind === "Model" && isArrayModelType(this.program, param.param.type)) {
|
|
649
660
|
if (param.type === "query") {
|
|
650
661
|
const queryParamOptions = getQueryParamOptions(this.program, param.param);
|
|
651
|
-
// TODO (weidxu): remove "as string" after http lib fix the type of queryParamOptions.format
|
|
652
662
|
switch (queryParamOptions === null || queryParamOptions === void 0 ? void 0 : queryParamOptions.format) {
|
|
653
663
|
case "csv":
|
|
654
664
|
style = SerializationStyle.Simple;
|
|
@@ -715,7 +725,7 @@ export class CodeModelBuilder {
|
|
|
715
725
|
else if (op.convenienceApi) {
|
|
716
726
|
this.trackSchemaUsage(schema, { usage: [SchemaContext.Public] });
|
|
717
727
|
}
|
|
718
|
-
if (param.name.toLowerCase() ===
|
|
728
|
+
if (param.name.toLowerCase() === CONTENT_TYPE_KEY) {
|
|
719
729
|
let mediaTypes = ["application/json"];
|
|
720
730
|
if (schema instanceof ConstantSchema) {
|
|
721
731
|
mediaTypes = [schema.value.value.toString()];
|
|
@@ -864,13 +874,19 @@ export class CodeModelBuilder {
|
|
|
864
874
|
processParameterBody(op, httpOperation, body) {
|
|
865
875
|
var _a, _b, _c;
|
|
866
876
|
const parameters = httpOperation.operation.parameters;
|
|
877
|
+
const unknownRequestBody = op.requests[0].protocol.http.mediaTypes &&
|
|
878
|
+
op.requests[0].protocol.http.mediaTypes.length > 0 &&
|
|
879
|
+
!isKnownContentType(op.requests[0].protocol.http.mediaTypes);
|
|
867
880
|
let schema;
|
|
868
|
-
if (
|
|
881
|
+
if (unknownRequestBody &&
|
|
882
|
+
body.kind === "ModelProperty" &&
|
|
883
|
+
body.type.kind === "Scalar" &&
|
|
884
|
+
body.type.name === "bytes") {
|
|
869
885
|
// handle binary request body
|
|
870
886
|
schema = this.processBinarySchema(body.type);
|
|
871
887
|
}
|
|
872
888
|
else {
|
|
873
|
-
schema = this.processSchema(body
|
|
889
|
+
schema = this.processSchema(body, body.name);
|
|
874
890
|
}
|
|
875
891
|
const parameter = new Parameter(body.name, this.getDoc(body), schema, {
|
|
876
892
|
summary: this.getSummary(body),
|
|
@@ -958,7 +974,13 @@ export class CodeModelBuilder {
|
|
|
958
974
|
serializedName: it.language.default.serializedName,
|
|
959
975
|
}));
|
|
960
976
|
});
|
|
961
|
-
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Input
|
|
977
|
+
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Input] });
|
|
978
|
+
if (op.internalApi) {
|
|
979
|
+
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Internal] });
|
|
980
|
+
}
|
|
981
|
+
else if (op.convenienceApi) {
|
|
982
|
+
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Public] });
|
|
983
|
+
}
|
|
962
984
|
// option bag parameter
|
|
963
985
|
const optionBagParameter = new Parameter("options", optionBagSchema.language.default.description, optionBagSchema, {
|
|
964
986
|
implementation: ImplementationLocation.Method,
|
|
@@ -1000,13 +1022,14 @@ export class CodeModelBuilder {
|
|
|
1000
1022
|
let trackConvenienceApi = (_a = op.convenienceApi) !== null && _a !== void 0 ? _a : false;
|
|
1001
1023
|
if (resp.responses && resp.responses.length > 0 && resp.responses[0].body) {
|
|
1002
1024
|
const responseBody = resp.responses[0].body;
|
|
1025
|
+
const unknownResponseBody = responseBody.contentTypes.length > 0 && !isKnownContentType(responseBody.contentTypes);
|
|
1003
1026
|
bodyType = this.findResponseBody(responseBody.type);
|
|
1004
|
-
if (bodyType.kind === "Scalar" && bodyType.name === "bytes") {
|
|
1027
|
+
if (unknownResponseBody && bodyType.kind === "Scalar" && bodyType.name === "bytes") {
|
|
1005
1028
|
// binary
|
|
1006
1029
|
response = new BinaryResponse({
|
|
1007
1030
|
protocol: {
|
|
1008
1031
|
http: {
|
|
1009
|
-
statusCodes:
|
|
1032
|
+
statusCodes: this.getStatusCodes(resp.statusCodes),
|
|
1010
1033
|
headers: headers,
|
|
1011
1034
|
mediaTypes: responseBody.contentTypes,
|
|
1012
1035
|
knownMediaType: "binary",
|
|
@@ -1063,13 +1086,13 @@ export class CodeModelBuilder {
|
|
|
1063
1086
|
schema = op.lroMetadata.pollResultType;
|
|
1064
1087
|
}
|
|
1065
1088
|
else {
|
|
1066
|
-
schema = this.processSchema(bodyType, "
|
|
1089
|
+
schema = this.processSchema(bodyType, op.language.default.name + "Response");
|
|
1067
1090
|
}
|
|
1068
1091
|
}
|
|
1069
1092
|
response = new SchemaResponse(schema, {
|
|
1070
1093
|
protocol: {
|
|
1071
1094
|
http: {
|
|
1072
|
-
statusCodes:
|
|
1095
|
+
statusCodes: this.getStatusCodes(resp.statusCodes),
|
|
1073
1096
|
headers: headers,
|
|
1074
1097
|
mediaTypes: responseBody.contentTypes,
|
|
1075
1098
|
},
|
|
@@ -1088,7 +1111,7 @@ export class CodeModelBuilder {
|
|
|
1088
1111
|
response = new Response({
|
|
1089
1112
|
protocol: {
|
|
1090
1113
|
http: {
|
|
1091
|
-
statusCodes:
|
|
1114
|
+
statusCodes: this.getStatusCodes(resp.statusCodes),
|
|
1092
1115
|
headers: headers,
|
|
1093
1116
|
},
|
|
1094
1117
|
},
|
|
@@ -1100,7 +1123,7 @@ export class CodeModelBuilder {
|
|
|
1100
1123
|
},
|
|
1101
1124
|
});
|
|
1102
1125
|
}
|
|
1103
|
-
if (resp.
|
|
1126
|
+
if (resp.statusCodes === "*" || (bodyType && isErrorModel(this.program, bodyType))) {
|
|
1104
1127
|
// "*", or the model is @error
|
|
1105
1128
|
op.addException(response);
|
|
1106
1129
|
if (response instanceof SchemaResponse) {
|
|
@@ -1120,12 +1143,25 @@ export class CodeModelBuilder {
|
|
|
1120
1143
|
}
|
|
1121
1144
|
}
|
|
1122
1145
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1146
|
+
getStatusCodes(statusCodes) {
|
|
1147
|
+
if (statusCodes === "*") {
|
|
1148
|
+
return ["default"];
|
|
1149
|
+
}
|
|
1150
|
+
else if (typeof statusCodes === "number") {
|
|
1151
|
+
return [statusCodes.toString()];
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
// HttpStatusCodeRange
|
|
1155
|
+
// azure-core does not support "status code range", hence here we expand the range to array of status codes
|
|
1156
|
+
return Array(statusCodes.end - statusCodes.start + 1)
|
|
1157
|
+
.fill(statusCodes.start)
|
|
1158
|
+
.map((it, index) => it + index)
|
|
1159
|
+
.map((it) => it.toString());
|
|
1160
|
+
}
|
|
1125
1161
|
}
|
|
1126
1162
|
getResponseDescription(resp) {
|
|
1127
1163
|
return (resp.description ||
|
|
1128
|
-
(resp.
|
|
1164
|
+
(resp.statusCodes === "*" ? "An unexpected error response" : getStatusCodeDescription(resp.statusCodes)) ||
|
|
1129
1165
|
"");
|
|
1130
1166
|
}
|
|
1131
1167
|
processSchema(type, nameHint) {
|
|
@@ -1159,7 +1195,7 @@ export class CodeModelBuilder {
|
|
|
1159
1195
|
schema = this.processChoiceSchema(knownValues, this.getName(knownValues), false);
|
|
1160
1196
|
}
|
|
1161
1197
|
else {
|
|
1162
|
-
schema = this.processSchema(type.type, nameHint);
|
|
1198
|
+
schema = this.processSchema(type.type, nameHint + "Model");
|
|
1163
1199
|
}
|
|
1164
1200
|
return this.applyModelPropertyDecorators(type, nameHint, schema);
|
|
1165
1201
|
}
|
|
@@ -1174,7 +1210,7 @@ export class CodeModelBuilder {
|
|
|
1174
1210
|
return this.processDictionarySchema(type, nameHint);
|
|
1175
1211
|
}
|
|
1176
1212
|
else {
|
|
1177
|
-
return this.processObjectSchema(type, this.getName(type));
|
|
1213
|
+
return this.processObjectSchema(type, this.getName(type, nameHint));
|
|
1178
1214
|
}
|
|
1179
1215
|
case "EnumMember":
|
|
1180
1216
|
// e.g. "type: TypeEnum.EnumValue1"
|
|
@@ -1645,13 +1681,13 @@ export class CodeModelBuilder {
|
|
|
1645
1681
|
}
|
|
1646
1682
|
// TODO: name from typespec-client-generator-core
|
|
1647
1683
|
const namespace = getNamespace(type);
|
|
1648
|
-
const unionSchema = new OrSchema(pascalCase(name) + "
|
|
1684
|
+
const unionSchema = new OrSchema(pascalCase(name) + "Base", this.getDoc(type), {
|
|
1649
1685
|
summary: this.getSummary(type),
|
|
1650
1686
|
});
|
|
1651
1687
|
unionSchema.anyOf = [];
|
|
1652
1688
|
nonNullVariants.forEach((it) => {
|
|
1653
1689
|
const variantName = this.getUnionVariantName(it.type, { depth: 0 });
|
|
1654
|
-
const modelName = variantName + pascalCase(name)
|
|
1690
|
+
const modelName = variantName + pascalCase(name);
|
|
1655
1691
|
const propertyName = "value";
|
|
1656
1692
|
// these ObjectSchema is not added to codeModel.schemas
|
|
1657
1693
|
const objectSchema = new ObjectSchema(modelName, this.getDoc(type), {
|
|
@@ -1749,7 +1785,7 @@ export class CodeModelBuilder {
|
|
|
1749
1785
|
getSummary(target) {
|
|
1750
1786
|
return getSummary(this.program, target);
|
|
1751
1787
|
}
|
|
1752
|
-
getName(target) {
|
|
1788
|
+
getName(target, nameHint = undefined) {
|
|
1753
1789
|
// 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
|
|
1754
1790
|
const languageProjectedName = getProjectedName(this.program, target, "java");
|
|
1755
1791
|
if (languageProjectedName) {
|
|
@@ -1773,6 +1809,11 @@ export class CodeModelBuilder {
|
|
|
1773
1809
|
this.logWarning(`Rename TypeSpec model '${tspName}' to '${newName}'`);
|
|
1774
1810
|
return newName;
|
|
1775
1811
|
}
|
|
1812
|
+
if (!target.name && nameHint && this.options["namer"]) {
|
|
1813
|
+
const newName = nameHint;
|
|
1814
|
+
this.logWarning(`Rename anonymous TypeSpec model to '${newName}'`);
|
|
1815
|
+
return newName;
|
|
1816
|
+
}
|
|
1776
1817
|
return target.name;
|
|
1777
1818
|
}
|
|
1778
1819
|
getSerializedName(target) {
|
|
@@ -1853,7 +1894,7 @@ export class CodeModelBuilder {
|
|
|
1853
1894
|
value: new ConstantValue(""),
|
|
1854
1895
|
})), {
|
|
1855
1896
|
implementation: ImplementationLocation.Client,
|
|
1856
|
-
origin:
|
|
1897
|
+
origin: ORIGIN_API_VERSION,
|
|
1857
1898
|
required: true,
|
|
1858
1899
|
protocol: {
|
|
1859
1900
|
http: new HttpParameter(parameterLocation),
|