chowbea-axios 1.0.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 +22 -0
- package/README.md +162 -0
- package/bin/dev.js +13 -0
- package/bin/run.js +10 -0
- package/dist/commands/diff.d.ts +31 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +215 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/fetch.d.ts +28 -0
- package/dist/commands/fetch.d.ts.map +1 -0
- package/dist/commands/fetch.js +223 -0
- package/dist/commands/fetch.js.map +1 -0
- package/dist/commands/generate.d.ts +26 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +187 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +92 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +738 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/status.d.ts +38 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +233 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/validate.d.ts +27 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +209 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/commands/watch.d.ts +34 -0
- package/dist/commands/watch.d.ts.map +1 -0
- package/dist/commands/watch.js +202 -0
- package/dist/commands/watch.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config.d.ts +151 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +336 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/errors.d.ts +77 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +144 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/fetcher.d.ts +115 -0
- package/dist/lib/fetcher.d.ts.map +1 -0
- package/dist/lib/fetcher.js +237 -0
- package/dist/lib/fetcher.js.map +1 -0
- package/dist/lib/generator.d.ts +96 -0
- package/dist/lib/generator.d.ts.map +1 -0
- package/dist/lib/generator.js +1575 -0
- package/dist/lib/generator.js.map +1 -0
- package/dist/lib/logger.d.ts +63 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +183 -0
- package/dist/lib/logger.js.map +1 -0
- package/oclif.manifest.json +556 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Emmanuel Alawode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# chowbea-axios
|
|
2
|
+
|
|
3
|
+
CLI tool for generating TypeScript types and operations from OpenAPI specifications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Self-healing**: Auto-creates config and output directories if missing
|
|
8
|
+
- **Retry logic**: Network operations retry 3x with exponential backoff
|
|
9
|
+
- **Caching**: Skips regeneration when spec hasn't changed
|
|
10
|
+
- **Atomic writes**: Generation never leaves files in a partial state
|
|
11
|
+
- **Graceful shutdown**: Watch mode preserves cache on interruption
|
|
12
|
+
- **Result-based errors**: API calls return `{ data, error }` instead of throwing
|
|
13
|
+
- **Error normalization**: Extracts messages from various API response formats
|
|
14
|
+
- **Local spec support**: Use local OpenAPI files instead of remote endpoints
|
|
15
|
+
- **Auth headers**: Configure headers with env var interpolation for protected specs
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g chowbea-axios
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or use with npx:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx chowbea-axios init
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Initialize in your project (creates config, generates client files)
|
|
33
|
+
chowbea-axios init
|
|
34
|
+
|
|
35
|
+
# Fetch spec and generate types
|
|
36
|
+
chowbea-axios fetch
|
|
37
|
+
|
|
38
|
+
# Watch for changes during development
|
|
39
|
+
chowbea-axios watch
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
### `chowbea-axios init`
|
|
45
|
+
|
|
46
|
+
Interactive setup - prompts for your API endpoint and generates everything.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
chowbea-axios init # Interactive setup
|
|
50
|
+
chowbea-axios init --force # Overwrite existing config
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### `chowbea-axios fetch`
|
|
54
|
+
|
|
55
|
+
Fetch OpenAPI spec and generate types.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
chowbea-axios fetch # Fetch from configured endpoint
|
|
59
|
+
chowbea-axios fetch --force # Regenerate even if unchanged
|
|
60
|
+
chowbea-axios fetch --dry-run # Preview without writing
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `chowbea-axios generate`
|
|
64
|
+
|
|
65
|
+
Generate types from local spec file.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
chowbea-axios generate # Generate from cached spec
|
|
69
|
+
chowbea-axios generate --spec-file ./api.json # Use specific file
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `chowbea-axios watch`
|
|
73
|
+
|
|
74
|
+
Watch for spec changes and regenerate automatically.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
chowbea-axios watch # Default 10s interval
|
|
78
|
+
chowbea-axios watch --interval 5000 # Poll every 5 seconds
|
|
79
|
+
chowbea-axios watch --debug # Show verbose logs
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### `chowbea-axios status`
|
|
83
|
+
|
|
84
|
+
Display current status of config, cache, and generated files.
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
chowbea-axios status
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `chowbea-axios validate`
|
|
91
|
+
|
|
92
|
+
Validate OpenAPI spec structure.
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
chowbea-axios validate
|
|
96
|
+
chowbea-axios validate --strict
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `chowbea-axios diff`
|
|
100
|
+
|
|
101
|
+
Compare current vs new spec.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
chowbea-axios diff
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Configuration
|
|
108
|
+
|
|
109
|
+
Config file `api.config.toml` is created by `init`:
|
|
110
|
+
|
|
111
|
+
```toml
|
|
112
|
+
api_endpoint = "http://localhost:3000/docs/swagger/json"
|
|
113
|
+
poll_interval_ms = 10000
|
|
114
|
+
|
|
115
|
+
[output]
|
|
116
|
+
folder = "app/services/api"
|
|
117
|
+
|
|
118
|
+
[instance]
|
|
119
|
+
base_url_env = "VITE_API_URL"
|
|
120
|
+
token_key = "auth-token"
|
|
121
|
+
with_credentials = true
|
|
122
|
+
timeout = 30000
|
|
123
|
+
|
|
124
|
+
[watch]
|
|
125
|
+
debug = false
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Generated Files
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
app/services/api/
|
|
132
|
+
├── _internal/
|
|
133
|
+
│ ├── .api-cache.json # Cache metadata
|
|
134
|
+
│ └── openapi.json # Cached spec
|
|
135
|
+
├── _generated/
|
|
136
|
+
│ ├── api.operations.ts # Generated operations
|
|
137
|
+
│ └── api.types.ts # Generated types
|
|
138
|
+
├── api.instance.ts # Axios instance (editable)
|
|
139
|
+
├── api.error.ts # Error types (editable)
|
|
140
|
+
└── api.client.ts # Typed API client (editable)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Usage
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { api } from "./app/services/api/api.client";
|
|
147
|
+
|
|
148
|
+
// Result-based - never throws
|
|
149
|
+
const { data, error } = await api.get("/users/{id}", { id: "123" });
|
|
150
|
+
|
|
151
|
+
if (error) {
|
|
152
|
+
console.error(error.message);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// data is fully typed
|
|
157
|
+
console.log(data.name);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT
|
package/bin/dev.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Development entry point for chowbea-axios CLI.
|
|
5
|
+
* Uses ts-node to run TypeScript directly without compilation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { execute } from "@oclif/core";
|
|
9
|
+
|
|
10
|
+
// Enable TypeScript execution for development
|
|
11
|
+
process.env.NODE_OPTIONS = "--loader ts-node/esm";
|
|
12
|
+
|
|
13
|
+
await execute({ development: true, dir: import.meta.url });
|
package/bin/run.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff command - compares current vs new spec and shows changes.
|
|
3
|
+
* Useful for previewing what would change before regenerating.
|
|
4
|
+
*/
|
|
5
|
+
import { Command } from "@oclif/core";
|
|
6
|
+
/**
|
|
7
|
+
* Compare current vs new spec and show changes.
|
|
8
|
+
*/
|
|
9
|
+
export default class Diff extends Command {
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: {
|
|
12
|
+
command: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}[];
|
|
15
|
+
static flags: {
|
|
16
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
spec: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
|
+
};
|
|
21
|
+
run(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts operations from an OpenAPI spec.
|
|
24
|
+
*/
|
|
25
|
+
private extractOperations;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if two operations have meaningful differences.
|
|
28
|
+
*/
|
|
29
|
+
private hasChanges;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/commands/diff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AA4B7C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAOsB;IAEjD,OAAgB,QAAQ;;;QAStB;IAEF,OAAgB,KAAK;;;;;MAmBnB;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAiK1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAuCzB;;OAEG;IACH,OAAO,CAAC,UAAU;CAQlB"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff command - compares current vs new spec and shows changes.
|
|
3
|
+
* Useful for previewing what would change before regenerating.
|
|
4
|
+
*/
|
|
5
|
+
import { Command, Flags } from "@oclif/core";
|
|
6
|
+
import { ensureOutputFolder, getOutputPaths, loadConfig, } from "../lib/config.js";
|
|
7
|
+
import { formatError, SpecNotFoundError } from "../lib/errors.js";
|
|
8
|
+
import { computeHash, fetchOpenApiSpec, hasLocalSpec, loadCacheMetadata, loadLocalSpec, } from "../lib/fetcher.js";
|
|
9
|
+
import { createLogger, getLogLevel, logSeparator } from "../lib/logger.js";
|
|
10
|
+
/**
|
|
11
|
+
* Compare current vs new spec and show changes.
|
|
12
|
+
*/
|
|
13
|
+
export default class Diff extends Command {
|
|
14
|
+
static description = `Preview API changes before regenerating.
|
|
15
|
+
|
|
16
|
+
Compares your cached spec with the remote (or a local file) and shows:
|
|
17
|
+
- New endpoints added
|
|
18
|
+
- Endpoints removed
|
|
19
|
+
- Endpoints modified
|
|
20
|
+
|
|
21
|
+
Useful to see what changed before running fetch.`;
|
|
22
|
+
static examples = [
|
|
23
|
+
{
|
|
24
|
+
command: "<%= config.bin %> diff",
|
|
25
|
+
description: "Compare cached spec with remote endpoint",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
command: "<%= config.bin %> diff --spec ./new-openapi.json",
|
|
29
|
+
description: "Compare cached spec with local file",
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
static flags = {
|
|
33
|
+
config: Flags.string({
|
|
34
|
+
char: "c",
|
|
35
|
+
description: "Path to api.config.toml",
|
|
36
|
+
}),
|
|
37
|
+
spec: Flags.string({
|
|
38
|
+
char: "s",
|
|
39
|
+
description: "Path to new OpenAPI spec file to compare against",
|
|
40
|
+
}),
|
|
41
|
+
quiet: Flags.boolean({
|
|
42
|
+
char: "q",
|
|
43
|
+
description: "Suppress non-error output",
|
|
44
|
+
default: false,
|
|
45
|
+
}),
|
|
46
|
+
verbose: Flags.boolean({
|
|
47
|
+
char: "v",
|
|
48
|
+
description: "Show detailed output",
|
|
49
|
+
default: false,
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
async run() {
|
|
53
|
+
const { flags } = await this.parse(Diff);
|
|
54
|
+
// Create logger with appropriate level
|
|
55
|
+
const logger = createLogger({
|
|
56
|
+
level: getLogLevel(flags),
|
|
57
|
+
});
|
|
58
|
+
logSeparator(logger, "chowbea-axios diff");
|
|
59
|
+
try {
|
|
60
|
+
// Load configuration
|
|
61
|
+
const { config, projectRoot } = await loadConfig(flags.config);
|
|
62
|
+
const outputPaths = getOutputPaths(config, projectRoot);
|
|
63
|
+
await ensureOutputFolder(outputPaths.folder);
|
|
64
|
+
// Load current spec (if exists)
|
|
65
|
+
const hasCurrentSpec = await hasLocalSpec(outputPaths.spec);
|
|
66
|
+
let currentOperations = new Map();
|
|
67
|
+
if (hasCurrentSpec) {
|
|
68
|
+
const { spec: currentSpec } = await loadLocalSpec(outputPaths.spec);
|
|
69
|
+
currentOperations = this.extractOperations(currentSpec);
|
|
70
|
+
logger.info({ operations: currentOperations.size }, "Loaded current spec");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
logger.info("No current spec found - will show all as new");
|
|
74
|
+
}
|
|
75
|
+
// Load new spec (from flag or fetch)
|
|
76
|
+
let newSpec;
|
|
77
|
+
let newHash;
|
|
78
|
+
if (flags.spec) {
|
|
79
|
+
// Load from provided file
|
|
80
|
+
const result = await loadLocalSpec(flags.spec);
|
|
81
|
+
newSpec = result.spec;
|
|
82
|
+
newHash = computeHash(result.buffer);
|
|
83
|
+
logger.info({ spec: flags.spec }, "Loaded new spec from file");
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Fetch from remote
|
|
87
|
+
logger.info({ endpoint: config.api_endpoint }, "Fetching new spec from endpoint...");
|
|
88
|
+
const fetchResult = await fetchOpenApiSpec({
|
|
89
|
+
endpoint: config.api_endpoint,
|
|
90
|
+
specPath: outputPaths.spec,
|
|
91
|
+
cachePath: outputPaths.cache,
|
|
92
|
+
logger,
|
|
93
|
+
force: true, // Always fetch fresh for diff
|
|
94
|
+
});
|
|
95
|
+
newSpec = JSON.parse(fetchResult.buffer.toString("utf8"));
|
|
96
|
+
newHash = fetchResult.hash;
|
|
97
|
+
}
|
|
98
|
+
// Check hash against cache
|
|
99
|
+
const cacheMetadata = await loadCacheMetadata(outputPaths.cache);
|
|
100
|
+
if (cacheMetadata && cacheMetadata.hash === newHash && !flags.spec) {
|
|
101
|
+
logger.info("Spec is identical to cached version - no changes");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// Extract operations from new spec
|
|
105
|
+
const newOperations = this.extractOperations(newSpec);
|
|
106
|
+
logger.info({ operations: newOperations.size }, "Analyzed new spec");
|
|
107
|
+
// Compute differences
|
|
108
|
+
const added = [];
|
|
109
|
+
const removed = [];
|
|
110
|
+
const modified = [];
|
|
111
|
+
// Find added and modified operations
|
|
112
|
+
for (const [id, newOp] of newOperations) {
|
|
113
|
+
const currentOp = currentOperations.get(id);
|
|
114
|
+
if (!currentOp) {
|
|
115
|
+
added.push(newOp);
|
|
116
|
+
}
|
|
117
|
+
else if (this.hasChanges(currentOp, newOp)) {
|
|
118
|
+
modified.push({ old: currentOp, new: newOp });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Find removed operations
|
|
122
|
+
for (const [id, currentOp] of currentOperations) {
|
|
123
|
+
if (!newOperations.has(id)) {
|
|
124
|
+
removed.push(currentOp);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Report changes
|
|
128
|
+
logSeparator(logger, "Changes Summary");
|
|
129
|
+
if (added.length === 0 && removed.length === 0 && modified.length === 0) {
|
|
130
|
+
logger.info("No changes to operations detected");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (added.length > 0) {
|
|
134
|
+
logger.info(`\n+ Added operations (${added.length}):`);
|
|
135
|
+
for (const op of added) {
|
|
136
|
+
logger.info(` + ${op.method.toUpperCase()} ${op.path} (${op.operationId})`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (removed.length > 0) {
|
|
140
|
+
logger.info(`\n- Removed operations (${removed.length}):`);
|
|
141
|
+
for (const op of removed) {
|
|
142
|
+
logger.info(` - ${op.method.toUpperCase()} ${op.path} (${op.operationId})`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (modified.length > 0) {
|
|
146
|
+
logger.info(`\n~ Modified operations (${modified.length}):`);
|
|
147
|
+
for (const { old: oldOp, new: newOp } of modified) {
|
|
148
|
+
logger.info(` ~ ${newOp.method.toUpperCase()} ${newOp.path} (${newOp.operationId})`);
|
|
149
|
+
if (oldOp.hasRequestBody !== newOp.hasRequestBody) {
|
|
150
|
+
logger.info(` Request body: ${oldOp.hasRequestBody} -> ${newOp.hasRequestBody}`);
|
|
151
|
+
}
|
|
152
|
+
if (oldOp.summary !== newOp.summary) {
|
|
153
|
+
logger.info(" Summary changed");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
logSeparator(logger);
|
|
158
|
+
logger.info({
|
|
159
|
+
added: added.length,
|
|
160
|
+
removed: removed.length,
|
|
161
|
+
modified: modified.length,
|
|
162
|
+
}, "Total changes");
|
|
163
|
+
logger.info("\nRun 'chowbea-axios fetch' to apply these changes");
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (error instanceof SpecNotFoundError) {
|
|
167
|
+
logger.warn("No local spec found - nothing to compare against");
|
|
168
|
+
logger.info("Run 'chowbea-axios fetch' first to download the spec");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
logger.error(formatError(error));
|
|
172
|
+
this.exit(1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Extracts operations from an OpenAPI spec.
|
|
177
|
+
*/
|
|
178
|
+
extractOperations(spec) {
|
|
179
|
+
const operations = new Map();
|
|
180
|
+
if (typeof spec !== "object" || spec === null) {
|
|
181
|
+
return operations;
|
|
182
|
+
}
|
|
183
|
+
const specObj = spec;
|
|
184
|
+
const paths = specObj.paths;
|
|
185
|
+
if (!paths) {
|
|
186
|
+
return operations;
|
|
187
|
+
}
|
|
188
|
+
for (const [pathTemplate, pathItem] of Object.entries(paths)) {
|
|
189
|
+
for (const method of ["get", "post", "put", "delete", "patch"]) {
|
|
190
|
+
const operation = pathItem[method];
|
|
191
|
+
if (!(operation && operation.operationId))
|
|
192
|
+
continue;
|
|
193
|
+
const operationId = operation.operationId;
|
|
194
|
+
operations.set(operationId, {
|
|
195
|
+
operationId,
|
|
196
|
+
method,
|
|
197
|
+
path: pathTemplate,
|
|
198
|
+
hasRequestBody: Boolean(operation.requestBody),
|
|
199
|
+
summary: operation.summary ?? "",
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return operations;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Checks if two operations have meaningful differences.
|
|
207
|
+
*/
|
|
208
|
+
hasChanges(a, b) {
|
|
209
|
+
return (a.method !== b.method ||
|
|
210
|
+
a.path !== b.path ||
|
|
211
|
+
a.hasRequestBody !== b.hasRequestBody ||
|
|
212
|
+
a.summary !== b.summary);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=diff.js.map
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ErB,CAAC;gBAEb,IAAI,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,WAAW,CAAC;oBAAE,SAAS;gBAEpD,MAAM,WAAW,GAAG,SAAS,CAAC,WAAqB,CAAC;gBAEpD,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE;oBAC3B,WAAW;oBACX,MAAM;oBACN,IAAI,EAAE,YAAY;oBAClB,cAAc,EAAE,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC;oBAC9C,OAAO,EAAG,SAAS,CAAC,OAAkB,IAAI,EAAE;iBAC5C,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAED,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,CAAgB,EAAE,CAAgB;QACpD,OAAO,CACN,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;YACrB,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI;YACjB,CAAC,CAAC,cAAc,KAAK,CAAC,CAAC,cAAc;YACrC,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,CACvB,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch command - fetches OpenAPI spec from remote endpoint and generates types.
|
|
3
|
+
* Includes retry logic and caching to skip regeneration when spec hasn't changed.
|
|
4
|
+
*/
|
|
5
|
+
import { Command } from "@oclif/core";
|
|
6
|
+
/**
|
|
7
|
+
* Fetch OpenAPI spec from remote endpoint and generate types.
|
|
8
|
+
*/
|
|
9
|
+
export default class Fetch extends Command {
|
|
10
|
+
static description: string;
|
|
11
|
+
static examples: {
|
|
12
|
+
command: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}[];
|
|
15
|
+
static flags: {
|
|
16
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
endpoint: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
"spec-file": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
|
+
"dry-run": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
21
|
+
"types-only": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
"operations-only": import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
24
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
25
|
+
};
|
|
26
|
+
run(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/commands/fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAsB7C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACzC,OAAgB,WAAW,SAOmB;IAE9C,OAAgB,QAAQ;;;QAqBtB;IAEF,OAAgB,KAAK;;;;;;;;;;MAyCnB;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA4K1B"}
|