counterfact 2.0.0 → 2.0.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.
@@ -6,6 +6,17 @@ import { ResponsesTypeCoder } from "./responses-type-coder.js";
6
6
  import { SchemaTypeCoder } from "./schema-type-coder.js";
7
7
  import { TypeCoder } from "./type-coder.js";
8
8
  import { ParameterExportTypeCoder } from "./parameter-export-type-coder.js";
9
+ function sanitizeIdentifier(value) {
10
+ // Treat any run of non-identifier characters as a camelCase separator
11
+ let result = value.replaceAll(/[^\w$]+(?<next>.)/gu, (_, char) => char.toUpperCase());
12
+ // Strip any trailing non-identifier characters (no following char to capitalize)
13
+ result = result.replaceAll(/[^\w$]/gu, "");
14
+ // If the identifier starts with a digit, prefix with an underscore
15
+ if (/^\d/u.test(result)) {
16
+ result = `_${result}`;
17
+ }
18
+ return result || "_";
19
+ }
9
20
  export class OperationTypeCoder extends TypeCoder {
10
21
  constructor(requirement, requestMethod, securitySchemes = []) {
11
22
  super(requirement);
@@ -17,7 +28,9 @@ export class OperationTypeCoder extends TypeCoder {
17
28
  }
18
29
  getOperationBaseName() {
19
30
  const operationId = this.requirement.get("operationId")?.data;
20
- return operationId || `HTTP_${this.requestMethod.toUpperCase()}`;
31
+ return operationId
32
+ ? sanitizeIdentifier(operationId)
33
+ : `HTTP_${this.requestMethod.toUpperCase()}`;
21
34
  }
22
35
  names() {
23
36
  return super.names(this.getOperationBaseName());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterfact",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Generate a TypeScript-based mock server from an OpenAPI spec in seconds — with stateful routes, hot reload, and REPL support.",
5
5
  "type": "module",
6
6
  "main": "./dist/app.js",
@@ -81,7 +81,7 @@
81
81
  "@stryker-mutator/core": "9.5.1",
82
82
  "@stryker-mutator/jest-runner": "9.5.1",
83
83
  "@stryker-mutator/typescript-checker": "9.5.1",
84
- "@swc/core": "1.15.13",
84
+ "@swc/core": "1.15.17",
85
85
  "@swc/jest": "0.2.39",
86
86
  "@testing-library/dom": "10.4.1",
87
87
  "@types/debug": "^4.1.12",
@@ -134,7 +134,7 @@
134
134
  "js-yaml": "4.1.1",
135
135
  "json-schema-faker": "0.5.9",
136
136
  "jsonwebtoken": "9.0.3",
137
- "koa": "3.1.1",
137
+ "koa": "3.1.2",
138
138
  "koa-bodyparser": "4.4.1",
139
139
  "koa-proxies": "0.12.4",
140
140
  "koa2-swagger-ui": "5.12.0",