@azure-tools/typespec-java 0.5.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,21 @@
1
1
  import { Operation, Program, Type, EmitContext } from "@typespec/compiler";
2
- import { AnySchema, BinarySchema, BooleanSchema, NumberSchema, Parameter, Schema, StringSchema } from "@autorest/codemodel";
2
+ import { AnySchema, BooleanSchema, NumberSchema, Parameter, Schema, StringSchema } from "@autorest/codemodel";
3
3
  import { CodeModel } from "./common/code-model.js";
4
4
  import { Operation as CodeModelOperation } from "./common/operation.js";
5
5
  import { EmitterOptions } from "./emitter.js";
6
+ import { ProcessingCache } from "./utils.js";
6
7
  export declare class CodeModelBuilder {
7
8
  private program;
8
9
  private typeNameOptions;
9
10
  private namespace;
10
- private dpgContext;
11
+ private sdkContext;
11
12
  private options;
12
13
  private codeModel;
13
14
  readonly schemaCache: ProcessingCache<Type, Schema>;
14
15
  readonly operationCache: Map<Operation, CodeModelOperation>;
16
+ private operationExamples;
15
17
  constructor(program1: Program, context: EmitContext<EmitterOptions>);
16
- build(): CodeModel;
18
+ build(): Promise<CodeModel>;
17
19
  private processHost;
18
20
  private processAuth;
19
21
  private processClients;
@@ -71,8 +73,6 @@ export declare class CodeModelBuilder {
71
73
  get integerSchema(): NumberSchema;
72
74
  private _booleanSchema?;
73
75
  get booleanSchema(): BooleanSchema;
74
- private _binarySchema?;
75
- get binarySchema(): BinarySchema;
76
76
  private _anySchema?;
77
77
  get anySchema(): AnySchema;
78
78
  private createApiVersionParameter;
@@ -83,20 +83,4 @@ export declare class CodeModelBuilder {
83
83
  private propagateSchemaUsage;
84
84
  private trackSchemaUsage;
85
85
  }
86
- /** Acts as a cache for processing inputs.
87
- *
88
- * If the input is undefined, the output is always undefined.
89
- * for a given input, the process is only ever called once.
90
- *
91
- *
92
- */
93
- declare class ProcessingCache<In, Out> {
94
- private transform;
95
- private results;
96
- constructor(transform: (orig: In, ...args: Array<any>) => Out);
97
- has(original: In | undefined): boolean;
98
- set(original: In, result: Out): Out;
99
- process(original: In | undefined, ...args: Array<any>): Out | undefined;
100
- }
101
- export {};
102
86
  //# sourceMappingURL=code-model-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-model-builder.d.ts","sourceRoot":"","sources":["../../src/code-model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAqBL,SAAS,EACT,OAAO,EAIP,IAAI,EAYJ,WAAW,EAGZ,MAAM,oBAAoB,CAAC;AAiC5B,OAAO,EACL,SAAS,EAGT,YAAY,EACZ,aAAa,EAab,YAAY,EAEZ,SAAS,EAKT,MAAM,EAIN,YAAY,EAab,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAkB,SAAS,IAAI,kBAAkB,EAA0B,MAAM,uBAAuB,CAAC;AAKhH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAK9C,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,cAAc,qCAA4C;gBAEhD,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,cAAc,CAAC;IAqDnE,KAAK,IAAI,SAAS;IAYzB,OAAO,CAAC,WAAW;IAyDnB,OAAO,CAAC,WAAW;IAsCnB,OAAO,CAAC,cAAc;IAmGtB,OAAO,CAAC,gBAAgB;IAgGxB,OAAO,CAAC,oBAAoB;IA2B5B,OAAO,CAAC,sBAAsB;IAyD9B,OAAO,CAAC,0BAA0B;IAyBlC,OAAO,CAAC,gBAAgB;IAiGxB,OAAO,CAAC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C,CAAY;IACzC,IAAI,mBAAmB,IAAI,SAAS,CAKnC;IAED,OAAO,CAAC,0BAA0B,CAAC,CAAY;IAC/C,IAAI,yBAAyB,IAAI,SAAS,CAMzC;IAED,OAAO,CAAC,oBAAoB;IAmD5B,OAAO,CAAC,gBAAgB;CAkBzB"}
@@ -1,19 +1,21 @@
1
- import { getDoc, getEffectiveModelType, getFormat, getFriendlyName, getKnownValues, getSummary, getVisibility, ignoreDiagnostics, isArrayModelType, isRecordModelType, isTemplateDeclaration, isTemplateInstance, isUnknownType, getDiscriminator, isNeverType, listServices, getNamespaceFullName, isNullType, NoTarget, getTypeName, getProjectedName, getService, } from "@typespec/compiler";
1
+ import { getDoc, getEffectiveModelType, getFormat, getFriendlyName, getKnownValues, getSummary, getVisibility, ignoreDiagnostics, isArrayModelType, isRecordModelType, isUnknownType, getDiscriminator, isNeverType, listServices, getNamespaceFullName, isNullType, NoTarget, getTypeName, getProjectedName, getService, } from "@typespec/compiler";
2
2
  import { getResourceOperation, getSegment } from "@typespec/rest";
3
- import { getAuthentication, getHeaderFieldName, getPathParamName, getQueryParamName, getServers, getStatusCodeDescription, isStatusCode, getHttpOperation, getQueryParamOptions, getHeaderFieldOptions, } from "@typespec/http";
3
+ import { getAuthentication, getServers, getStatusCodeDescription, getHttpOperation, getQueryParamOptions, getHeaderFieldOptions, } from "@typespec/http";
4
4
  import { getVersion } from "@typespec/versioning";
5
5
  import { isPollingLocation, getPagedResult, getOperationLinks, isFixed } from "@azure-tools/typespec-azure-core";
6
- import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createDpgContext, shouldGenerateProtocol, } from "@azure-tools/typespec-client-generator-core";
6
+ import { listClients, listOperationGroups, listOperationsInOperationGroup, isApiVersion, shouldGenerateConvenient, createSdkContext, shouldGenerateProtocol, isInternal, } from "@azure-tools/typespec-client-generator-core";
7
7
  import { fail } from "assert";
8
- import { AnySchema, ArraySchema, BinaryResponse, BinarySchema, BooleanSchema, ByteArraySchema, ChoiceValue, ConstantSchema, ConstantValue, DateTimeSchema, DateSchema, DictionarySchema, Discriminator, DurationSchema, HttpHeader, HttpParameter, ImplementationLocation, NumberSchema, ObjectSchema, Parameter, ParameterLocation, Property, Relations, Response, SchemaResponse, SchemaType, StringSchema, TimeSchema, Security, OAuth2SecurityScheme, KeySecurityScheme, OperationGroup, UriSchema, VirtualParameter, GroupSchema, GroupProperty, ApiVersion, SerializationStyle, } from "@autorest/codemodel";
8
+ import { AnySchema, ArraySchema, BinaryResponse, BinarySchema, BooleanSchema, ByteArraySchema, ChoiceValue, DateTimeSchema, DateSchema, DictionarySchema, Discriminator, DurationSchema, HttpHeader, HttpParameter, ImplementationLocation, NumberSchema, ObjectSchema, Parameter, ParameterLocation, Property, Relations, Response, SchemaResponse, SchemaType, StringSchema, TimeSchema, Security, OAuth2SecurityScheme, KeySecurityScheme, OperationGroup, UriSchema, VirtualParameter, GroupSchema, GroupProperty, ApiVersion, SerializationStyle, } from "@autorest/codemodel";
9
9
  import { CodeModel } from "./common/code-model.js";
10
- import { Client as CodeModelClient, ServiceVersion } from "./common/client.js";
10
+ import { Client as CodeModelClient } from "./common/client.js";
11
11
  import { ConvenienceApi, Operation as CodeModelOperation, OperationLink, Request } from "./common/operation.js";
12
12
  import { SchemaContext } from "./common/schemas/usage.js";
13
13
  import { ChoiceSchema, SealedChoiceSchema } from "./common/schemas/choice.js";
14
+ import { ConstantSchema, ConstantValue } from "./common/schemas/constant.js";
14
15
  import { OrSchema } from "./common/schemas/relationship.js";
15
16
  import { PreNamer } from "./prenamer/prenamer.js";
16
17
  import { ClientContext, LongRunningMetadata } from "./models.js";
18
+ import { ProcessingCache, stringArrayContainsIgnoreCase, getClientApiVersions, getJavaNamespace, getServiceVersion, isModelReferredInTemplate, operationContainsJsonMergePatch, getNamespace, pushDistinct, isPayloadProperty, modelContainsDerivedModel, pascalCase, getNameForTemplate, originApiVersion, specialHeaderNames, loadExamples, } from "./utils.js";
17
19
  import pkg from "lodash";
18
20
  const { isEqual } = pkg;
19
21
  export class CodeModelBuilder {
@@ -21,9 +23,10 @@ export class CodeModelBuilder {
21
23
  var _a;
22
24
  this.schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
23
25
  this.operationCache = new Map();
26
+ this.operationExamples = new Map();
24
27
  this.options = context.options;
25
28
  this.program = program1;
26
- this.dpgContext = createDpgContext(context);
29
+ this.sdkContext = createSdkContext(context);
27
30
  const service = listServices(this.program)[0];
28
31
  const serviceNamespace = service.type;
29
32
  if (serviceNamespace === undefined) {
@@ -66,8 +69,9 @@ export class CodeModelBuilder {
66
69
  this.processAuth(auth);
67
70
  }
68
71
  }
69
- build() {
72
+ async build() {
70
73
  var _a;
74
+ this.operationExamples = await loadExamples(this.program, this.options);
71
75
  this.processClients();
72
76
  (_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => this.propagateSchemaUsage(it));
73
77
  if (this.options.namer) {
@@ -80,7 +84,7 @@ export class CodeModelBuilder {
80
84
  if (server) {
81
85
  server.parameters.forEach((it) => {
82
86
  let parameter;
83
- if (isApiVersion(this.dpgContext, it)) {
87
+ if (isApiVersion(this.sdkContext, it)) {
84
88
  parameter = this.createApiVersionParameter(it.name, ParameterLocation.Uri);
85
89
  }
86
90
  else {
@@ -165,7 +169,7 @@ export class CodeModelBuilder {
165
169
  }
166
170
  processClients() {
167
171
  var _a;
168
- const clients = listClients(this.dpgContext);
172
+ const clients = listClients(this.sdkContext);
169
173
  for (const client of clients) {
170
174
  const codeModelClient = new CodeModelClient(client.name, this.getDoc(client.type), {
171
175
  summary: this.getSummary(client.type),
@@ -205,8 +209,8 @@ export class CodeModelBuilder {
205
209
  const hostParameters = this.processHost((servers === null || servers === void 0 ? void 0 : servers.length) === 1 ? servers[0] : undefined);
206
210
  codeModelClient.addGlobalParameters(hostParameters);
207
211
  const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters);
208
- const operationGroups = listOperationGroups(this.dpgContext, client);
209
- const operationWithoutGroup = listOperationsInOperationGroup(this.dpgContext, client);
212
+ const operationGroups = listOperationGroups(this.sdkContext, client);
213
+ const operationWithoutGroup = listOperationsInOperationGroup(this.sdkContext, client);
210
214
  let codeModelGroup = new OperationGroup("");
211
215
  for (const operation of operationWithoutGroup) {
212
216
  codeModelGroup.addOperation(this.processOperation("", operation, clientContext));
@@ -215,7 +219,7 @@ export class CodeModelBuilder {
215
219
  codeModelClient.operationGroups.push(codeModelGroup);
216
220
  }
217
221
  for (const operationGroup of operationGroups) {
218
- const operations = listOperationsInOperationGroup(this.dpgContext, operationGroup);
222
+ const operations = listOperationsInOperationGroup(this.sdkContext, operationGroup);
219
223
  codeModelGroup = new OperationGroup(operationGroup.type.name);
220
224
  for (const operation of operations) {
221
225
  codeModelGroup.addOperation(this.processOperation(operationGroup.type.name, operation, clientContext));
@@ -260,22 +264,31 @@ export class CodeModelBuilder {
260
264
  }
261
265
  }
262
266
  processOperation(groupName, operation, clientContext, fromLinkedOperation = false) {
263
- var _a;
267
+ var _a, _b, _c;
264
268
  const op = ignoreDiagnostics(getHttpOperation(this.program, operation));
265
269
  const operationGroup = this.codeModel.getOperationGroup(groupName);
266
270
  const operationName = this.getName(operation);
267
271
  const opId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
272
+ const operationExample = this.operationExamples.get(operation);
268
273
  const codeModelOperation = new CodeModelOperation(operationName, this.getDoc(operation), {
269
274
  operationId: opId,
270
275
  summary: this.getSummary(operation),
276
+ extensions: {
277
+ "x-ms-examples": operationExample
278
+ ? { [(_b = (_a = operationExample.title) !== null && _a !== void 0 ? _a : operationExample.operationId) !== null && _b !== void 0 ? _b : operation.name]: operationExample }
279
+ : undefined,
280
+ },
271
281
  });
272
- if (fromLinkedOperation || !operationContainsJsonMergePatch(op)) {
282
+ if (!operationContainsJsonMergePatch(op)) {
273
283
  // do not generate convenience method for JSON Merge Patch
274
284
  const convenienceApiName = this.getConvenienceApiName(operation);
275
- if (convenienceApiName) {
285
+ if (convenienceApiName && !isInternal(this.sdkContext, operation)) {
276
286
  codeModelOperation.convenienceApi = new ConvenienceApi(convenienceApiName);
277
287
  }
278
288
  }
289
+ // check for generating protocol api or not
290
+ codeModelOperation.generateProtocolApi =
291
+ shouldGenerateProtocol(this.sdkContext, operation) && !isInternal(this.sdkContext, operation);
279
292
  if (!fromLinkedOperation) {
280
293
  // cache for later reference from operationLinks
281
294
  this.operationCache.set(operation, codeModelOperation);
@@ -304,7 +317,7 @@ export class CodeModelBuilder {
304
317
  let bodyType = this.getEffectiveSchemaType(op.parameters.body.type);
305
318
  if (bodyType.kind === "Model") {
306
319
  // try use resource type as round-trip model
307
- const resourceType = (_a = getResourceOperation(this.program, operation)) === null || _a === void 0 ? void 0 : _a.resourceType;
320
+ const resourceType = (_c = getResourceOperation(this.program, operation)) === null || _c === void 0 ? void 0 : _c.resourceType;
308
321
  if (resourceType && op.responses && op.responses.length > 0) {
309
322
  const resp = op.responses[0];
310
323
  if (resp.responses && resp.responses.length > 0 && resp.responses[0].body) {
@@ -321,7 +334,9 @@ export class CodeModelBuilder {
321
334
  }
322
335
  }
323
336
  // linked operations
324
- const lroMetadata = this.processLinkedOperation(codeModelOperation, groupName, operation, clientContext);
337
+ const lroMetadata = fromLinkedOperation
338
+ ? new LongRunningMetadata(false)
339
+ : this.processLinkedOperation(codeModelOperation, groupName, operation, clientContext);
325
340
  // responses
326
341
  const candidateResponseSchema = lroMetadata.pollResultType; // candidate: response body type of pollingOperation
327
342
  op.responses.map((it) => this.processResponse(codeModelOperation, it, candidateResponseSchema));
@@ -329,8 +344,6 @@ export class CodeModelBuilder {
329
344
  this.processRouteForPaged(codeModelOperation, op.responses);
330
345
  // check for long-running operation
331
346
  this.processRouteForLongRunning(codeModelOperation, op.responses, lroMetadata.longRunning);
332
- // check for generating protocol api or not
333
- codeModelOperation.generateProtocolApi = shouldGenerateProtocol(this.dpgContext, operation);
334
347
  operationGroup.addOperation(codeModelOperation);
335
348
  return codeModelOperation;
336
349
  }
@@ -428,7 +441,7 @@ export class CodeModelBuilder {
428
441
  }
429
442
  processParameter(op, param, clientContext) {
430
443
  var _a;
431
- if (isApiVersion(this.dpgContext, param)) {
444
+ if (isApiVersion(this.sdkContext, param)) {
432
445
  const parameter = param.type === "query" ? this.apiVersionParameter : this.apiVersionParameterInPath;
433
446
  op.addParameter(parameter);
434
447
  clientContext.addGlobalParameter(parameter);
@@ -436,15 +449,17 @@ export class CodeModelBuilder {
436
449
  else if (specialHeaderNames.has(param.name.toLowerCase())) {
437
450
  // special headers
438
451
  op.specialHeaders = (_a = op.specialHeaders) !== null && _a !== void 0 ? _a : [];
439
- if (!containsIgnoreCase(op.specialHeaders, param.name)) {
452
+ if (!stringArrayContainsIgnoreCase(op.specialHeaders, param.name)) {
440
453
  op.specialHeaders.push(param.name);
441
454
  }
442
455
  }
443
456
  else {
444
457
  // schema
445
458
  let schema;
446
- if (param.type === "header" && param.param.type.kind === "Scalar" && param.param.type.name === "zonedDateTime") {
447
- // zonedTateTime in header maps to RFC 5322
459
+ if (param.type === "header" &&
460
+ param.param.type.kind === "Scalar" &&
461
+ (param.param.type.name === "utcDateTime" || param.param.type.name === "offsetDateTime")) {
462
+ // utcDateTime in header maps to RFC 5322
448
463
  schema = this.processDateTimeSchema(param.param.type, param.param.name, true);
449
464
  }
450
465
  else {
@@ -553,8 +568,8 @@ export class CodeModelBuilder {
553
568
  var _a, _b, _c;
554
569
  let schema;
555
570
  if (body.kind === "ModelProperty" && body.type.kind === "Scalar" && body.type.name === "bytes") {
556
- //handle for binary body
557
- schema = this.processBinarySchema(body.name);
571
+ // handle binary request body
572
+ schema = this.processBinarySchema(body.type);
558
573
  }
559
574
  else {
560
575
  schema = this.processSchema(body.kind === "Model" ? body : body.type, body.name);
@@ -881,7 +896,8 @@ export class CodeModelBuilder {
881
896
  return this.processTimeSchema(type, nameHint);
882
897
  case "plainDate":
883
898
  return this.processDateSchema(type, nameHint);
884
- case "zonedDateTime":
899
+ case "utcDateTime":
900
+ case "offsetDateTime":
885
901
  return this.processDateTimeSchema(type, nameHint, false);
886
902
  case "duration":
887
903
  return this.processDurationSchema(type, nameHint);
@@ -928,9 +944,7 @@ export class CodeModelBuilder {
928
944
  }
929
945
  }
930
946
  processAnySchema(type, name) {
931
- return this.codeModel.schemas.add(new AnySchema(this.getDoc(type), {
932
- summary: this.getSummary(type),
933
- }));
947
+ return this.anySchema;
934
948
  }
935
949
  processStringSchema(type, name) {
936
950
  return this.codeModel.schemas.add(new StringSchema(name, this.getDoc(type), {
@@ -972,6 +986,10 @@ export class CodeModelBuilder {
972
986
  this.schemaCache.set(type, dictSchema);
973
987
  const elementSchema = this.processSchema(type.indexer.value, name);
974
988
  dictSchema.elementType = elementSchema;
989
+ if (type.indexer.value.kind === "Union") {
990
+ dictSchema.nullableItems =
991
+ Array.from(type.indexer.value.variants.values()).findIndex((it) => isNullType(it.type)) >= 0;
992
+ }
975
993
  return this.codeModel.schemas.add(dictSchema);
976
994
  }
977
995
  processChoiceSchema(type, name, sealed) {
@@ -1274,8 +1292,10 @@ export class CodeModelBuilder {
1274
1292
  });
1275
1293
  return this.codeModel.schemas.add(unionSchema);
1276
1294
  }
1277
- processBinarySchema(name) {
1278
- return this.codeModel.schemas.add(new BinarySchema(name));
1295
+ processBinarySchema(type) {
1296
+ return this.codeModel.schemas.add(new BinarySchema(this.getDoc(type), {
1297
+ summary: this.getSummary(type),
1298
+ }));
1279
1299
  }
1280
1300
  getUnionVariantName(type, option) {
1281
1301
  switch (type.kind) {
@@ -1291,7 +1311,7 @@ export class CodeModelBuilder {
1291
1311
  else if (scalarName === "bytes") {
1292
1312
  name = "ByteArray";
1293
1313
  }
1294
- else if (scalarName === "zonedDateTime") {
1314
+ else if (scalarName === "utcDateTime" || scalarName === "offsetDateTime") {
1295
1315
  name = "Time";
1296
1316
  }
1297
1317
  return pascalCase(name);
@@ -1420,7 +1440,7 @@ export class CodeModelBuilder {
1420
1440
  }
1421
1441
  getConvenienceApiName(op) {
1422
1442
  // check @convenienceMethod
1423
- if (shouldGenerateConvenient(this.dpgContext, op)) {
1443
+ if (shouldGenerateConvenient(this.sdkContext, op)) {
1424
1444
  return this.getName(op);
1425
1445
  }
1426
1446
  else {
@@ -1448,9 +1468,6 @@ export class CodeModelBuilder {
1448
1468
  return (this._booleanSchema ||
1449
1469
  (this._booleanSchema = this.codeModel.schemas.add(new BooleanSchema("boolean", "simple boolean"))));
1450
1470
  }
1451
- get binarySchema() {
1452
- return this._binarySchema || (this._binarySchema = this.codeModel.schemas.add(new BinarySchema("binary")));
1453
- }
1454
1471
  get anySchema() {
1455
1472
  var _a;
1456
1473
  return (_a = this._anySchema) !== null && _a !== void 0 ? _a : (this._anySchema = this.codeModel.schemas.add(new AnySchema("Anything")));
@@ -1533,7 +1550,8 @@ export class CodeModelBuilder {
1533
1550
  schema instanceof GroupSchema ||
1534
1551
  schema instanceof ChoiceSchema ||
1535
1552
  schema instanceof SealedChoiceSchema ||
1536
- schema instanceof OrSchema) {
1553
+ schema instanceof OrSchema ||
1554
+ schema instanceof ConstantSchema) {
1537
1555
  if (schemaUsage.usage) {
1538
1556
  pushDistinct((schema.usage = schema.usage || []), ...schemaUsage.usage);
1539
1557
  }
@@ -1546,136 +1564,4 @@ export class CodeModelBuilder {
1546
1564
  }
1547
1565
  }
1548
1566
  }
1549
- /** Acts as a cache for processing inputs.
1550
- *
1551
- * If the input is undefined, the output is always undefined.
1552
- * for a given input, the process is only ever called once.
1553
- *
1554
- *
1555
- */
1556
- class ProcessingCache {
1557
- constructor(transform) {
1558
- this.transform = transform;
1559
- this.results = new Map();
1560
- }
1561
- has(original) {
1562
- return !!original && !!this.results.get(original);
1563
- }
1564
- set(original, result) {
1565
- this.results.set(original, result);
1566
- return result;
1567
- }
1568
- process(original, ...args) {
1569
- if (original) {
1570
- const result = this.results.get(original) || this.transform(original, ...args);
1571
- this.results.set(original, result);
1572
- return result;
1573
- }
1574
- return undefined;
1575
- }
1576
- }
1577
- /** adds only if the item is not in the collection already
1578
- *
1579
- * @note While this isn't very efficient, it doesn't disturb the original
1580
- * collection, so you won't get inadvertent side effects from using Set, etc.
1581
- */
1582
- function pushDistinct(targetArray, ...items) {
1583
- for (const i of items) {
1584
- if (!targetArray.includes(i)) {
1585
- targetArray.push(i);
1586
- }
1587
- }
1588
- return targetArray;
1589
- }
1590
- function getNamespace(type) {
1591
- let namespaceRef = type.namespace;
1592
- let namespaceStr = undefined;
1593
- while (namespaceRef && namespaceRef.name.length !== 0) {
1594
- namespaceStr = namespaceRef.name + (namespaceStr ? "." + namespaceStr : "");
1595
- namespaceRef = namespaceRef.namespace;
1596
- }
1597
- return namespaceStr;
1598
- }
1599
- function getJavaNamespace(namespace) {
1600
- return namespace ? "com." + namespace.toLowerCase() : undefined;
1601
- }
1602
- function modelContainsDerivedModel(model) {
1603
- return !isTemplateDeclaration(model) && !(isTemplateInstance(model) && model.derivedModels.length === 0);
1604
- }
1605
- function isModelReferredInTemplate(template, target) {
1606
- var _a, _b, _c;
1607
- return (template === target ||
1608
- ((_c = (_b = (_a = template === null || template === void 0 ? void 0 : template.templateMapper) === null || _a === void 0 ? void 0 : _a.args) === null || _b === void 0 ? void 0 : _b.some((it) => it.kind === "Model" || it.kind === "Union" ? isModelReferredInTemplate(it, target) : false)) !== null && _c !== void 0 ? _c : false));
1609
- }
1610
- function getNameForTemplate(target) {
1611
- switch (target.kind) {
1612
- case "Model": {
1613
- let name = target.name;
1614
- if (target.templateMapper && target.templateMapper.args) {
1615
- name = name + target.templateMapper.args.map((it) => getNameForTemplate(it)).join("");
1616
- }
1617
- return name;
1618
- }
1619
- case "String":
1620
- return target.value;
1621
- default:
1622
- return "";
1623
- }
1624
- }
1625
- function containsIgnoreCase(stringList, str) {
1626
- return stringList && str ? stringList.findIndex((s) => s.toLowerCase() === str.toLowerCase()) != -1 : false;
1627
- }
1628
- function operationContainsJsonMergePatch(op) {
1629
- for (const param of op.parameters.parameters) {
1630
- if (param.type === "header" && param.name.toLowerCase() === "content-type") {
1631
- if (param.param.type.kind === "String" && param.param.type.value === "application/merge-patch+json") {
1632
- return true;
1633
- }
1634
- }
1635
- }
1636
- return false;
1637
- }
1638
- function pascalCase(name) {
1639
- if (name.length > 0) {
1640
- return name[0].toUpperCase() + name.slice(1);
1641
- }
1642
- else {
1643
- return name;
1644
- }
1645
- }
1646
- function isPayloadProperty(program, property) {
1647
- const headerInfo = getHeaderFieldName(program, property);
1648
- const queryInfo = getQueryParamName(program, property);
1649
- const pathInfo = getPathParamName(program, property);
1650
- const statusCodeInfo = isStatusCode(program, property);
1651
- return !(headerInfo || queryInfo || pathInfo || statusCodeInfo);
1652
- }
1653
- function getClientApiVersions(client) {
1654
- var _a;
1655
- if ((_a = client.globalParameters) === null || _a === void 0 ? void 0 : _a.find((it) => it.origin === originApiVersion)) {
1656
- return client.apiVersions;
1657
- }
1658
- else {
1659
- return undefined;
1660
- }
1661
- }
1662
- function getServiceVersion(client) {
1663
- let name = client.language.default.name;
1664
- let description = name;
1665
- if (name.endsWith("Client")) {
1666
- name = name.substring(0, name.length - "Client".length);
1667
- }
1668
- else {
1669
- description = description + "Client";
1670
- }
1671
- if (name.endsWith("Service")) {
1672
- name = name + "Version";
1673
- }
1674
- else {
1675
- name = name + "ServiceVersion";
1676
- }
1677
- return new ServiceVersion(name, description);
1678
- }
1679
- const specialHeaderNames = new Set(["repeatability-request-id", "repeatability-first-sent"]);
1680
- const originApiVersion = "modelerfour:synthesized/api-version";
1681
1567
  //# sourceMappingURL=code-model-builder.js.map