swaggerizer 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -301,12 +301,39 @@ What is checked, judged from the point of view of code using the generated clien
301
301
 
302
302
  Renaming a path parameter (`/pets/{id}` → `/pets/{petId}`) isn't reported, because the generated call doesn't change.
303
303
 
304
+ ## Request validation
305
+
306
+ `serve --validate enforce` checks every matched request against the spec and answers `400` when it does not fit, so the mock cannot prove an integration the real API will reject:
307
+
308
+ ```bash
309
+ npx swaggerizer serve --folder ./specs --validate enforce
310
+ ```
311
+
312
+ | Mode | What happens |
313
+ | --- | --- |
314
+ | `off` (default) | requests are not inspected |
315
+ | `warn` | problems appear in the admin page's Live requests (`⚠ n`) and the request is answered normally |
316
+ | `enforce` | problems answer `400` with the issues; the request is not proxied and custom handlers do not run |
317
+
318
+ Checks cover path, query, header and cookie parameters and JSON or `x-www-form-urlencoded` request bodies. A media type the tool cannot parse is reported as skipped rather than failed. Set the mode per spec with `validate`, exempt individual operations with `validateIgnore`, or override it for one request with `X-Swaggerizer-Validation: off | warn | enforce`:
319
+
320
+ ```ts
321
+ export default defineConfig({
322
+ validate: "warn",
323
+ specs: {
324
+ orders: { validate: "enforce", validateIgnore: ["POST /legacy/import"] }
325
+ }
326
+ });
327
+ ```
328
+
329
+ `GET {endpoint}/api/validation` reports the active mode and which operations declare something to check. Responses are not validated: the mock serves bodies taken from the spec itself.
330
+
304
331
  ## CLI
305
332
 
306
333
  ```
307
334
  swaggerizer serve [--config <file>] [--folder <files|dirs|urls…>] [-H 'Name: value'] [--port 8080] [--host] [--endpoint swaggerizer]
308
335
  [--no-ui] [--proxy <url>] [--delay <ms>] [--fallback <url>] [--state-file <file>]
309
- [--generated <dir>] [--watch] [--silent]
336
+ [--generated <dir>] [--watch] [--validate off|warn|enforce] [--silent]
310
337
  swaggerizer generate [--config <file>] [--folder …] [-H 'Name: value'] [--output src/api] [--client fetch] [--base-url <url>]
311
338
  [--no-mock] [--state-file <file>] [--fail-on breaking|warning|any|none] [--yes]
312
339
  [--runtime-import swaggerizer/msw] [--verbose]
package/dist/admin.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type http from "node:http";
2
- import type { OperationState, RequestLogEntry, ScenarioSelection, SpecSummary, SwaggerizerState } from "./types";
2
+ import type { OperationState, RequestLogEntry, ScenarioSelection, SpecSummary, SwaggerizerState, ValidationInfo } from "./types";
3
3
  export interface AdminContext {
4
4
  basePath: string;
5
5
  ui: boolean;
@@ -14,6 +14,7 @@ export interface AdminContext {
14
14
  getRequestLog: (sinceId?: number) => RequestLogEntry[];
15
15
  recordRequest: (entry: Omit<RequestLogEntry, "id" | "time">) => RequestLogEntry;
16
16
  getSpecDocument: (id: string) => any;
17
+ getValidation: () => ValidationInfo;
17
18
  }
18
19
  export interface AdminRequest {
19
20
  method: string;
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../src/admin.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,gBAAgB,CAAC;IACjC,MAAM,EAAE,CAAC,SAAS,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,KAAK,cAAc,EAAE,CAAC;IACjF,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IAChE,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC;IAC9D,MA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,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IAChE,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC;IAC9D,MAAM,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACxC,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,eAAe,EAAE,CAAC;IACvD,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,MAAM,CAAC,KAAK,eAAe,CAAC;IAChF,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,GAAG,CAAC;IACrC,aAAa,EAAE,MAAM,cAAc,CAAC;CACrC;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,eAAe,CAAC;IACvB,IAAI,EAAE,GAAG,CAAC;IACV,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA8BD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAsBvE;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY;kBASlB,YAAY,OAAO,IAAI,CAAC,cAAc,KAAG,OAAO,CAAC,OAAO,CAAC;;EA6HrF"}
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAyDA,wBAAsB,GAAG,CAAC,IAAI,WAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA4H5D"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AA0DA,wBAAsB,GAAG,CAAC,IAAI,WAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAiI5D"}