counterfact 1.1.7 → 1.2.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/bin/counterfact.js
CHANGED
|
@@ -135,6 +135,7 @@ async function main(source, destination) {
|
|
|
135
135
|
const swaggerUrl = `${url}/counterfact/swagger/`;
|
|
136
136
|
|
|
137
137
|
const config = {
|
|
138
|
+
alwaysFakeOptionals: options.alwaysFakeOptionals,
|
|
138
139
|
basePath,
|
|
139
140
|
|
|
140
141
|
generate: {
|
|
@@ -268,5 +269,9 @@ program
|
|
|
268
269
|
"base path from which routes will be served (e.g. /api/v1)",
|
|
269
270
|
"",
|
|
270
271
|
)
|
|
272
|
+
.option(
|
|
273
|
+
"--always-fake-optionals",
|
|
274
|
+
"random responses will include optional fields",
|
|
275
|
+
)
|
|
271
276
|
.action(main)
|
|
272
277
|
.parse(process.argv);
|
package/dist/app.js
CHANGED
|
@@ -32,7 +32,7 @@ export async function counterfact(config) {
|
|
|
32
32
|
const registry = new Registry();
|
|
33
33
|
const contextRegistry = new ContextRegistry();
|
|
34
34
|
const codeGenerator = new CodeGenerator(config.openApiPath, config.basePath, config.generate);
|
|
35
|
-
const dispatcher = new Dispatcher(registry, contextRegistry, await loadOpenApiDocument(config.openApiPath));
|
|
35
|
+
const dispatcher = new Dispatcher(registry, contextRegistry, await loadOpenApiDocument(config.openApiPath), config);
|
|
36
36
|
const transpiler = new Transpiler(nodePath.join(modulesPath, "routes").replaceAll("\\", "/"), compiledPathsDirectory, "commonjs");
|
|
37
37
|
const moduleLoader = new ModuleLoader(compiledPathsDirectory, registry, contextRegistry);
|
|
38
38
|
const middleware = koaMiddleware(dispatcher, config);
|
|
@@ -9,11 +9,13 @@ export class Dispatcher {
|
|
|
9
9
|
contextRegistry;
|
|
10
10
|
openApiDocument;
|
|
11
11
|
fetch;
|
|
12
|
-
|
|
12
|
+
config; // Add config property
|
|
13
|
+
constructor(registry, contextRegistry, openApiDocument, config) {
|
|
13
14
|
this.registry = registry;
|
|
14
15
|
this.contextRegistry = contextRegistry;
|
|
15
16
|
this.openApiDocument = openApiDocument;
|
|
16
17
|
this.fetch = fetch;
|
|
18
|
+
this.config = config;
|
|
17
19
|
}
|
|
18
20
|
parameterTypes(parameters) {
|
|
19
21
|
const types = {
|
|
@@ -147,7 +149,7 @@ export class Dispatcher {
|
|
|
147
149
|
},
|
|
148
150
|
query,
|
|
149
151
|
// @ts-expect-error - Might be pushing the limits of what TypeScript can do here
|
|
150
|
-
response: createResponseBuilder(operation ?? { responses: {} }),
|
|
152
|
+
response: createResponseBuilder(operation ?? { responses: {} }, this.config), // Pass config
|
|
151
153
|
tools: new Tools({ headers }),
|
|
152
154
|
});
|
|
153
155
|
if (response === undefined) {
|
|
@@ -29,7 +29,7 @@ function unknownStatusCodeResponse(statusCode) {
|
|
|
29
29
|
status: 500,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
export function createResponseBuilder(operation) {
|
|
32
|
+
export function createResponseBuilder(operation, config) {
|
|
33
33
|
return new Proxy({}, {
|
|
34
34
|
get: (target, statusCode) => ({
|
|
35
35
|
header(name, value) {
|
|
@@ -64,6 +64,11 @@ export function createResponseBuilder(operation) {
|
|
|
64
64
|
};
|
|
65
65
|
},
|
|
66
66
|
random() {
|
|
67
|
+
if (config?.alwaysFakeOptionals) {
|
|
68
|
+
JSONSchemaFaker.option("alwaysFakeOptionals", true);
|
|
69
|
+
JSONSchemaFaker.option("fixedProbabilities", true);
|
|
70
|
+
JSONSchemaFaker.option("optionalsProbability", 1.0);
|
|
71
|
+
}
|
|
67
72
|
if (operation.produces) {
|
|
68
73
|
return this.randomLegacy();
|
|
69
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "counterfact",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "a library for building a fake REST API for testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/server/counterfact.js",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"postinstall": "patch-package"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@changesets/cli": "2.27.
|
|
47
|
+
"@changesets/cli": "2.27.12",
|
|
48
48
|
"@stryker-mutator/core": "8.7.1",
|
|
49
49
|
"@stryker-mutator/jest-runner": "8.7.1",
|
|
50
50
|
"@stryker-mutator/typescript-checker": "8.7.1",
|
|
51
|
-
"@swc/core": "1.10.
|
|
51
|
+
"@swc/core": "1.10.14",
|
|
52
52
|
"@swc/jest": "0.2.37",
|
|
53
53
|
"@testing-library/dom": "10.4.0",
|
|
54
54
|
"@types/jest": "29.5.14",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"@types/koa-bodyparser": "4.3.12",
|
|
58
58
|
"@types/koa-proxy": "1.0.7",
|
|
59
59
|
"@types/koa-static": "4.0.4",
|
|
60
|
-
"@types/lodash": "4.17.
|
|
60
|
+
"@types/lodash": "4.17.15",
|
|
61
61
|
"copyfiles": "2.4.1",
|
|
62
|
-
"eslint": "9.
|
|
62
|
+
"eslint": "9.19.0",
|
|
63
63
|
"eslint-config-hardcore": "47.0.1",
|
|
64
64
|
"eslint-formatter-github-annotations": "0.1.0",
|
|
65
65
|
"eslint-import-resolver-typescript": "3.7.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"eslint-plugin-jest": "28.11.0",
|
|
70
70
|
"eslint-plugin-jest-dom": "5.5.0",
|
|
71
71
|
"eslint-plugin-no-explicit-type-exports": "0.12.1",
|
|
72
|
-
"eslint-plugin-prettier": "5.2.
|
|
72
|
+
"eslint-plugin-prettier": "5.2.3",
|
|
73
73
|
"eslint-plugin-unused-imports": "4.1.4",
|
|
74
74
|
"husky": "9.1.7",
|
|
75
75
|
"jest": "29.7.0",
|
|
@@ -81,12 +81,12 @@
|
|
|
81
81
|
"using-temporary-files": "2.2.1"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@apidevtools/json-schema-ref-parser": "11.
|
|
84
|
+
"@apidevtools/json-schema-ref-parser": "11.9.0",
|
|
85
85
|
"@hapi/accept": "6.0.3",
|
|
86
86
|
"@types/json-schema": "7.0.15",
|
|
87
87
|
"ast-types": "0.14.2",
|
|
88
88
|
"chokidar": "4.0.3",
|
|
89
|
-
"commander": "13.
|
|
89
|
+
"commander": "13.1.0",
|
|
90
90
|
"debug": "4.4.0",
|
|
91
91
|
"fetch": "1.1.0",
|
|
92
92
|
"fs-extra": "11.3.0",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"node-fetch": "3.3.2",
|
|
104
104
|
"open": "10.1.0",
|
|
105
105
|
"patch-package": "8.0.0",
|
|
106
|
-
"precinct": "12.1.
|
|
106
|
+
"precinct": "12.1.3",
|
|
107
107
|
"prettier": "3.4.2",
|
|
108
108
|
"recast": "0.23.9",
|
|
109
109
|
"typescript": "5.7.3"
|