counterfact 0.21.1 → 0.21.3
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# counterfact
|
|
2
2
|
|
|
3
|
+
## 0.21.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1d13668: fix an issue where the random() function doesn't recognize it should use OpenAPI2
|
|
8
|
+
|
|
9
|
+
## 0.21.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 9ca754f: fix another bug where OpenAPI2 puts the produces proprty in the root
|
|
14
|
+
|
|
3
15
|
## 0.21.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
package/src/server/dispatcher.js
CHANGED
|
@@ -44,7 +44,17 @@ export class Dispatcher {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
operationForPathAndMethod(path, method) {
|
|
47
|
-
|
|
47
|
+
const operation =
|
|
48
|
+
this.openApiDocument?.paths?.[path]?.[method.toLowerCase()];
|
|
49
|
+
|
|
50
|
+
if (this.openApiDocument?.produces) {
|
|
51
|
+
return {
|
|
52
|
+
produces: this.openApiDocument.produces,
|
|
53
|
+
...operation,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return operation;
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
async request({ method, path, headers, body, query, req }) {
|
|
@@ -101,7 +101,8 @@ export class OperationTypeCoder extends Coder {
|
|
|
101
101
|
|
|
102
102
|
const responseType = new ResponseTypeCoder(
|
|
103
103
|
this.requirement.get("responses"),
|
|
104
|
-
this.requirement.get("produces")?.data
|
|
104
|
+
this.requirement.get("produces")?.data ??
|
|
105
|
+
this.requirement.specification?.rootRequirement?.get("produces")?.data
|
|
105
106
|
).write(script);
|
|
106
107
|
|
|
107
108
|
const proxyType = "(url: string) => { proxyUrl: string }";
|
|
@@ -538,4 +538,25 @@ describe("given an invalid path", () => {
|
|
|
538
538
|
"Could not find a PUT method matching /your/left/foot/in/and/your/right/foot/out\n"
|
|
539
539
|
);
|
|
540
540
|
});
|
|
541
|
+
|
|
542
|
+
it("attaches the root produces array to an operation", () => {
|
|
543
|
+
const registry = new Registry();
|
|
544
|
+
|
|
545
|
+
registry.add("/your/{side}/{bodyPart}/in/and/your/left/foot/out", {
|
|
546
|
+
PUT() {
|
|
547
|
+
return {
|
|
548
|
+
status: 201,
|
|
549
|
+
body: "ok",
|
|
550
|
+
};
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
const dispatcher = new Dispatcher(registry, new ContextRegistry(), {
|
|
555
|
+
produces: ["text/plain"],
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
const operation = dispatcher.operationForPathAndMethod("/hello", "GET");
|
|
559
|
+
|
|
560
|
+
expect(operation.produces).toStrictEqual(["text/plain"]);
|
|
561
|
+
});
|
|
541
562
|
});
|
|
@@ -53,15 +53,27 @@ exports[`an OperationTypeCoder generates a complex post operation (OpenAPI 2 wit
|
|
|
53
53
|
response: ResponseBuilderFactory<{
|
|
54
54
|
200: {
|
|
55
55
|
headers: {};
|
|
56
|
-
content: {
|
|
56
|
+
content: {
|
|
57
|
+
\\"application/json\\": {
|
|
58
|
+
schema: Type;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
57
61
|
};
|
|
58
62
|
400: {
|
|
59
63
|
headers: {};
|
|
60
|
-
content: {
|
|
64
|
+
content: {
|
|
65
|
+
\\"application/json\\": {
|
|
66
|
+
schema: Type;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
61
69
|
};
|
|
62
70
|
[statusCode in Exclude<HttpStatusCode, 200 | 400>]: {
|
|
63
71
|
headers: {};
|
|
64
|
-
content: {
|
|
72
|
+
content: {
|
|
73
|
+
\\"application/json\\": {
|
|
74
|
+
schema: Type;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
65
77
|
};
|
|
66
78
|
}>;
|
|
67
79
|
proxy: (url: string) => { proxyUrl: string };
|