@azure-tools/typespec-java 0.5.0 → 0.6.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.
@@ -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;IAiCnB,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,28 +1,32 @@
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, } 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 {
20
22
  constructor(program1, context) {
23
+ var _a;
21
24
  this.schemaCache = new ProcessingCache((type, name) => this.processSchemaImpl(type, name));
22
25
  this.operationCache = new Map();
26
+ this.operationExamples = new Map();
23
27
  this.options = context.options;
24
28
  this.program = program1;
25
- this.dpgContext = createDpgContext(context);
29
+ this.sdkContext = createSdkContext(context);
26
30
  const service = listServices(this.program)[0];
27
31
  const serviceNamespace = service.type;
28
32
  if (serviceNamespace === undefined) {
@@ -40,7 +44,7 @@ export class CodeModelBuilder {
40
44
  },
41
45
  };
42
46
  // init code model
43
- const title = serviceNamespace.name;
47
+ const title = (_a = this.options["service-name"]) !== null && _a !== void 0 ? _a : serviceNamespace.name;
44
48
  const description = this.getDoc(serviceNamespace);
45
49
  this.codeModel = new CodeModel(title, false, {
46
50
  info: {
@@ -65,8 +69,9 @@ export class CodeModelBuilder {
65
69
  this.processAuth(auth);
66
70
  }
67
71
  }
68
- build() {
72
+ async build() {
69
73
  var _a;
74
+ this.operationExamples = await loadExamples(this.program, this.options);
70
75
  this.processClients();
71
76
  (_a = this.codeModel.schemas.objects) === null || _a === void 0 ? void 0 : _a.forEach((it) => this.propagateSchemaUsage(it));
72
77
  if (this.options.namer) {
@@ -79,7 +84,7 @@ export class CodeModelBuilder {
79
84
  if (server) {
80
85
  server.parameters.forEach((it) => {
81
86
  let parameter;
82
- if (isApiVersion(this.dpgContext, it)) {
87
+ if (isApiVersion(this.sdkContext, it)) {
83
88
  parameter = this.createApiVersionParameter(it.name, ParameterLocation.Uri);
84
89
  }
85
90
  else {
@@ -148,6 +153,11 @@ export class CodeModelBuilder {
148
153
  securitySchemes.push(keyScheme);
149
154
  }
150
155
  break;
156
+ case "http":
157
+ {
158
+ this.logWarning(scheme.scheme + " auth method is currently not supported.");
159
+ }
160
+ break;
151
161
  }
152
162
  }
153
163
  }
@@ -159,7 +169,7 @@ export class CodeModelBuilder {
159
169
  }
160
170
  processClients() {
161
171
  var _a;
162
- const clients = listClients(this.dpgContext);
172
+ const clients = listClients(this.sdkContext);
163
173
  for (const client of clients) {
164
174
  const codeModelClient = new CodeModelClient(client.name, this.getDoc(client.type), {
165
175
  summary: this.getSummary(client.type),
@@ -199,8 +209,8 @@ export class CodeModelBuilder {
199
209
  const hostParameters = this.processHost((servers === null || servers === void 0 ? void 0 : servers.length) === 1 ? servers[0] : undefined);
200
210
  codeModelClient.addGlobalParameters(hostParameters);
201
211
  const clientContext = new ClientContext(baseUri, hostParameters, codeModelClient.globalParameters);
202
- const operationGroups = listOperationGroups(this.dpgContext, client);
203
- const operationWithoutGroup = listOperationsInOperationGroup(this.dpgContext, client);
212
+ const operationGroups = listOperationGroups(this.sdkContext, client);
213
+ const operationWithoutGroup = listOperationsInOperationGroup(this.sdkContext, client);
204
214
  let codeModelGroup = new OperationGroup("");
205
215
  for (const operation of operationWithoutGroup) {
206
216
  codeModelGroup.addOperation(this.processOperation("", operation, clientContext));
@@ -209,7 +219,7 @@ export class CodeModelBuilder {
209
219
  codeModelClient.operationGroups.push(codeModelGroup);
210
220
  }
211
221
  for (const operationGroup of operationGroups) {
212
- const operations = listOperationsInOperationGroup(this.dpgContext, operationGroup);
222
+ const operations = listOperationsInOperationGroup(this.sdkContext, operationGroup);
213
223
  codeModelGroup = new OperationGroup(operationGroup.type.name);
214
224
  for (const operation of operations) {
215
225
  codeModelGroup.addOperation(this.processOperation(operationGroup.type.name, operation, clientContext));
@@ -254,16 +264,22 @@ export class CodeModelBuilder {
254
264
  }
255
265
  }
256
266
  processOperation(groupName, operation, clientContext, fromLinkedOperation = false) {
257
- var _a;
267
+ var _a, _b, _c;
258
268
  const op = ignoreDiagnostics(getHttpOperation(this.program, operation));
259
269
  const operationGroup = this.codeModel.getOperationGroup(groupName);
260
270
  const operationName = this.getName(operation);
261
271
  const opId = groupName ? `${groupName}_${operationName}` : `${operationName}`;
272
+ const operationExample = this.operationExamples.get(operation);
262
273
  const codeModelOperation = new CodeModelOperation(operationName, this.getDoc(operation), {
263
274
  operationId: opId,
264
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
+ },
265
281
  });
266
- if (fromLinkedOperation || !operationContainsJsonMergePatch(op)) {
282
+ if (!operationContainsJsonMergePatch(op)) {
267
283
  // do not generate convenience method for JSON Merge Patch
268
284
  const convenienceApiName = this.getConvenienceApiName(operation);
269
285
  if (convenienceApiName) {
@@ -298,7 +314,7 @@ export class CodeModelBuilder {
298
314
  let bodyType = this.getEffectiveSchemaType(op.parameters.body.type);
299
315
  if (bodyType.kind === "Model") {
300
316
  // try use resource type as round-trip model
301
- const resourceType = (_a = getResourceOperation(this.program, operation)) === null || _a === void 0 ? void 0 : _a.resourceType;
317
+ const resourceType = (_c = getResourceOperation(this.program, operation)) === null || _c === void 0 ? void 0 : _c.resourceType;
302
318
  if (resourceType && op.responses && op.responses.length > 0) {
303
319
  const resp = op.responses[0];
304
320
  if (resp.responses && resp.responses.length > 0 && resp.responses[0].body) {
@@ -315,7 +331,9 @@ export class CodeModelBuilder {
315
331
  }
316
332
  }
317
333
  // linked operations
318
- const lroMetadata = this.processLinkedOperation(codeModelOperation, groupName, operation, clientContext);
334
+ const lroMetadata = fromLinkedOperation
335
+ ? new LongRunningMetadata(false)
336
+ : this.processLinkedOperation(codeModelOperation, groupName, operation, clientContext);
319
337
  // responses
320
338
  const candidateResponseSchema = lroMetadata.pollResultType; // candidate: response body type of pollingOperation
321
339
  op.responses.map((it) => this.processResponse(codeModelOperation, it, candidateResponseSchema));
@@ -324,7 +342,7 @@ export class CodeModelBuilder {
324
342
  // check for long-running operation
325
343
  this.processRouteForLongRunning(codeModelOperation, op.responses, lroMetadata.longRunning);
326
344
  // check for generating protocol api or not
327
- codeModelOperation.generateProtocolApi = shouldGenerateProtocol(this.dpgContext, operation);
345
+ codeModelOperation.generateProtocolApi = shouldGenerateProtocol(this.sdkContext, operation);
328
346
  operationGroup.addOperation(codeModelOperation);
329
347
  return codeModelOperation;
330
348
  }
@@ -422,7 +440,7 @@ export class CodeModelBuilder {
422
440
  }
423
441
  processParameter(op, param, clientContext) {
424
442
  var _a;
425
- if (isApiVersion(this.dpgContext, param)) {
443
+ if (isApiVersion(this.sdkContext, param)) {
426
444
  const parameter = param.type === "query" ? this.apiVersionParameter : this.apiVersionParameterInPath;
427
445
  op.addParameter(parameter);
428
446
  clientContext.addGlobalParameter(parameter);
@@ -430,15 +448,17 @@ export class CodeModelBuilder {
430
448
  else if (specialHeaderNames.has(param.name.toLowerCase())) {
431
449
  // special headers
432
450
  op.specialHeaders = (_a = op.specialHeaders) !== null && _a !== void 0 ? _a : [];
433
- if (!containsIgnoreCase(op.specialHeaders, param.name)) {
451
+ if (!stringArrayContainsIgnoreCase(op.specialHeaders, param.name)) {
434
452
  op.specialHeaders.push(param.name);
435
453
  }
436
454
  }
437
455
  else {
438
456
  // schema
439
457
  let schema;
440
- if (param.type === "header" && param.param.type.kind === "Scalar" && param.param.type.name === "zonedDateTime") {
441
- // zonedTateTime in header maps to RFC 5322
458
+ if (param.type === "header" &&
459
+ param.param.type.kind === "Scalar" &&
460
+ (param.param.type.name === "utcDateTime" || param.param.type.name === "offsetDateTime")) {
461
+ // utcDateTime in header maps to RFC 5322
442
462
  schema = this.processDateTimeSchema(param.param.type, param.param.name, true);
443
463
  }
444
464
  else {
@@ -547,8 +567,8 @@ export class CodeModelBuilder {
547
567
  var _a, _b, _c;
548
568
  let schema;
549
569
  if (body.kind === "ModelProperty" && body.type.kind === "Scalar" && body.type.name === "bytes") {
550
- //handle for binary body
551
- schema = this.processBinarySchema(body.name);
570
+ // handle binary request body
571
+ schema = this.processBinarySchema(body.type);
552
572
  }
553
573
  else {
554
574
  schema = this.processSchema(body.kind === "Model" ? body : body.type, body.name);
@@ -875,7 +895,8 @@ export class CodeModelBuilder {
875
895
  return this.processTimeSchema(type, nameHint);
876
896
  case "plainDate":
877
897
  return this.processDateSchema(type, nameHint);
878
- case "zonedDateTime":
898
+ case "utcDateTime":
899
+ case "offsetDateTime":
879
900
  return this.processDateTimeSchema(type, nameHint, false);
880
901
  case "duration":
881
902
  return this.processDurationSchema(type, nameHint);
@@ -922,9 +943,7 @@ export class CodeModelBuilder {
922
943
  }
923
944
  }
924
945
  processAnySchema(type, name) {
925
- return this.codeModel.schemas.add(new AnySchema(this.getDoc(type), {
926
- summary: this.getSummary(type),
927
- }));
946
+ return this.anySchema;
928
947
  }
929
948
  processStringSchema(type, name) {
930
949
  return this.codeModel.schemas.add(new StringSchema(name, this.getDoc(type), {
@@ -966,6 +985,10 @@ export class CodeModelBuilder {
966
985
  this.schemaCache.set(type, dictSchema);
967
986
  const elementSchema = this.processSchema(type.indexer.value, name);
968
987
  dictSchema.elementType = elementSchema;
988
+ if (type.indexer.value.kind === "Union") {
989
+ dictSchema.nullableItems =
990
+ Array.from(type.indexer.value.variants.values()).findIndex((it) => isNullType(it.type)) >= 0;
991
+ }
969
992
  return this.codeModel.schemas.add(dictSchema);
970
993
  }
971
994
  processChoiceSchema(type, name, sealed) {
@@ -1268,8 +1291,10 @@ export class CodeModelBuilder {
1268
1291
  });
1269
1292
  return this.codeModel.schemas.add(unionSchema);
1270
1293
  }
1271
- processBinarySchema(name) {
1272
- return this.codeModel.schemas.add(new BinarySchema(name));
1294
+ processBinarySchema(type) {
1295
+ return this.codeModel.schemas.add(new BinarySchema(this.getDoc(type), {
1296
+ summary: this.getSummary(type),
1297
+ }));
1273
1298
  }
1274
1299
  getUnionVariantName(type, option) {
1275
1300
  switch (type.kind) {
@@ -1285,7 +1310,7 @@ export class CodeModelBuilder {
1285
1310
  else if (scalarName === "bytes") {
1286
1311
  name = "ByteArray";
1287
1312
  }
1288
- else if (scalarName === "zonedDateTime") {
1313
+ else if (scalarName === "utcDateTime" || scalarName === "offsetDateTime") {
1289
1314
  name = "Time";
1290
1315
  }
1291
1316
  return pascalCase(name);
@@ -1414,7 +1439,7 @@ export class CodeModelBuilder {
1414
1439
  }
1415
1440
  getConvenienceApiName(op) {
1416
1441
  // check @convenienceMethod
1417
- if (shouldGenerateConvenient(this.dpgContext, op)) {
1442
+ if (shouldGenerateConvenient(this.sdkContext, op)) {
1418
1443
  return this.getName(op);
1419
1444
  }
1420
1445
  else {
@@ -1442,9 +1467,6 @@ export class CodeModelBuilder {
1442
1467
  return (this._booleanSchema ||
1443
1468
  (this._booleanSchema = this.codeModel.schemas.add(new BooleanSchema("boolean", "simple boolean"))));
1444
1469
  }
1445
- get binarySchema() {
1446
- return this._binarySchema || (this._binarySchema = this.codeModel.schemas.add(new BinarySchema("binary")));
1447
- }
1448
1470
  get anySchema() {
1449
1471
  var _a;
1450
1472
  return (_a = this._anySchema) !== null && _a !== void 0 ? _a : (this._anySchema = this.codeModel.schemas.add(new AnySchema("Anything")));
@@ -1527,7 +1549,8 @@ export class CodeModelBuilder {
1527
1549
  schema instanceof GroupSchema ||
1528
1550
  schema instanceof ChoiceSchema ||
1529
1551
  schema instanceof SealedChoiceSchema ||
1530
- schema instanceof OrSchema) {
1552
+ schema instanceof OrSchema ||
1553
+ schema instanceof ConstantSchema) {
1531
1554
  if (schemaUsage.usage) {
1532
1555
  pushDistinct((schema.usage = schema.usage || []), ...schemaUsage.usage);
1533
1556
  }
@@ -1540,136 +1563,4 @@ export class CodeModelBuilder {
1540
1563
  }
1541
1564
  }
1542
1565
  }
1543
- /** Acts as a cache for processing inputs.
1544
- *
1545
- * If the input is undefined, the output is always undefined.
1546
- * for a given input, the process is only ever called once.
1547
- *
1548
- *
1549
- */
1550
- class ProcessingCache {
1551
- constructor(transform) {
1552
- this.transform = transform;
1553
- this.results = new Map();
1554
- }
1555
- has(original) {
1556
- return !!original && !!this.results.get(original);
1557
- }
1558
- set(original, result) {
1559
- this.results.set(original, result);
1560
- return result;
1561
- }
1562
- process(original, ...args) {
1563
- if (original) {
1564
- const result = this.results.get(original) || this.transform(original, ...args);
1565
- this.results.set(original, result);
1566
- return result;
1567
- }
1568
- return undefined;
1569
- }
1570
- }
1571
- /** adds only if the item is not in the collection already
1572
- *
1573
- * @note While this isn't very efficient, it doesn't disturb the original
1574
- * collection, so you won't get inadvertent side effects from using Set, etc.
1575
- */
1576
- function pushDistinct(targetArray, ...items) {
1577
- for (const i of items) {
1578
- if (!targetArray.includes(i)) {
1579
- targetArray.push(i);
1580
- }
1581
- }
1582
- return targetArray;
1583
- }
1584
- function getNamespace(type) {
1585
- let namespaceRef = type.namespace;
1586
- let namespaceStr = undefined;
1587
- while (namespaceRef && namespaceRef.name.length !== 0) {
1588
- namespaceStr = namespaceRef.name + (namespaceStr ? "." + namespaceStr : "");
1589
- namespaceRef = namespaceRef.namespace;
1590
- }
1591
- return namespaceStr;
1592
- }
1593
- function getJavaNamespace(namespace) {
1594
- return namespace ? "com." + namespace.toLowerCase() : undefined;
1595
- }
1596
- function modelContainsDerivedModel(model) {
1597
- return !isTemplateDeclaration(model) && !(isTemplateInstance(model) && model.derivedModels.length === 0);
1598
- }
1599
- function isModelReferredInTemplate(template, target) {
1600
- var _a, _b, _c;
1601
- return (template === target ||
1602
- ((_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));
1603
- }
1604
- function getNameForTemplate(target) {
1605
- switch (target.kind) {
1606
- case "Model": {
1607
- let name = target.name;
1608
- if (target.templateMapper && target.templateMapper.args) {
1609
- name = name + target.templateMapper.args.map((it) => getNameForTemplate(it)).join("");
1610
- }
1611
- return name;
1612
- }
1613
- case "String":
1614
- return target.value;
1615
- default:
1616
- return "";
1617
- }
1618
- }
1619
- function containsIgnoreCase(stringList, str) {
1620
- return stringList && str ? stringList.findIndex((s) => s.toLowerCase() === str.toLowerCase()) != -1 : false;
1621
- }
1622
- function operationContainsJsonMergePatch(op) {
1623
- for (const param of op.parameters.parameters) {
1624
- if (param.type === "header" && param.name.toLowerCase() === "content-type") {
1625
- if (param.param.type.kind === "String" && param.param.type.value === "application/merge-patch+json") {
1626
- return true;
1627
- }
1628
- }
1629
- }
1630
- return false;
1631
- }
1632
- function pascalCase(name) {
1633
- if (name.length > 0) {
1634
- return name[0].toUpperCase() + name.slice(1);
1635
- }
1636
- else {
1637
- return name;
1638
- }
1639
- }
1640
- function isPayloadProperty(program, property) {
1641
- const headerInfo = getHeaderFieldName(program, property);
1642
- const queryInfo = getQueryParamName(program, property);
1643
- const pathInfo = getPathParamName(program, property);
1644
- const statusCodeInfo = isStatusCode(program, property);
1645
- return !(headerInfo || queryInfo || pathInfo || statusCodeInfo);
1646
- }
1647
- function getClientApiVersions(client) {
1648
- var _a;
1649
- if ((_a = client.globalParameters) === null || _a === void 0 ? void 0 : _a.find((it) => it.origin === originApiVersion)) {
1650
- return client.apiVersions;
1651
- }
1652
- else {
1653
- return undefined;
1654
- }
1655
- }
1656
- function getServiceVersion(client) {
1657
- let name = client.language.default.name;
1658
- let description = name;
1659
- if (name.endsWith("Client")) {
1660
- name = name.substring(0, name.length - "Client".length);
1661
- }
1662
- else {
1663
- description = description + "Client";
1664
- }
1665
- if (name.endsWith("Service")) {
1666
- name = name + "Version";
1667
- }
1668
- else {
1669
- name = name + "ServiceVersion";
1670
- }
1671
- return new ServiceVersion(name, description);
1672
- }
1673
- const specialHeaderNames = new Set(["repeatability-request-id", "repeatability-first-sent"]);
1674
- const originApiVersion = "modelerfour:synthesized/api-version";
1675
1566
  //# sourceMappingURL=code-model-builder.js.map