@schmock/cli 1.9.4 → 1.9.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.
package/dist/bin.js CHANGED
@@ -23186,7 +23186,7 @@ var require_ajv = __commonJS((exports, module) => {
23186
23186
  });
23187
23187
 
23188
23188
  // src/cli.ts
23189
- import { readFileSync as readFileSync2, watch } from "node:fs";
23189
+ import { readFileSync, watch } from "node:fs";
23190
23190
  import { createServer as createServer2 } from "node:http";
23191
23191
  import { parseArgs } from "node:util";
23192
23192
 
@@ -23940,7 +23940,7 @@ function schmock(config) {
23940
23940
  return callableInstance;
23941
23941
  }
23942
23942
  // ../openapi/package.json
23943
- var version = "1.9.4";
23943
+ var version = "1.9.5";
23944
23944
 
23945
23945
  // ../openapi/src/utils.ts
23946
23946
  function isRecord(value) {
@@ -33339,7 +33339,12 @@ async function parseSpec(source) {
33339
33339
  const copy = structuredClone(source);
33340
33340
  stripRootExtensions(copy);
33341
33341
  ensurePathsKey(copy);
33342
- api = await import_swagger_parser.default.dereference(copy);
33342
+ const hasRefs = JSON.stringify(copy).includes('"$ref"');
33343
+ if (hasRefs) {
33344
+ api = await import_swagger_parser.default.dereference(copy);
33345
+ } else {
33346
+ api = copy;
33347
+ }
33343
33348
  } else {
33344
33349
  throw new Error("Invalid OpenAPI spec: must be a string path or an OpenAPI document object");
33345
33350
  }
@@ -33942,14 +33947,14 @@ function generateResponseBody(schema, seed) {
33942
33947
  }
33943
33948
 
33944
33949
  // ../openapi/src/seed.ts
33945
- import { readFileSync } from "node:fs";
33946
- function loadSeed(config, resources) {
33950
+ async function loadSeed(config, resources) {
33947
33951
  const result = new Map;
33948
33952
  for (const [resourceName, source] of Object.entries(config)) {
33949
33953
  const resource = resources.find((r2) => r2.name === resourceName);
33950
33954
  if (Array.isArray(source)) {
33951
33955
  result.set(resourceName, [...source]);
33952
33956
  } else if (typeof source === "string") {
33957
+ const { readFileSync } = await import("node:fs");
33953
33958
  const content = readFileSync(source, "utf-8");
33954
33959
  let parsed;
33955
33960
  try {
@@ -33980,7 +33985,7 @@ function loadSeed(config, resources) {
33980
33985
  async function openapi(options) {
33981
33986
  const spec = await parseSpec(options.spec);
33982
33987
  const { resources, nonCrudPaths } = detectCrudResources(spec.paths);
33983
- const seedData = options.seed ? loadSeed(options.seed, resources) : new Map;
33988
+ const seedData = options.seed ? await loadSeed(options.seed, resources) : new Map;
33984
33989
  const allParsedPaths = new Map;
33985
33990
  for (const pp of [...spec.paths]) {
33986
33991
  allParsedPaths.set(`${pp.method} ${pp.path}`, pp);
@@ -34040,7 +34045,7 @@ function isSeedSource(value) {
34040
34045
  return Array.isArray(value) || typeof value === "string" || typeof value === "object" && value !== null && "count" in value;
34041
34046
  }
34042
34047
  function loadSeedFile(seedPath) {
34043
- const raw = readFileSync2(seedPath, "utf-8");
34048
+ const raw = readFileSync(seedPath, "utf-8");
34044
34049
  const parsed = JSON.parse(raw);
34045
34050
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
34046
34051
  throw new Error(`Seed file must contain a JSON object, got: ${typeof parsed}`);
package/dist/index.js CHANGED
@@ -23185,7 +23185,7 @@ var require_ajv = __commonJS((exports, module) => {
23185
23185
  });
23186
23186
 
23187
23187
  // src/cli.ts
23188
- import { readFileSync as readFileSync2, watch } from "node:fs";
23188
+ import { readFileSync, watch } from "node:fs";
23189
23189
  import { createServer as createServer2 } from "node:http";
23190
23190
  import { parseArgs } from "node:util";
23191
23191
 
@@ -23939,7 +23939,7 @@ function schmock(config) {
23939
23939
  return callableInstance;
23940
23940
  }
23941
23941
  // ../openapi/package.json
23942
- var version = "1.9.4";
23942
+ var version = "1.9.5";
23943
23943
 
23944
23944
  // ../openapi/src/utils.ts
23945
23945
  function isRecord(value) {
@@ -33338,7 +33338,12 @@ async function parseSpec(source) {
33338
33338
  const copy = structuredClone(source);
33339
33339
  stripRootExtensions(copy);
33340
33340
  ensurePathsKey(copy);
33341
- api = await import_swagger_parser.default.dereference(copy);
33341
+ const hasRefs = JSON.stringify(copy).includes('"$ref"');
33342
+ if (hasRefs) {
33343
+ api = await import_swagger_parser.default.dereference(copy);
33344
+ } else {
33345
+ api = copy;
33346
+ }
33342
33347
  } else {
33343
33348
  throw new Error("Invalid OpenAPI spec: must be a string path or an OpenAPI document object");
33344
33349
  }
@@ -33941,14 +33946,14 @@ function generateResponseBody(schema, seed) {
33941
33946
  }
33942
33947
 
33943
33948
  // ../openapi/src/seed.ts
33944
- import { readFileSync } from "node:fs";
33945
- function loadSeed(config, resources) {
33949
+ async function loadSeed(config, resources) {
33946
33950
  const result = new Map;
33947
33951
  for (const [resourceName, source] of Object.entries(config)) {
33948
33952
  const resource = resources.find((r2) => r2.name === resourceName);
33949
33953
  if (Array.isArray(source)) {
33950
33954
  result.set(resourceName, [...source]);
33951
33955
  } else if (typeof source === "string") {
33956
+ const { readFileSync } = await import("node:fs");
33952
33957
  const content = readFileSync(source, "utf-8");
33953
33958
  let parsed;
33954
33959
  try {
@@ -33979,7 +33984,7 @@ function loadSeed(config, resources) {
33979
33984
  async function openapi(options) {
33980
33985
  const spec = await parseSpec(options.spec);
33981
33986
  const { resources, nonCrudPaths } = detectCrudResources(spec.paths);
33982
- const seedData = options.seed ? loadSeed(options.seed, resources) : new Map;
33987
+ const seedData = options.seed ? await loadSeed(options.seed, resources) : new Map;
33983
33988
  const allParsedPaths = new Map;
33984
33989
  for (const pp of [...spec.paths]) {
33985
33990
  allParsedPaths.set(`${pp.method} ${pp.path}`, pp);
@@ -34039,7 +34044,7 @@ function isSeedSource(value) {
34039
34044
  return Array.isArray(value) || typeof value === "string" || typeof value === "object" && value !== null && "count" in value;
34040
34045
  }
34041
34046
  function loadSeedFile(seedPath) {
34042
- const raw = readFileSync2(seedPath, "utf-8");
34047
+ const raw = readFileSync(seedPath, "utf-8");
34043
34048
  const parsed = JSON.parse(raw);
34044
34049
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
34045
34050
  throw new Error(`Seed file must contain a JSON object, got: ${typeof parsed}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@schmock/cli",
3
3
  "description": "CLI for running Schmock mock servers from OpenAPI specs",
4
- "version": "1.9.4",
4
+ "version": "1.9.5",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@schmock/core": "^1.9.4",
36
- "@schmock/openapi": "^1.9.4"
35
+ "@schmock/core": "^1.9.5",
36
+ "@schmock/openapi": "^1.9.5"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@amiceli/vitest-cucumber": "^6.2.0",