@powerduck/openapi-cli 0.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/LICENSE +21 -0
- package/README.md +702 -0
- package/dist/chunk-XORDZRWZ.js +1 -0
- package/dist/cli.cjs +2 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +2 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +241 -0
- package/dist/index.d.ts +241 -0
- package/dist/index.js +1 -0
- package/package.json +77 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for @powerduck/openapi-cli.
|
|
3
|
+
*/
|
|
4
|
+
type ProtocolName = "http" | "sse" | "websocket" | "graphql" | "grpc" | "mcp";
|
|
5
|
+
type ReportFormat = "json" | "cli" | "html";
|
|
6
|
+
type TestStatus = "passed" | "failed" | "skipped" | "error";
|
|
7
|
+
interface AuthConfig {
|
|
8
|
+
type: "bearer" | "basic" | "apikey" | "none";
|
|
9
|
+
token?: string;
|
|
10
|
+
username?: string;
|
|
11
|
+
password?: string;
|
|
12
|
+
key?: string;
|
|
13
|
+
value?: string;
|
|
14
|
+
in?: "header" | "query";
|
|
15
|
+
}
|
|
16
|
+
interface TlsConfig {
|
|
17
|
+
/** Path to a CA certificate bundle (PEM). */
|
|
18
|
+
caCert?: string;
|
|
19
|
+
/** Path to a client certificate (PEM) for mTLS. */
|
|
20
|
+
clientCert?: string;
|
|
21
|
+
/** Path to a client private key (PEM) for mTLS. */
|
|
22
|
+
clientKey?: string;
|
|
23
|
+
/** Skip TLS certificate verification (insecure). */
|
|
24
|
+
strictSSL?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface FilterConfig {
|
|
27
|
+
/** Only test these HTTP methods (e.g. ["get","post"]). */
|
|
28
|
+
methods?: string[];
|
|
29
|
+
/** Only test paths matching any of these regex patterns. */
|
|
30
|
+
paths?: string[];
|
|
31
|
+
/** Only test operations with these tags. */
|
|
32
|
+
tags?: string[];
|
|
33
|
+
/** Only test these operationIds. */
|
|
34
|
+
operationIds?: string[];
|
|
35
|
+
}
|
|
36
|
+
interface CliConfig {
|
|
37
|
+
/** Path to the OpenAPI 3.2 JSON file. */
|
|
38
|
+
specPath: string;
|
|
39
|
+
/** Override the server URL from the spec. */
|
|
40
|
+
serverUrl?: string;
|
|
41
|
+
/** Directory to write report files. Default: "./openapi-cli-report". */
|
|
42
|
+
outputDir?: string;
|
|
43
|
+
/** Report formats to generate. Default: ["json","cli","html"]. */
|
|
44
|
+
formats?: ReportFormat[];
|
|
45
|
+
/** Filter which operations to test. */
|
|
46
|
+
filter?: FilterConfig;
|
|
47
|
+
/** Max concurrent requests. Default: 5. */
|
|
48
|
+
concurrency?: number;
|
|
49
|
+
/** Per-request timeout in ms. Default: 30000. */
|
|
50
|
+
timeout?: number;
|
|
51
|
+
/** HTTP(S) proxy URL (e.g. http://proxy:8080). */
|
|
52
|
+
proxy?: string;
|
|
53
|
+
/** TLS / certificate configuration. */
|
|
54
|
+
tls?: TlsConfig;
|
|
55
|
+
/** Extra headers sent with every request. */
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
/** Authentication configuration. */
|
|
58
|
+
auth?: AuthConfig;
|
|
59
|
+
/** Postman variables ({{name}}) to inject. */
|
|
60
|
+
variables?: Record<string, string>;
|
|
61
|
+
/** Exit with non-zero code if any test fails. Default: true. */
|
|
62
|
+
failOnError?: boolean;
|
|
63
|
+
/** Path to a .env file (KEY=VALUE per line). */
|
|
64
|
+
envFile?: string;
|
|
65
|
+
/** gRPC-specific: use server reflection. Default: true. */
|
|
66
|
+
grpcReflection?: boolean;
|
|
67
|
+
/** gRPC-specific: paths to .proto files or directories. */
|
|
68
|
+
grpcProtoPaths?: string[];
|
|
69
|
+
/** MCP-specific: transport for MCP operations. Default: "streamable-http". */
|
|
70
|
+
mcpTransport?: "streamable-http" | "stdio";
|
|
71
|
+
/** MCP stdio: command to spawn. */
|
|
72
|
+
mcpCommand?: string;
|
|
73
|
+
/** MCP stdio: command arguments. */
|
|
74
|
+
mcpArgs?: string[];
|
|
75
|
+
/** MCP stdio: working directory. */
|
|
76
|
+
mcpCwd?: string;
|
|
77
|
+
}
|
|
78
|
+
interface AssertionResult {
|
|
79
|
+
name: string;
|
|
80
|
+
passed: boolean;
|
|
81
|
+
error?: string;
|
|
82
|
+
}
|
|
83
|
+
interface TestResult {
|
|
84
|
+
operationId: string;
|
|
85
|
+
path: string;
|
|
86
|
+
method: string;
|
|
87
|
+
protocol: ProtocolName | string;
|
|
88
|
+
status: TestStatus;
|
|
89
|
+
durationMs: number;
|
|
90
|
+
response?: {
|
|
91
|
+
status?: number;
|
|
92
|
+
statusText?: string;
|
|
93
|
+
contentType?: string;
|
|
94
|
+
sizeBytes?: number;
|
|
95
|
+
body?: unknown;
|
|
96
|
+
text?: string;
|
|
97
|
+
headers?: Record<string, string>;
|
|
98
|
+
events?: unknown[];
|
|
99
|
+
streaming?: boolean;
|
|
100
|
+
};
|
|
101
|
+
assertions?: AssertionResult[];
|
|
102
|
+
error?: string;
|
|
103
|
+
timestamp: string;
|
|
104
|
+
}
|
|
105
|
+
interface TestSummary {
|
|
106
|
+
total: number;
|
|
107
|
+
passed: number;
|
|
108
|
+
failed: number;
|
|
109
|
+
errors: number;
|
|
110
|
+
skipped: number;
|
|
111
|
+
durationMs: number;
|
|
112
|
+
passRate: number;
|
|
113
|
+
}
|
|
114
|
+
interface TestReport {
|
|
115
|
+
summary: TestSummary;
|
|
116
|
+
results: TestResult[];
|
|
117
|
+
config: CliConfig;
|
|
118
|
+
generatedAt: string;
|
|
119
|
+
version: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Run all tests defined in the spec.
|
|
124
|
+
*/
|
|
125
|
+
declare function runTests(config: CliConfig): Promise<TestReport>;
|
|
126
|
+
|
|
127
|
+
declare const DEFAULT_CONFIG: Required<Pick<CliConfig, "outputDir" | "formats" | "concurrency" | "timeout" | "failOnError" | "grpcReflection" | "mcpTransport">>;
|
|
128
|
+
interface CliArgs {
|
|
129
|
+
spec?: string;
|
|
130
|
+
server?: string;
|
|
131
|
+
output?: string;
|
|
132
|
+
format?: string;
|
|
133
|
+
method?: string;
|
|
134
|
+
path?: string;
|
|
135
|
+
tag?: string;
|
|
136
|
+
operationId?: string;
|
|
137
|
+
concurrency?: number;
|
|
138
|
+
timeout?: number;
|
|
139
|
+
proxy?: string;
|
|
140
|
+
ca?: string;
|
|
141
|
+
cert?: string;
|
|
142
|
+
key?: string;
|
|
143
|
+
insecure?: boolean;
|
|
144
|
+
header?: string[];
|
|
145
|
+
bearer?: string;
|
|
146
|
+
variable?: string[];
|
|
147
|
+
config?: string;
|
|
148
|
+
env?: string;
|
|
149
|
+
failOnError?: boolean;
|
|
150
|
+
grpcReflection?: boolean;
|
|
151
|
+
grpcProto?: string[];
|
|
152
|
+
mcpTransport?: string;
|
|
153
|
+
mcpCommand?: string;
|
|
154
|
+
mcpArgs?: string;
|
|
155
|
+
mcpCwd?: string;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Resolve the final CliConfig from CLI args, an optional config file,
|
|
159
|
+
* environment variables, and defaults.
|
|
160
|
+
*/
|
|
161
|
+
declare function resolveConfig(args: CliArgs): CliConfig;
|
|
162
|
+
/**
|
|
163
|
+
* Check whether a spec path is a remote URL.
|
|
164
|
+
*/
|
|
165
|
+
declare function isRemoteSpec(specPath: string): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Load and parse the OpenAPI spec from a local file or remote URL.
|
|
168
|
+
*/
|
|
169
|
+
declare function loadSpec(config: CliConfig): Promise<any>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Assertion engine. Supports two sources:
|
|
173
|
+
* 1. Declarative `x-tests` array on the operation (simple, JSON-serializable).
|
|
174
|
+
* 2. Postman `x-postman-scripts.test` string (full pm.* API, executed by
|
|
175
|
+
* @powerduck/request's script sandbox and surfaced via onAssertion).
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
interface DeclarativeAssertion {
|
|
179
|
+
name: string;
|
|
180
|
+
/** What to assert. */
|
|
181
|
+
assert: "status" | "header" | "bodyContains" | "jsonPath" | "responseTime" | "bodyEquals";
|
|
182
|
+
/** Expected status code (for assert=status). */
|
|
183
|
+
value?: number;
|
|
184
|
+
/** Header name (for assert=header). */
|
|
185
|
+
key?: string;
|
|
186
|
+
/** Substring to check (for assert=header / bodyContains). */
|
|
187
|
+
contains?: string;
|
|
188
|
+
/** JSONPath expression (for assert=jsonPath). Simple dot-notation supported. */
|
|
189
|
+
path?: string;
|
|
190
|
+
/** Expected value at path (for assert=jsonPath). */
|
|
191
|
+
equals?: unknown;
|
|
192
|
+
/** Whether the path must exist (for assert=jsonPath). */
|
|
193
|
+
exists?: boolean;
|
|
194
|
+
/** Max response time in ms (for assert=responseTime). */
|
|
195
|
+
max?: number;
|
|
196
|
+
/** Expected body string (for assert=bodyEquals). */
|
|
197
|
+
body?: string;
|
|
198
|
+
}
|
|
199
|
+
interface AssertionContext {
|
|
200
|
+
status?: number;
|
|
201
|
+
headers?: Record<string, string>;
|
|
202
|
+
body?: unknown;
|
|
203
|
+
bodyText?: string;
|
|
204
|
+
durationMs: number;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Run declarative assertions against a response context.
|
|
208
|
+
*/
|
|
209
|
+
declare function runDeclarativeAssertions(assertions: DeclarativeAssertion[], ctx: AssertionContext): AssertionResult[];
|
|
210
|
+
/**
|
|
211
|
+
* Minimal JSONPath resolver supporting dot notation and array indices.
|
|
212
|
+
* e.g. "$.data.items[0].id" or "data.user.name"
|
|
213
|
+
*/
|
|
214
|
+
declare function resolveJsonPath(obj: unknown, path: string): unknown;
|
|
215
|
+
/**
|
|
216
|
+
* Extract declarative assertions from an OpenAPI operation.
|
|
217
|
+
* Looks for `x-tests` on the operation or path item.
|
|
218
|
+
*/
|
|
219
|
+
declare function extractAssertions(operation: any, pathItem?: any): DeclarativeAssertion[];
|
|
220
|
+
/**
|
|
221
|
+
* Extract Postman test scripts from an operation.
|
|
222
|
+
* Looks for `x-postman-scripts.test` on the operation.
|
|
223
|
+
*/
|
|
224
|
+
declare function extractPostmanScripts(operation: any): string | undefined;
|
|
225
|
+
|
|
226
|
+
declare function generateJsonReport(report: TestReport, outputDir: string): string;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* CLI reporter: prints a colored, human-readable summary to stdout.
|
|
230
|
+
* No external dependencies — uses ANSI escape codes directly.
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
declare function generateCliReport(report: TestReport): string;
|
|
234
|
+
/**
|
|
235
|
+
* Print the CLI report to stdout and return it.
|
|
236
|
+
*/
|
|
237
|
+
declare function printCliReport(report: TestReport): string;
|
|
238
|
+
|
|
239
|
+
declare function generateHtmlReport(report: TestReport, outputDir: string): string;
|
|
240
|
+
|
|
241
|
+
export { type AssertionResult, type AuthConfig, type CliArgs, type CliConfig, DEFAULT_CONFIG, type DeclarativeAssertion, type FilterConfig, type ProtocolName, type ReportFormat, type TestReport, type TestResult, type TestStatus, type TestSummary, type TlsConfig, extractAssertions, extractPostmanScripts, generateCliReport, generateHtmlReport, generateJsonReport, isRemoteSpec, loadSpec, printCliReport, resolveConfig, resolveJsonPath, runDeclarativeAssertions, runTests };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DEFAULT_CONFIG as o,extractAssertions as r,extractPostmanScripts as m,generateCliReport as p,generateHtmlReport as t,generateJsonReport as R,isRemoteSpec as Z,loadSpec as c,printCliReport as e,resolveConfig as f,resolveJsonPath as h,runDeclarativeAssertions as i,runTests as j}from"./chunk-XORDZRWZ.js";export{o as DEFAULT_CONFIG,r as extractAssertions,m as extractPostmanScripts,p as generateCliReport,t as generateHtmlReport,R as generateJsonReport,Z as isRemoteSpec,c as loadSpec,e as printCliReport,f as resolveConfig,h as resolveJsonPath,i as runDeclarativeAssertions,j as runTests};
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@powerduck/openapi-cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "CI-ready CLI for batch-testing OpenAPI documents across HTTP, SSE, WebSocket, GraphQL, gRPC and MCP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"openapi-cli": "./dist/cli.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.17"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc --noEmit && tsup",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:watch": "vitest",
|
|
34
|
+
"test:coverage": "vitest run --coverage",
|
|
35
|
+
"prepublishOnly": "npm run build",
|
|
36
|
+
"check": "tsc --noEmit && vitest run"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"openapi",
|
|
40
|
+
"cli",
|
|
41
|
+
"testing",
|
|
42
|
+
"grpc",
|
|
43
|
+
"mcp",
|
|
44
|
+
"graphql",
|
|
45
|
+
"sse",
|
|
46
|
+
"websocket",
|
|
47
|
+
"ci",
|
|
48
|
+
"api-testing",
|
|
49
|
+
"contract-testing"
|
|
50
|
+
],
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"author": "Powerduck limited",
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@powerduck/openapi-parser": "^0.3.3",
|
|
55
|
+
"@powerduck/request": "^0.2.2",
|
|
56
|
+
"commander": "^15.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/node": "^20.14.0",
|
|
60
|
+
"terser": "^5.51.2",
|
|
61
|
+
"tsup": "^8.0.0",
|
|
62
|
+
"typescript": "^5.5.0",
|
|
63
|
+
"@vitest/coverage-v8": "^3.2.7",
|
|
64
|
+
"vitest": "^3.2.7"
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "git+https://github.com/PowerDuckie/openapi-cli.git"
|
|
69
|
+
},
|
|
70
|
+
"bugs": {
|
|
71
|
+
"url": "https://github.com/PowerDuckie/openapi-cli/issues"
|
|
72
|
+
},
|
|
73
|
+
"homepage": "https://github.com/PowerDuckie/openapi-cli#readme",
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
}
|
|
77
|
+
}
|