swaggie 2.1.2 → 2.1.3

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.
@@ -623,23 +623,36 @@ const PRIMITIVES =
623
623
  * and inline object types (including PascalCase names used as property value types
624
624
  * inside `{ key: SomeType }` shapes).
625
625
  *
626
- * @example prefixApiType('Pet') 'API.Pet'
627
- * @example prefixApiType('Pet[]') → 'API.Pet[]'
628
- * @example prefixApiType('Pet | null') → 'API.Pet | null'
629
- * @example prefixApiType('unknown') → 'unknown'
630
- * @example prefixApiType('{ id: number }') → '{ id: number }'
631
- * @example prefixApiType('{ profile: MyEnum; }') → '{ profile: API.MyEnum; }'
632
- * @example prefixApiType('API.Pet') → 'API.Pet' (API itself is in the exclude list)
626
+ * Quoted string literals (single or double) are left entirely untouched so that
627
+ * enum-derived types like `"AZURE" | "AWS"` are never incorrectly rewritten to
628
+ * `"API.AZURE" | "API.AWS"`.
629
+ *
630
+ * @example prefixApiType('Pet') → 'API.Pet'
631
+ * @example prefixApiType('Pet[]') → 'API.Pet[]'
632
+ * @example prefixApiType('Pet | null') → 'API.Pet | null'
633
+ * @example prefixApiType('unknown') → 'unknown'
634
+ * @example prefixApiType('{ id: number }') → '{ id: number }'
635
+ * @example prefixApiType('{ profile: MyEnum; }') → '{ profile: API.MyEnum; }'
636
+ * @example prefixApiType('API.Pet') → 'API.Pet'
637
+ * @example prefixApiType('"AZURE" | "AWS"') → '"AZURE" | "AWS"'
638
+ * @example prefixApiType('"available" | Pet') → '"available" | API.Pet'
633
639
  */
634
640
  function prefixApiType(typeStr) {
635
641
  if (!typeStr) {
636
642
  return typeStr;
637
643
  }
638
- // The negative lookbehind `(?<!\.)` skips identifiers that are already part
639
- // of a namespace reference (e.g. `API.Pet` when the regex reaches `Pet` it
640
- // is preceded by `.`, so we leave it alone).
641
- return typeStr.replace(/(?<!\.)\b([A-Z][A-Za-z0-9_]*)\b/g, (match) =>
642
- PRIMITIVES.test(match) ? match : `API.${match}`
644
+ // The alternation has two branches:
645
+ // Group 1: a full quoted string literal ("..." or '...') returned as-is so
646
+ // that enum-derived values like "AZURE" are never prefixed.
647
+ // Group 2: an uppercase-starting identifier that is NOT already preceded by a
648
+ // dot (negative lookbehind) prefixed with API. unless it is a known
649
+ // primitive / built-in.
650
+ return typeStr.replace(
651
+ /("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')|(?<!\.)\b([A-Z][A-Za-z0-9_]*)\b/g,
652
+ (match, quotedLiteral, ident) => {
653
+ if (quotedLiteral !== undefined) return quotedLiteral;
654
+ return PRIMITIVES.test(ident) ? ident : `API.${ident}`;
655
+ },
643
656
  );
644
657
  } exports.prefixApiType = prefixApiType;
645
658
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Generate a fully typed TypeScript API client from your OpenAPI 3 spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",
@@ -72,16 +72,16 @@
72
72
  "dependencies": {
73
73
  "case": "^1.6.3",
74
74
  "commander": "^14.0.3",
75
- "eta": "^4.5.1",
75
+ "eta": "^4.6.0",
76
76
  "yaml": "^2.8.3",
77
77
  "picocolors": "^1.1.1"
78
78
  },
79
79
  "devDependencies": {
80
- "bun-types": "1.3.11",
80
+ "bun-types": "1.3.13",
81
81
  "openapi-types": "^12.1.3",
82
82
  "sucrase": "3.35.1",
83
- "typescript": "6.0.2",
83
+ "typescript": "6.0.3",
84
84
  "vitepress": "^2.0.0-alpha.17",
85
- "vitepress-plugin-tabs": "0.8.0"
85
+ "vitepress-plugin-tabs": "0.9.0"
86
86
  }
87
87
  }