@stdy/cli 0.4.2
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 +93 -0
- package/README.md +247 -0
- package/package.json +38 -0
- package/steady.js +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
21
|
+
|
|
22
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
+
software that is protected by the license key.
|
|
25
|
+
|
|
26
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
+
of the licensor in the software. Any use of the licensor's trademarks is subject
|
|
28
|
+
to applicable law.
|
|
29
|
+
|
|
30
|
+
## Patents
|
|
31
|
+
|
|
32
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
+
sale, import and have imported the software, in each case subject to the
|
|
35
|
+
limitations and conditions in this license. This license does not cover any
|
|
36
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
+
the software. If you or your company make any written claim that the software
|
|
38
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
+
the software granted under these terms ends immediately. If your company makes
|
|
40
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
+
company.
|
|
42
|
+
|
|
43
|
+
## Notices
|
|
44
|
+
|
|
45
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
+
also gets a copy of these terms.
|
|
47
|
+
|
|
48
|
+
If you modify the software, you must include in any modified copies of the
|
|
49
|
+
software prominent notices stating that you have modified the software.
|
|
50
|
+
|
|
51
|
+
## No Other Rights
|
|
52
|
+
|
|
53
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
+
these terms.
|
|
55
|
+
|
|
56
|
+
## Termination
|
|
57
|
+
|
|
58
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
+
to terminate automatically and permanently.
|
|
65
|
+
|
|
66
|
+
## No Liability
|
|
67
|
+
|
|
68
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
+
legal claim.*
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
+
software the licensor makes available under these terms, including any portion
|
|
77
|
+
of it.
|
|
78
|
+
|
|
79
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
+
organization that you work for, plus all organizations that have control over,
|
|
83
|
+
are under the control of, or are under common control with that
|
|
84
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
+
otherwise. Control can be direct or indirect.
|
|
87
|
+
|
|
88
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
+
these terms.
|
|
90
|
+
|
|
91
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
+
|
|
93
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Steady
|
|
2
|
+
|
|
3
|
+
OpenAPI 3.0/3.1 mock server built with Deno. Validates requests against specs
|
|
4
|
+
and generates responses from schemas or examples.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
# npm (recommended)
|
|
10
|
+
npm install -g @stdy/cli
|
|
11
|
+
|
|
12
|
+
# Or with Deno
|
|
13
|
+
deno install -gAn steady jsr:@steady/cli
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Start mock server
|
|
20
|
+
steady api.yaml
|
|
21
|
+
|
|
22
|
+
# Validate spec without starting server
|
|
23
|
+
steady validate api.yaml
|
|
24
|
+
|
|
25
|
+
# Watch for spec changes
|
|
26
|
+
steady -r api.yaml
|
|
27
|
+
|
|
28
|
+
# Interactive mode with expandable request logs
|
|
29
|
+
steady -i api.yaml
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
steady [command] [options] <spec-file>
|
|
36
|
+
|
|
37
|
+
Commands:
|
|
38
|
+
validate <spec> Validate an OpenAPI spec (doesn't start server)
|
|
39
|
+
<spec> Start mock server (default)
|
|
40
|
+
|
|
41
|
+
Options:
|
|
42
|
+
-p, --port <port> Override server port (default: from spec or 3000)
|
|
43
|
+
-r, --auto-reload Restart on spec file changes
|
|
44
|
+
-i, --interactive Interactive TUI with expandable logs
|
|
45
|
+
--log-level <level> summary | details | full (default: summary)
|
|
46
|
+
--log-bodies Show request/response bodies
|
|
47
|
+
--log=false Disable request logging
|
|
48
|
+
--strict Reject invalid requests (default)
|
|
49
|
+
--relaxed Log warnings but return responses anyway
|
|
50
|
+
-h, --help Show help
|
|
51
|
+
|
|
52
|
+
Generator Options:
|
|
53
|
+
--generator-array-size=<n> Exact size for all generated arrays
|
|
54
|
+
--generator-array-min=<n> Minimum array size (default: 1)
|
|
55
|
+
--generator-array-max=<n> Maximum array size (default: 1)
|
|
56
|
+
--generator-seed=<n> Seed for deterministic generation (-1 for random)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Port Configuration
|
|
60
|
+
|
|
61
|
+
The server port is determined in this order:
|
|
62
|
+
|
|
63
|
+
1. `-p, --port` CLI flag
|
|
64
|
+
2. `servers[0].url` port in your spec
|
|
65
|
+
3. Default: 3000
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
# Option 1: CLI flag takes precedence
|
|
69
|
+
steady -p 8080 api.yaml
|
|
70
|
+
|
|
71
|
+
# Option 2: Set in spec
|
|
72
|
+
servers:
|
|
73
|
+
- url: http://localhost:8080
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Response Generation
|
|
77
|
+
|
|
78
|
+
Steady generates responses in this order:
|
|
79
|
+
|
|
80
|
+
1. `example` field on the media type
|
|
81
|
+
2. First entry from `examples` map
|
|
82
|
+
3. Generated from `schema` (if present)
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
responses:
|
|
86
|
+
200:
|
|
87
|
+
content:
|
|
88
|
+
application/json:
|
|
89
|
+
# Option 1: explicit example (preferred)
|
|
90
|
+
example:
|
|
91
|
+
id: 123
|
|
92
|
+
name: "Alice"
|
|
93
|
+
|
|
94
|
+
# Option 2: multiple examples
|
|
95
|
+
examples:
|
|
96
|
+
success:
|
|
97
|
+
value: { id: 123, name: "Alice" }
|
|
98
|
+
|
|
99
|
+
# Option 3: generate from schema
|
|
100
|
+
schema:
|
|
101
|
+
$ref: "#/components/schemas/User"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Request Validation
|
|
105
|
+
|
|
106
|
+
In `--strict` mode (default), requests are validated against:
|
|
107
|
+
|
|
108
|
+
- **Path parameters** - type coercion and schema validation
|
|
109
|
+
- **Query parameters** - required check, type validation
|
|
110
|
+
- **Headers** - required headers, schema validation
|
|
111
|
+
- **Cookies** - required cookies, schema validation
|
|
112
|
+
- **Request body** - JSON Schema validation, content-type check
|
|
113
|
+
|
|
114
|
+
Invalid requests return 400 with validation errors. In `--relaxed` mode,
|
|
115
|
+
validation errors are logged but responses are still returned.
|
|
116
|
+
|
|
117
|
+
### Request Headers
|
|
118
|
+
|
|
119
|
+
Override server behavior for individual requests:
|
|
120
|
+
|
|
121
|
+
| Header | Description |
|
|
122
|
+
| --------------------- | ------------------------------------------------- |
|
|
123
|
+
| `X-Steady-Mode` | Override validation mode: `strict` or `relaxed` |
|
|
124
|
+
| `X-Steady-Array-Size` | Override array size (sets both min and max) |
|
|
125
|
+
| `X-Steady-Array-Min` | Override minimum array size |
|
|
126
|
+
| `X-Steady-Array-Max` | Override maximum array size |
|
|
127
|
+
| `X-Steady-Seed` | Override random seed (`-1` for non-deterministic) |
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Force strict validation
|
|
131
|
+
curl -H "X-Steady-Mode: strict" http://localhost:3000/users
|
|
132
|
+
|
|
133
|
+
# Request 50 items in arrays
|
|
134
|
+
curl -H "X-Steady-Array-Size: 50" http://localhost:3000/users
|
|
135
|
+
|
|
136
|
+
# Get random (non-deterministic) responses
|
|
137
|
+
curl -H "X-Steady-Seed: -1" http://localhost:3000/users
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Response Headers
|
|
141
|
+
|
|
142
|
+
Informational headers returned by the server:
|
|
143
|
+
|
|
144
|
+
| Header | Description |
|
|
145
|
+
| ------------------------- | ----------------------------------------------------- |
|
|
146
|
+
| `X-Steady-Mode` | The validation mode used for this request |
|
|
147
|
+
| `X-Steady-Matched-Path` | The OpenAPI path pattern that matched |
|
|
148
|
+
| `X-Steady-Example-Source` | How the response was generated: `generated` or `none` |
|
|
149
|
+
|
|
150
|
+
## Special Endpoints
|
|
151
|
+
|
|
152
|
+
- `GET /_x-steady/health` - Health check with schema stats
|
|
153
|
+
- `GET /_x-steady/spec` - Returns the loaded OpenAPI spec as JSON
|
|
154
|
+
|
|
155
|
+
## JSON Schema Support
|
|
156
|
+
|
|
157
|
+
Supports JSON Schema draft 2020-12 with ~91% compliance.
|
|
158
|
+
|
|
159
|
+
**Supported:**
|
|
160
|
+
|
|
161
|
+
- Types: `string`, `number`, `integer`, `boolean`, `null`, `array`, `object`
|
|
162
|
+
- String: `minLength`, `maxLength`, `pattern`, `format`
|
|
163
|
+
- Number: `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`,
|
|
164
|
+
`multipleOf`
|
|
165
|
+
- Array: `items`, `prefixItems`, `minItems`, `maxItems`, `uniqueItems`,
|
|
166
|
+
`contains`, `unevaluatedItems`
|
|
167
|
+
- Object: `properties`, `required`, `additionalProperties`, `patternProperties`,
|
|
168
|
+
`propertyNames`, `minProperties`, `maxProperties`, `unevaluatedProperties`
|
|
169
|
+
- Composition: `allOf`, `anyOf`, `oneOf`, `not`
|
|
170
|
+
- Conditional: `if`/`then`/`else`
|
|
171
|
+
- References: `$ref`, `$defs`, `$anchor`
|
|
172
|
+
- `const`, `enum`, `default`
|
|
173
|
+
|
|
174
|
+
**Not supported:**
|
|
175
|
+
|
|
176
|
+
- `$dynamicRef` / `$dynamicAnchor`
|
|
177
|
+
- External `$ref` (http://, file://)
|
|
178
|
+
|
|
179
|
+
## Error Attribution
|
|
180
|
+
|
|
181
|
+
Errors indicate whether the issue is likely in the spec or the client request:
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
POST /users → 400 Bad Request
|
|
185
|
+
|
|
186
|
+
Validation errors:
|
|
187
|
+
1. Required parameter missing
|
|
188
|
+
Path: query.limit
|
|
189
|
+
Expected: integer
|
|
190
|
+
|
|
191
|
+
Attribution: SDK issue (high confidence)
|
|
192
|
+
Suggestion: Check SDK implementation - required parameter not sent
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Development
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
git clone https://github.com/dgellow/steady.git
|
|
199
|
+
cd steady
|
|
200
|
+
git submodule update --init # fetch test fixtures
|
|
201
|
+
|
|
202
|
+
# Run tests
|
|
203
|
+
deno task test
|
|
204
|
+
|
|
205
|
+
# Type check
|
|
206
|
+
deno task check
|
|
207
|
+
|
|
208
|
+
# Lint + format
|
|
209
|
+
deno task lint
|
|
210
|
+
deno task fmt
|
|
211
|
+
|
|
212
|
+
# Run all checks
|
|
213
|
+
deno task test-all
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Project Structure
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
steady/
|
|
220
|
+
├── cmd/steady.ts # CLI entry point
|
|
221
|
+
├── src/
|
|
222
|
+
│ ├── server.ts # HTTP server, route matching
|
|
223
|
+
│ ├── validator.ts # Request validation
|
|
224
|
+
│ ├── errors.ts # Error types with attribution
|
|
225
|
+
│ └── logging/ # Request logging utilities
|
|
226
|
+
├── packages/
|
|
227
|
+
│ ├── json-pointer/ # @steady/json-pointer - RFC 6901
|
|
228
|
+
│ ├── json-schema/ # @steady/json-schema - JSON Schema processor
|
|
229
|
+
│ └── openapi/ # @steady/openapi - OpenAPI 3.x parser
|
|
230
|
+
└── tests/
|
|
231
|
+
└── edge-cases/ # Edge case tests
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Tasks
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
deno task dev # Dev server with watch
|
|
238
|
+
deno task start # Production server
|
|
239
|
+
deno task test # Run all tests
|
|
240
|
+
deno task test:json-schema # JSON Schema tests only
|
|
241
|
+
deno task test:parser # OpenAPI parser tests only
|
|
242
|
+
deno task test:json-pointer # JSON Pointer tests only
|
|
243
|
+
deno task check # Type check
|
|
244
|
+
deno task lint # Lint
|
|
245
|
+
deno task fmt # Format
|
|
246
|
+
deno task check-boundaries # Verify package dependencies
|
|
247
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdy/cli",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "OpenAPI 3 mock server. Validates SDKs against OpenAPI specs with clear error attribution.",
|
|
5
|
+
"license": "Elastic-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/stainless-api/steady.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/stainless-api/steady/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/stainless-api/steady#readme",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"openapi",
|
|
16
|
+
"mock-server",
|
|
17
|
+
"api-testing",
|
|
18
|
+
"sdk-testing",
|
|
19
|
+
"json-schema",
|
|
20
|
+
"validation"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"steady": "./steady.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"steady.js"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=14.0.0"
|
|
30
|
+
},
|
|
31
|
+
"optionalDependencies": {
|
|
32
|
+
"@stdy/cli-linux-x64": "0.4.2",
|
|
33
|
+
"@stdy/cli-linux-arm64": "0.4.2",
|
|
34
|
+
"@stdy/cli-darwin-x64": "0.4.2",
|
|
35
|
+
"@stdy/cli-darwin-arm64": "0.4.2",
|
|
36
|
+
"@stdy/cli-win32-x64": "0.4.2"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/steady.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execFileSync } = require("child_process");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
|
|
6
|
+
const platform = process.platform;
|
|
7
|
+
const arch = process.arch;
|
|
8
|
+
|
|
9
|
+
const PLATFORMS = {
|
|
10
|
+
"linux-x64": "cli-linux-x64",
|
|
11
|
+
"linux-arm64": "cli-linux-arm64",
|
|
12
|
+
"darwin-x64": "cli-darwin-x64",
|
|
13
|
+
"darwin-arm64": "cli-darwin-arm64",
|
|
14
|
+
"win32-x64": "cli-win32-x64",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const key = `${platform}-${arch}`;
|
|
18
|
+
const pkgSuffix = PLATFORMS[key];
|
|
19
|
+
|
|
20
|
+
if (!pkgSuffix) {
|
|
21
|
+
console.error(`Unsupported platform: ${key}`);
|
|
22
|
+
console.error("Please use Deno directly: deno run -A jsr:@steady/cli");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const binName = platform === "win32" ? "steady.exe" : "steady";
|
|
27
|
+
let binPath;
|
|
28
|
+
|
|
29
|
+
// Try multiple locations:
|
|
30
|
+
// 1. Sibling directory (for local dev/testing)
|
|
31
|
+
// 2. node_modules (for installed package)
|
|
32
|
+
const locations = [
|
|
33
|
+
// Local dev: ../cli-linux-x64/bin/steady
|
|
34
|
+
path.join(__dirname, "..", pkgSuffix, "bin", binName),
|
|
35
|
+
// Installed: node_modules/@stdy/cli-linux-x64/bin/steady
|
|
36
|
+
path.join(__dirname, "..", "..", pkgSuffix, "bin", binName),
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
for (const loc of locations) {
|
|
40
|
+
if (fs.existsSync(loc)) {
|
|
41
|
+
binPath = loc;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!binPath) {
|
|
47
|
+
// Try require.resolve as fallback
|
|
48
|
+
try {
|
|
49
|
+
const pkgPath = require.resolve(`@stdy/${pkgSuffix}/package.json`);
|
|
50
|
+
const pkgDir = path.dirname(pkgPath);
|
|
51
|
+
binPath = path.join(pkgDir, "bin", binName);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error(`Failed to find binary for ${key}`);
|
|
54
|
+
console.error("Try reinstalling: npm install @stdy/cli");
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (e.status !== undefined) {
|
|
63
|
+
process.exit(e.status);
|
|
64
|
+
}
|
|
65
|
+
throw e;
|
|
66
|
+
}
|