api-spec-cli 0.2.3 → 0.2.4
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/README.md +343 -282
- package/package.json +53 -41
- package/src/cli.js +183 -172
- package/src/commands/add.js +161 -78
- package/src/commands/auth.js +32 -0
- package/src/commands/call.js +220 -207
- package/src/commands/fetch.js +344 -308
- package/src/commands/grep.js +67 -64
- package/src/commands/list.js +78 -80
- package/src/commands/show.js +224 -215
- package/src/commands/specs.js +82 -69
- package/src/commands/types.js +167 -163
- package/src/commands/validate.js +295 -269
- package/src/glob.js +34 -29
- package/src/mcp-client.js +88 -63
- package/src/oauth/auth-flow.js +59 -0
- package/src/oauth/provider.js +192 -0
- package/src/oauth/tokens.js +53 -0
- package/src/registry.js +79 -53
- package/src/resolve.js +64 -65
package/src/resolve.js
CHANGED
|
@@ -1,65 +1,64 @@
|
|
|
1
|
-
import { getEntry, getCachedSpec, saveCachedSpec } from "./registry.js";
|
|
2
|
-
import { fetchSpec, inlineEntryFromFlags } from "./commands/fetch.js";
|
|
3
|
-
import { getConfig } from "./store.js";
|
|
4
|
-
import { parseKV } from "./args.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Resolve the active spec from flags.
|
|
8
|
-
* Priority:
|
|
9
|
-
* 1. --spec <name> → registry (auto-caches on first use)
|
|
10
|
-
* 2. Inline flags → ad-hoc, no caching
|
|
11
|
-
* 3. Error → no spec source given
|
|
12
|
-
*/
|
|
13
|
-
export async function resolveSpec(flags) {
|
|
14
|
-
if (flags.spec) {
|
|
15
|
-
const entry = getEntry(flags.spec);
|
|
16
|
-
let spec = getCachedSpec(flags.spec);
|
|
17
|
-
if (!spec) {
|
|
18
|
-
spec = await fetchSpec(entry);
|
|
19
|
-
saveCachedSpec(flags.spec, spec);
|
|
20
|
-
}
|
|
21
|
-
return { spec, entry };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const inlineEntry = inlineEntryFromFlags(flags);
|
|
25
|
-
if (inlineEntry) {
|
|
26
|
-
const spec = await fetchSpec(inlineEntry);
|
|
27
|
-
return { spec, entry: inlineEntry };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
throw new Error(
|
|
31
|
-
"No spec source. Pass --spec <name> (registered) or an inline flag:\n" +
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Build the effective config for a command.
|
|
42
|
-
* Precedence (highest → lowest):
|
|
43
|
-
* 1. Call-time flags: --auth, --base-url, --header k=v
|
|
44
|
-
* 2. Registry entry config
|
|
45
|
-
* 3. .spec-cli/config.json
|
|
46
|
-
*/
|
|
47
|
-
export function resolveConfig(flags, entry) {
|
|
48
|
-
const global = getConfig();
|
|
49
|
-
const entryConfig = entry?.config || {};
|
|
50
|
-
const callHeaders = parseKV(flags.header);
|
|
51
|
-
|
|
52
|
-
const auth = flags.auth || entryConfig.auth || global.auth;
|
|
53
|
-
const baseUrl = flags["base-url"] || entryConfig.baseUrl || global.baseUrl;
|
|
54
|
-
const headers = { ...global.headers, ...(entryConfig.headers || {}), ...callHeaders };
|
|
55
|
-
|
|
56
|
-
// Apply auth as Authorization header if not already there (case-insensitive check)
|
|
57
|
-
const hasAuthHeader = Object.keys(headers).some((k) => k.toLowerCase() === "authorization");
|
|
58
|
-
if (auth && !hasAuthHeader) {
|
|
59
|
-
headers["Authorization"] =
|
|
60
|
-
? auth
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
1
|
+
import { getEntry, getCachedSpec, saveCachedSpec } from "./registry.js";
|
|
2
|
+
import { fetchSpec, inlineEntryFromFlags } from "./commands/fetch.js";
|
|
3
|
+
import { getConfig } from "./store.js";
|
|
4
|
+
import { parseKV } from "./args.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the active spec from flags.
|
|
8
|
+
* Priority:
|
|
9
|
+
* 1. --spec <name> → registry (auto-caches on first use)
|
|
10
|
+
* 2. Inline flags → ad-hoc, no caching
|
|
11
|
+
* 3. Error → no spec source given
|
|
12
|
+
*/
|
|
13
|
+
export async function resolveSpec(flags) {
|
|
14
|
+
if (flags.spec) {
|
|
15
|
+
const entry = getEntry(flags.spec); // throws if missing or disabled
|
|
16
|
+
let spec = getCachedSpec(flags.spec);
|
|
17
|
+
if (!spec) {
|
|
18
|
+
spec = await fetchSpec(entry);
|
|
19
|
+
saveCachedSpec(flags.spec, spec);
|
|
20
|
+
}
|
|
21
|
+
return { spec, entry };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const inlineEntry = inlineEntryFromFlags(flags);
|
|
25
|
+
if (inlineEntry) {
|
|
26
|
+
const spec = await fetchSpec(inlineEntry);
|
|
27
|
+
return { spec, entry: inlineEntry };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error(
|
|
31
|
+
"No spec source. Pass --spec <name> (registered) or an inline flag:\n" +
|
|
32
|
+
" --openapi <url-or-file>\n" +
|
|
33
|
+
" --graphql <url>\n" +
|
|
34
|
+
" --mcp-http <url>\n" +
|
|
35
|
+
" --mcp-sse <url>\n" +
|
|
36
|
+
' --mcp-stdio "<cmd args>"'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Build the effective config for a command.
|
|
42
|
+
* Precedence (highest → lowest):
|
|
43
|
+
* 1. Call-time flags: --auth, --base-url, --header k=v
|
|
44
|
+
* 2. Registry entry config
|
|
45
|
+
* 3. .spec-cli/config.json
|
|
46
|
+
*/
|
|
47
|
+
export function resolveConfig(flags, entry) {
|
|
48
|
+
const global = getConfig();
|
|
49
|
+
const entryConfig = entry?.config || {};
|
|
50
|
+
const callHeaders = parseKV(flags.header);
|
|
51
|
+
|
|
52
|
+
const auth = flags.auth || entryConfig.auth || global.auth;
|
|
53
|
+
const baseUrl = flags["base-url"] || entryConfig.baseUrl || global.baseUrl;
|
|
54
|
+
const headers = { ...global.headers, ...(entryConfig.headers || {}), ...callHeaders };
|
|
55
|
+
|
|
56
|
+
// Apply auth as Authorization header if not already there (case-insensitive check)
|
|
57
|
+
const hasAuthHeader = Object.keys(headers).some((k) => k.toLowerCase() === "authorization");
|
|
58
|
+
if (auth && !hasAuthHeader) {
|
|
59
|
+
headers["Authorization"] =
|
|
60
|
+
auth.startsWith("Bearer ") || auth.startsWith("Basic ") ? auth : `Bearer ${auth}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return { auth, baseUrl, headers };
|
|
64
|
+
}
|