@looker/sdk-codegen 21.2.0 → 21.2.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.
@@ -348,7 +348,7 @@ export declare class ArrayType extends Type {
348
348
  export declare class EnumType extends Type implements IEnumType {
349
349
  elementType: IType;
350
350
  readonly values: EnumValueType[];
351
- constructor(elementType: IType, schema: OAS.SchemaObject, types: TypeList, typeName?: string, methodName?: string);
351
+ constructor(elementType: IType, schema: OAS.SchemaObject, api: ApiModel, typeName?: string, methodName?: string);
352
352
  private findName;
353
353
  searchString(criteria: SearchCriteria): string;
354
354
  get className(): string;
@@ -419,6 +419,7 @@ export declare class ApiModel implements ISymbolTable, IApiModel {
419
419
  registerEnum(type: IType, methodName?: string): IType;
420
420
  private _getRequestType;
421
421
  getRequestType(method: IMethod): IType | undefined;
422
+ getEnumList(): TypeList;
422
423
  makeWriteableType(hash: string, type: IType): WriteType;
423
424
  mayGetWriteableType(type: IType): IType | WriteType | undefined;
424
425
  loadDynamicTypes(): void;
package/lib/sdkModels.js CHANGED
@@ -1028,7 +1028,7 @@ class Type {
1028
1028
  load(api) {
1029
1029
  Object.entries(this.schema.properties || {}).forEach(_ref7 => {
1030
1030
  var [propName, propSchema] = _ref7;
1031
- var propType = api.resolveType(propSchema, undefined, propName);
1031
+ var propType = api.resolveType(propSchema, undefined, propName, this.name);
1032
1032
 
1033
1033
  if (propType.instanceOf('EnumType')) {
1034
1034
  api.registerEnum(propType, propName);
@@ -1146,7 +1146,7 @@ class ArrayType extends Type {
1146
1146
  exports.ArrayType = ArrayType;
1147
1147
 
1148
1148
  class EnumType extends Type {
1149
- constructor(elementType, schema, types, typeName, methodName) {
1149
+ constructor(elementType, schema, api, typeName, methodName) {
1150
1150
  super(schema, schema.name);
1151
1151
  this.elementType = elementType;
1152
1152
 
@@ -1163,27 +1163,36 @@ class EnumType extends Type {
1163
1163
  }
1164
1164
 
1165
1165
  if (methodName) {
1166
- this.description = "Type defined in ".concat(methodName, "\n").concat(this.description);
1166
+ this.description = "".concat(this.description).concat(this.description ? ' ' : '', "(Enum defined in ").concat(methodName, ")");
1167
1167
  }
1168
1168
 
1169
- this.name = this.findName(types, typeName, methodName);
1169
+ this.name = this.findName(api, typeName, methodName);
1170
1170
  }
1171
1171
 
1172
- findName(types, typeName, methodName) {
1172
+ findName(api, typeName, methodName) {
1173
+ var hash = (0, _blueimpMd.default)(this.asHashString());
1174
+ var enums = api.getEnumList();
1173
1175
  var name = titleCase(this.name || typeName || 'Enum');
1174
1176
 
1175
- if (name in types) {
1177
+ if (name in api.types) {
1178
+ var matched = enums[hash];
1179
+
1180
+ if ((matched === null || matched === void 0 ? void 0 : matched.name) === name) {
1181
+ return name;
1182
+ }
1183
+
1176
1184
  var baseName = methodName ? titleCase("".concat(methodName, "_").concat(name)) : name;
1177
1185
  var newName = baseName;
1178
1186
  var i = 0;
1179
1187
 
1180
- while (newName in types) {
1188
+ while (newName in api.types) {
1181
1189
  newName = "".concat(baseName).concat(++i);
1182
1190
  }
1183
1191
 
1184
1192
  name = newName;
1185
1193
  }
1186
1194
 
1195
+ enums[hash] = this;
1187
1196
  return name;
1188
1197
  }
1189
1198
 
@@ -1535,7 +1544,7 @@ class ApiModel {
1535
1544
  }
1536
1545
 
1537
1546
  if (this.schemaHasEnums(schema)) {
1538
- var num = new EnumType(resolved, schema, this.types, typeName, methodName);
1547
+ var num = new EnumType(resolved, schema, this, typeName, methodName);
1539
1548
  this.registerEnum(num, methodName);
1540
1549
  var result = new ArrayType(num, schema);
1541
1550
  return result;
@@ -1545,7 +1554,9 @@ class ApiModel {
1545
1554
  }
1546
1555
 
1547
1556
  if (this.schemaHasEnums(schema)) {
1548
- var _result = new EnumType(this.resolveType(schema.type), schema, this.types, typeName, methodName);
1557
+ var _resolved = this.resolveType(schema.type, style, typeName, methodName);
1558
+
1559
+ var _result = new EnumType(_resolved, schema, this, typeName, methodName);
1549
1560
 
1550
1561
  if (_result) {
1551
1562
  return this.registerEnum(_result, methodName);
@@ -1587,10 +1598,14 @@ class ApiModel {
1587
1598
 
1588
1599
  registerEnum(type, methodName) {
1589
1600
  if (!(type instanceof EnumType)) return type;
1590
- var hash = (0, _blueimpMd.default)(type.asHashString());
1591
1601
 
1592
- if (hash in this.enumTypes) {
1593
- return this.enumTypes[hash];
1602
+ if (type.name in this.types) {
1603
+ var hash = (0, _blueimpMd.default)(type.asHashString());
1604
+ var matched = this.enumTypes[hash];
1605
+
1606
+ if ((matched === null || matched === void 0 ? void 0 : matched.name) === type.name) {
1607
+ return this.enumTypes[hash];
1608
+ }
1594
1609
  }
1595
1610
 
1596
1611
  if (methodName) {
@@ -1603,7 +1618,6 @@ class ApiModel {
1603
1618
  }
1604
1619
  }
1605
1620
 
1606
- this.enumTypes[hash] = type;
1607
1621
  this.types[type.name] = type;
1608
1622
  return type;
1609
1623
  }
@@ -1625,6 +1639,10 @@ class ApiModel {
1625
1639
  return result;
1626
1640
  }
1627
1641
 
1642
+ getEnumList() {
1643
+ return this.enumTypes;
1644
+ }
1645
+
1628
1646
  makeWriteableType(hash, type) {
1629
1647
  var writer = new WriteType(this, type);
1630
1648
  this.types[writer.name] = writer;