@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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ### [21.2.1](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-v21.2.0...sdk-codegen-v21.2.1) (2021-12-06)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * enum naming and registration ([#918](https://www.github.com/looker-open-source/sdk-codegen/issues/918)) ([9d4a6cb](https://www.github.com/looker-open-source/sdk-codegen/commit/9d4a6cbfac5defad3a35389e2d46947d2135d349))
14
+
8
15
  ## [21.2.0](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-v21.1.1...sdk-codegen-v21.2.0) (2021-11-10)
9
16
 
10
17
 
@@ -243,4 +250,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
243
250
 
244
251
  ### Added
245
252
 
246
- - [API spec diff utility](https://github.com/looker-open-source/sdk-codegen/pull/380)
253
+ - [API spec diff utility](https://github.com/looker-open-source/sdk-codegen/pull/380)
@@ -957,7 +957,7 @@ export class Type {
957
957
  load(api) {
958
958
  Object.entries(this.schema.properties || {}).forEach(_ref7 => {
959
959
  var [propName, propSchema] = _ref7;
960
- var propType = api.resolveType(propSchema, undefined, propName);
960
+ var propType = api.resolveType(propSchema, undefined, propName, this.name);
961
961
 
962
962
  if (propType.instanceOf('EnumType')) {
963
963
  api.registerEnum(propType, propName);
@@ -1069,7 +1069,7 @@ export class ArrayType extends Type {
1069
1069
 
1070
1070
  }
1071
1071
  export class EnumType extends Type {
1072
- constructor(elementType, schema, types, typeName, methodName) {
1072
+ constructor(elementType, schema, api, typeName, methodName) {
1073
1073
  super(schema, schema.name);
1074
1074
  this.elementType = elementType;
1075
1075
 
@@ -1086,27 +1086,36 @@ export class EnumType extends Type {
1086
1086
  }
1087
1087
 
1088
1088
  if (methodName) {
1089
- this.description = "Type defined in ".concat(methodName, "\n").concat(this.description);
1089
+ this.description = "".concat(this.description).concat(this.description ? ' ' : '', "(Enum defined in ").concat(methodName, ")");
1090
1090
  }
1091
1091
 
1092
- this.name = this.findName(types, typeName, methodName);
1092
+ this.name = this.findName(api, typeName, methodName);
1093
1093
  }
1094
1094
 
1095
- findName(types, typeName, methodName) {
1095
+ findName(api, typeName, methodName) {
1096
+ var hash = md5(this.asHashString());
1097
+ var enums = api.getEnumList();
1096
1098
  var name = titleCase(this.name || typeName || 'Enum');
1097
1099
 
1098
- if (name in types) {
1100
+ if (name in api.types) {
1101
+ var matched = enums[hash];
1102
+
1103
+ if ((matched === null || matched === void 0 ? void 0 : matched.name) === name) {
1104
+ return name;
1105
+ }
1106
+
1099
1107
  var baseName = methodName ? titleCase("".concat(methodName, "_").concat(name)) : name;
1100
1108
  var newName = baseName;
1101
1109
  var i = 0;
1102
1110
 
1103
- while (newName in types) {
1111
+ while (newName in api.types) {
1104
1112
  newName = "".concat(baseName).concat(++i);
1105
1113
  }
1106
1114
 
1107
1115
  name = newName;
1108
1116
  }
1109
1117
 
1118
+ enums[hash] = this;
1110
1119
  return name;
1111
1120
  }
1112
1121
 
@@ -1442,7 +1451,7 @@ export class ApiModel {
1442
1451
  }
1443
1452
 
1444
1453
  if (this.schemaHasEnums(schema)) {
1445
- var num = new EnumType(resolved, schema, this.types, typeName, methodName);
1454
+ var num = new EnumType(resolved, schema, this, typeName, methodName);
1446
1455
  this.registerEnum(num, methodName);
1447
1456
  var result = new ArrayType(num, schema);
1448
1457
  return result;
@@ -1452,7 +1461,9 @@ export class ApiModel {
1452
1461
  }
1453
1462
 
1454
1463
  if (this.schemaHasEnums(schema)) {
1455
- var _result = new EnumType(this.resolveType(schema.type), schema, this.types, typeName, methodName);
1464
+ var _resolved = this.resolveType(schema.type, style, typeName, methodName);
1465
+
1466
+ var _result = new EnumType(_resolved, schema, this, typeName, methodName);
1456
1467
 
1457
1468
  if (_result) {
1458
1469
  return this.registerEnum(_result, methodName);
@@ -1494,10 +1505,14 @@ export class ApiModel {
1494
1505
 
1495
1506
  registerEnum(type, methodName) {
1496
1507
  if (!(type instanceof EnumType)) return type;
1497
- var hash = md5(type.asHashString());
1498
1508
 
1499
- if (hash in this.enumTypes) {
1500
- return this.enumTypes[hash];
1509
+ if (type.name in this.types) {
1510
+ var hash = md5(type.asHashString());
1511
+ var matched = this.enumTypes[hash];
1512
+
1513
+ if ((matched === null || matched === void 0 ? void 0 : matched.name) === type.name) {
1514
+ return this.enumTypes[hash];
1515
+ }
1501
1516
  }
1502
1517
 
1503
1518
  if (methodName) {
@@ -1510,7 +1525,6 @@ export class ApiModel {
1510
1525
  }
1511
1526
  }
1512
1527
 
1513
- this.enumTypes[hash] = type;
1514
1528
  this.types[type.name] = type;
1515
1529
  return type;
1516
1530
  }
@@ -1532,6 +1546,10 @@ export class ApiModel {
1532
1546
  return result;
1533
1547
  }
1534
1548
 
1549
+ getEnumList() {
1550
+ return this.enumTypes;
1551
+ }
1552
+
1535
1553
  makeWriteableType(hash, type) {
1536
1554
  var writer = new WriteType(this, type);
1537
1555
  this.types[writer.name] = writer;