swagger-typescript-api 13.6.3 → 13.6.5

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.
@@ -47,12 +47,12 @@ let node_crypto = require("node:crypto");
47
47
  node_crypto = __toESM(node_crypto);
48
48
  let swagger2openapi = require("swagger2openapi");
49
49
  swagger2openapi = __toESM(swagger2openapi);
50
- let yaml = require("yaml");
51
- yaml = __toESM(yaml);
52
50
  let node_fs = require("node:fs");
53
51
  node_fs = __toESM(node_fs);
54
52
  let _apidevtools_swagger_parser = require("@apidevtools/swagger-parser");
55
53
  _apidevtools_swagger_parser = __toESM(_apidevtools_swagger_parser);
54
+ let yaml = require("yaml");
55
+ yaml = __toESM(yaml);
56
56
  let node_module = require("node:module");
57
57
  node_module = __toESM(node_module);
58
58
  let node_url = require("node:url");
@@ -213,7 +213,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
213
213
  //#endregion
214
214
  //#region package.json
215
215
  var name = "swagger-typescript-api";
216
- var version = "13.6.3";
216
+ var version = "13.6.5";
217
217
  var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
218
218
  //#endregion
219
219
  //#region src/constants.ts
@@ -2366,6 +2366,48 @@ var SchemaRoutes = class {
2366
2366
  };
2367
2367
  };
2368
2368
  //#endregion
2369
+ //#region src/util/parse-schema-content.ts
2370
+ function normalizeYamlEscapedLineBreaks(content) {
2371
+ let normalized = "";
2372
+ let inDoubleQuotedScalar = false;
2373
+ let escaped = false;
2374
+ for (let index = 0; index < content.length; index += 1) {
2375
+ const currentChar = content[index];
2376
+ if (!inDoubleQuotedScalar) {
2377
+ if (currentChar === "\"") inDoubleQuotedScalar = true;
2378
+ normalized += currentChar;
2379
+ continue;
2380
+ }
2381
+ if (escaped) {
2382
+ normalized += currentChar;
2383
+ escaped = false;
2384
+ continue;
2385
+ }
2386
+ if (currentChar === "\\") {
2387
+ const nextChar = content[index + 1];
2388
+ if (nextChar === "\n" || nextChar === "\r") {
2389
+ index += 1;
2390
+ if (nextChar === "\r" && content[index + 1] === "\n") index += 1;
2391
+ while (content[index + 1] === " " || content[index + 1] === " ") index += 1;
2392
+ continue;
2393
+ }
2394
+ normalized += currentChar;
2395
+ escaped = true;
2396
+ continue;
2397
+ }
2398
+ if (currentChar === "\"") inDoubleQuotedScalar = false;
2399
+ normalized += currentChar;
2400
+ }
2401
+ return normalized;
2402
+ }
2403
+ function parseSchemaContent(content) {
2404
+ try {
2405
+ return JSON.parse(content);
2406
+ } catch {
2407
+ return yaml.parse(normalizeYamlEscapedLineBreaks(content));
2408
+ }
2409
+ }
2410
+ //#endregion
2369
2411
  //#region src/resolved-swagger-schema.ts
2370
2412
  var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2371
2413
  parsedRefsCache = /* @__PURE__ */ new Map();
@@ -2431,11 +2473,10 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2431
2473
  if (!response.ok) return null;
2432
2474
  const content = await response.text();
2433
2475
  try {
2434
- const parsed = JSON.parse(content);
2476
+ const parsed = parseSchemaContent(content);
2435
2477
  if (parsed && typeof parsed === "object") return parsed;
2436
2478
  } catch {
2437
- const parsed = yaml.parse(content);
2438
- if (parsed && typeof parsed === "object") return parsed;
2479
+ return null;
2439
2480
  }
2440
2481
  } catch (e) {
2441
2482
  consola.default.debug(e);
@@ -2598,21 +2639,11 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2598
2639
  if (this.externalSchemaCache.has(filePath)) return this.externalSchemaCache.get(filePath) || null;
2599
2640
  if (!node_fs.existsSync(filePath)) return null;
2600
2641
  try {
2601
- const content = node_fs.readFileSync(filePath, "utf8");
2602
- const parsed = JSON.parse(content);
2642
+ const parsed = parseSchemaContent(node_fs.readFileSync(filePath, "utf8"));
2603
2643
  this.externalSchemaCache.set(filePath, parsed);
2604
2644
  return parsed;
2605
2645
  } catch {
2606
- try {
2607
- const content = node_fs.readFileSync(filePath, "utf8");
2608
- const parsed = yaml.parse(content);
2609
- if (parsed && typeof parsed === "object") {
2610
- this.externalSchemaCache.set(filePath, parsed);
2611
- return parsed;
2612
- }
2613
- } catch (e) {
2614
- consola.default.debug(e);
2615
- }
2646
+ consola.default.debug("Failed to parse external schema", filePath);
2616
2647
  }
2617
2648
  return null;
2618
2649
  }
@@ -2809,11 +2840,7 @@ var SwaggerSchemaResolver = class {
2809
2840
  }
2810
2841
  processSwaggerSchemaFile(file) {
2811
2842
  if (typeof file !== "string") return file;
2812
- try {
2813
- return JSON.parse(file);
2814
- } catch {
2815
- return yaml.parse(file);
2816
- }
2843
+ return parseSchemaContent(file);
2817
2844
  }
2818
2845
  normalizeRefValue(ref) {
2819
2846
  const refWithoutSlashBeforeHash = ref.split("/#/").join("#/");
@@ -3623,4 +3650,4 @@ Object.defineProperty(exports, "version", {
3623
3650
  }
3624
3651
  });
3625
3652
 
3626
- //# sourceMappingURL=src-DqcUpLvd.cjs.map
3653
+ //# sourceMappingURL=src-DNKGwk6n.cjs.map