@ir-kit/openapi-tools 0.1.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.md +21 -0
- package/README.md +48 -0
- package/dist/diff.d.ts +65 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +296 -0
- package/dist/diff.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/ir.d.ts +5 -0
- package/dist/ir.d.ts.map +1 -0
- package/dist/ir.js +36 -0
- package/dist/ir.js.map +1 -0
- package/dist/load.d.ts +27 -0
- package/dist/load.d.ts.map +1 -0
- package/dist/load.js +38 -0
- package/dist/load.js.map +1 -0
- package/dist/match.d.ts +20 -0
- package/dist/match.d.ts.map +1 -0
- package/dist/match.js +60 -0
- package/dist/match.js.map +1 -0
- package/dist/merge/components.d.ts +7 -0
- package/dist/merge/components.d.ts.map +1 -0
- package/dist/merge/components.js +86 -0
- package/dist/merge/components.js.map +1 -0
- package/dist/merge/core.d.ts +3 -0
- package/dist/merge/core.d.ts.map +1 -0
- package/dist/merge/core.js +181 -0
- package/dist/merge/core.js.map +1 -0
- package/dist/merge/paths.d.ts +9 -0
- package/dist/merge/paths.d.ts.map +1 -0
- package/dist/merge/paths.js +43 -0
- package/dist/merge/paths.js.map +1 -0
- package/dist/merge/refs.d.ts +3 -0
- package/dist/merge/refs.d.ts.map +1 -0
- package/dist/merge/refs.js +34 -0
- package/dist/merge/refs.js.map +1 -0
- package/dist/merge/types.d.ts +55 -0
- package/dist/merge/types.d.ts.map +1 -0
- package/dist/merge/types.js +2 -0
- package/dist/merge/types.js.map +1 -0
- package/dist/merge.d.ts +5 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +4 -0
- package/dist/merge.js.map +1 -0
- package/dist/parse.d.ts +7 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +23 -0
- package/dist/parse.js.map +1 -0
- package/dist/route.d.ts +17 -0
- package/dist/route.d.ts.map +1 -0
- package/dist/route.js +2 -0
- package/dist/route.js.map +1 -0
- package/dist/router.d.ts +22 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +40 -0
- package/dist/router.js.map +1 -0
- package/dist/schema.d.ts +7 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +15 -0
- package/dist/schema.js.map +1 -0
- package/package.json +104 -0
package/dist/match.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { URLPattern } from "urlpattern-polyfill";
|
|
2
|
+
/** Higher = more specific; literals outweigh `{param}` segments. */
|
|
3
|
+
function scorePath(spec) {
|
|
4
|
+
let score = 0;
|
|
5
|
+
for (const segment of spec.split("/").filter(Boolean)) {
|
|
6
|
+
score += segment.startsWith("{") ? 1 : 100;
|
|
7
|
+
}
|
|
8
|
+
return score;
|
|
9
|
+
}
|
|
10
|
+
const cache = new WeakMap();
|
|
11
|
+
function compile(routes) {
|
|
12
|
+
const hit = cache.get(routes);
|
|
13
|
+
if (hit)
|
|
14
|
+
return hit;
|
|
15
|
+
const compiled = routes.map((r) => ({
|
|
16
|
+
...r,
|
|
17
|
+
compiled: new URLPattern({ pathname: r.pattern }),
|
|
18
|
+
score: scorePath(r.spec),
|
|
19
|
+
}));
|
|
20
|
+
compiled.sort((a, b) => b.score - a.score);
|
|
21
|
+
cache.set(routes, compiled);
|
|
22
|
+
return compiled;
|
|
23
|
+
}
|
|
24
|
+
/** Match a request against routes. Returns `MatchResult<R>` discriminated union or `null`. */
|
|
25
|
+
export function match(routes, request) {
|
|
26
|
+
const url = new URL(request.url);
|
|
27
|
+
const lower = request.method.toLowerCase();
|
|
28
|
+
for (const route of compile(routes)) {
|
|
29
|
+
if (route.method !== lower)
|
|
30
|
+
continue;
|
|
31
|
+
const m = route.compiled.exec({ pathname: url.pathname });
|
|
32
|
+
if (!m)
|
|
33
|
+
continue;
|
|
34
|
+
const params = {};
|
|
35
|
+
for (const [k, v] of Object.entries(m.pathname.groups ?? {})) {
|
|
36
|
+
if (typeof v === "string")
|
|
37
|
+
params[k] = v;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
spec: route.spec,
|
|
41
|
+
method: route.method,
|
|
42
|
+
params,
|
|
43
|
+
operationId: route.operationId,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** Boolean: does this request hit any route? */
|
|
49
|
+
export function isInSpec(routes, request) {
|
|
50
|
+
const url = new URL(request.url);
|
|
51
|
+
const lower = request.method.toLowerCase();
|
|
52
|
+
for (const route of compile(routes)) {
|
|
53
|
+
if (route.method !== lower)
|
|
54
|
+
continue;
|
|
55
|
+
if (route.compiled.test({ pathname: url.pathname }))
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../src/match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAyBjD,oEAAoE;AACpE,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACtD,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,KAAK,GAAG,IAAI,OAAO,EAAqC,CAAC;AAE/D,SAAS,OAAO,CAAC,MAAwB;IACvC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,C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AAK,QAAQ;gBAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,MAAM;YACN,WAAW,EAAE,KAAK,CAAC,WAAW;SACb,CAAC;IACtB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,QAAQ,CAAC,MAAwB,EAAE,OAAgB;IACjE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IAC3C,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK;YAAE,SAAS;QACrC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;YAAE,OAAO,IAAI,CAAC;IACnE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComponentPolicy, Components, MergeSource, RenameMap } from "./types.js";
|
|
2
|
+
export declare function mergeComponents(sources: MergeSource[], policy?: ComponentPolicy): {
|
|
3
|
+
components: Components;
|
|
4
|
+
renames: Record<string, RenameMap>;
|
|
5
|
+
};
|
|
6
|
+
export declare function flattenRenames(perSource: Record<string, RenameMap>): RenameMap;
|
|
7
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/merge/components.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,WAAW,EACX,SAAS,EACV,MAAM,YAAY,CAAC;AAoBpB,wBAAgB,eAAe,CAC7B,OAAO,EAAE,WAAW,EAAE,EACtB,MAAM,GAAE,eAAoB,GAC3B;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACpC,CAqEA;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GACnC,SAAS,CASX"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { MergeConflictError } from "./paths.js";
|
|
2
|
+
import { rewriteRefs } from "./refs.js";
|
|
3
|
+
const DEFAULTS = {
|
|
4
|
+
onConflict: "namespace",
|
|
5
|
+
namespace: (label, name) => `${label}_${name}`,
|
|
6
|
+
};
|
|
7
|
+
const COMPONENT_SECTIONS = [
|
|
8
|
+
"schemas",
|
|
9
|
+
"responses",
|
|
10
|
+
"parameters",
|
|
11
|
+
"examples",
|
|
12
|
+
"requestBodies",
|
|
13
|
+
"headers",
|
|
14
|
+
"securitySchemes",
|
|
15
|
+
"links",
|
|
16
|
+
"callbacks",
|
|
17
|
+
"pathItems",
|
|
18
|
+
];
|
|
19
|
+
export function mergeComponents(sources, policy = {}) {
|
|
20
|
+
const cfg = { ...DEFAULTS, ...policy };
|
|
21
|
+
const out = {};
|
|
22
|
+
const renames = {};
|
|
23
|
+
const claimed = {};
|
|
24
|
+
for (const section of COMPONENT_SECTIONS) {
|
|
25
|
+
claimed[section] = new Set();
|
|
26
|
+
}
|
|
27
|
+
for (const { label, spec } of sources) {
|
|
28
|
+
const renameMap = {};
|
|
29
|
+
renames[label] = renameMap;
|
|
30
|
+
const components = spec.components ?? {};
|
|
31
|
+
for (const section of COMPONENT_SECTIONS) {
|
|
32
|
+
const entries = components[section];
|
|
33
|
+
if (!entries || typeof entries !== "object")
|
|
34
|
+
continue;
|
|
35
|
+
const seen = claimed[section];
|
|
36
|
+
const sectionOut = out[section] ?? {};
|
|
37
|
+
for (const [name, value] of Object.entries(entries)) {
|
|
38
|
+
const wantRename = cfg.onConflict === "namespace" || seen.has(name);
|
|
39
|
+
const finalName = wantRename ? cfg.namespace(label, name) : name;
|
|
40
|
+
if (finalName !== name) {
|
|
41
|
+
renameMap[section] ??= {};
|
|
42
|
+
renameMap[section][name] = finalName;
|
|
43
|
+
}
|
|
44
|
+
if (sectionOut[finalName] !== undefined) {
|
|
45
|
+
switch (cfg.onConflict) {
|
|
46
|
+
case "error":
|
|
47
|
+
throw new MergeConflictError(`components.${section}.${name} collides across sources (source: ${label})`);
|
|
48
|
+
case "first-wins":
|
|
49
|
+
continue;
|
|
50
|
+
case "last-wins":
|
|
51
|
+
sectionOut[finalName] = value;
|
|
52
|
+
continue;
|
|
53
|
+
case "namespace":
|
|
54
|
+
sectionOut[finalName] = value;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
sectionOut[finalName] = value;
|
|
60
|
+
}
|
|
61
|
+
seen.add(finalName);
|
|
62
|
+
}
|
|
63
|
+
if (Object.keys(sectionOut).length > 0) {
|
|
64
|
+
out[section] = sectionOut;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const section of COMPONENT_SECTIONS) {
|
|
69
|
+
const sectionOut = out[section];
|
|
70
|
+
if (!sectionOut)
|
|
71
|
+
continue;
|
|
72
|
+
out[section] = rewriteRefs(sectionOut, flattenRenames(renames));
|
|
73
|
+
}
|
|
74
|
+
return { components: out, renames };
|
|
75
|
+
}
|
|
76
|
+
export function flattenRenames(perSource) {
|
|
77
|
+
const out = {};
|
|
78
|
+
for (const map of Object.values(perSource)) {
|
|
79
|
+
for (const [section, names] of Object.entries(map)) {
|
|
80
|
+
out[section] ??= {};
|
|
81
|
+
Object.assign(out[section], names);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 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
+
import { flattenRenames, mergeComponents } from "./components.js";
|
|
2
|
+
import { MergeConflictError, mergePaths } from "./paths.js";
|
|
3
|
+
import { rewriteRefs } from "./refs.js";
|
|
4
|
+
const HTTP_METHODS = [
|
|
5
|
+
"get",
|
|
6
|
+
"put",
|
|
7
|
+
"post",
|
|
8
|
+
"delete",
|
|
9
|
+
"options",
|
|
10
|
+
"head",
|
|
11
|
+
"patch",
|
|
12
|
+
"trace",
|
|
13
|
+
];
|
|
14
|
+
export function merge(sources, opts = {}) {
|
|
15
|
+
if (sources.length === 0) {
|
|
16
|
+
return {
|
|
17
|
+
openapi: "3.1.0",
|
|
18
|
+
info: { title: "Merged API", version: "0.0.0" },
|
|
19
|
+
paths: {},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const { components, renames } = mergeComponents(sources, opts.components);
|
|
23
|
+
const rewrittenSources = sources.map(({ label, spec }) => {
|
|
24
|
+
const renameMap = renames[label];
|
|
25
|
+
if (!renameMap || Object.keys(renameMap).length === 0) {
|
|
26
|
+
return { label, spec };
|
|
27
|
+
}
|
|
28
|
+
const rewrittenPaths = rewriteRefs(spec.paths ?? {}, renameMap);
|
|
29
|
+
const rewrittenWebhooks = spec.webhooks
|
|
30
|
+
? rewriteRefs(spec.webhooks, renameMap)
|
|
31
|
+
: undefined;
|
|
32
|
+
return {
|
|
33
|
+
label,
|
|
34
|
+
spec: {
|
|
35
|
+
...spec,
|
|
36
|
+
paths: rewrittenPaths,
|
|
37
|
+
...(rewrittenWebhooks ? { webhooks: rewrittenWebhooks } : {}),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
resolveOperationIdConflicts(rewrittenSources, opts.operationIds);
|
|
42
|
+
const { paths } = mergePaths(rewrittenSources, opts.paths);
|
|
43
|
+
const allRenames = flattenRenames(renames);
|
|
44
|
+
const finalPaths = rewriteRefs(paths, allRenames);
|
|
45
|
+
const webhooks = mergeWebhooks(rewrittenSources);
|
|
46
|
+
const tags = mergeTags(sources, opts.tags);
|
|
47
|
+
const servers = mergeServers(sources, opts.servers);
|
|
48
|
+
const security = mergeSecurity(sources);
|
|
49
|
+
const info = mergeInfo(sources, opts.info);
|
|
50
|
+
const out = {
|
|
51
|
+
openapi: "3.1.0",
|
|
52
|
+
info,
|
|
53
|
+
paths: finalPaths,
|
|
54
|
+
};
|
|
55
|
+
if (servers.length > 0)
|
|
56
|
+
out.servers = servers;
|
|
57
|
+
if (Object.keys(components).length > 0)
|
|
58
|
+
out.components = components;
|
|
59
|
+
if (tags.length > 0)
|
|
60
|
+
out.tags = tags;
|
|
61
|
+
if (security.length > 0)
|
|
62
|
+
out.security = security;
|
|
63
|
+
if (Object.keys(webhooks).length > 0)
|
|
64
|
+
out.webhooks = webhooks;
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
function mergeInfo(sources, override) {
|
|
68
|
+
const first = sources[0]?.spec.info ?? {};
|
|
69
|
+
const merged = {
|
|
70
|
+
...first,
|
|
71
|
+
title: override?.title ?? first.title ?? "Merged API",
|
|
72
|
+
version: override?.version ?? first.version ?? "0.0.0",
|
|
73
|
+
};
|
|
74
|
+
if (override?.description !== undefined)
|
|
75
|
+
merged.description = override.description;
|
|
76
|
+
if (override?.summary !== undefined)
|
|
77
|
+
merged.summary = override.summary;
|
|
78
|
+
if (override?.contact !== undefined)
|
|
79
|
+
merged.contact = override.contact;
|
|
80
|
+
if (override?.license !== undefined)
|
|
81
|
+
merged.license = override.license;
|
|
82
|
+
if (override?.termsOfService !== undefined)
|
|
83
|
+
merged.termsOfService = override.termsOfService;
|
|
84
|
+
return merged;
|
|
85
|
+
}
|
|
86
|
+
function mergeTags(sources, policy = {}) {
|
|
87
|
+
const strategy = policy.strategy ?? "union";
|
|
88
|
+
const namespace = policy.namespace ?? ((label, tag) => `${label}:${tag}`);
|
|
89
|
+
const seen = new Map();
|
|
90
|
+
for (const { label, spec } of sources) {
|
|
91
|
+
for (const tag of spec.tags ?? []) {
|
|
92
|
+
const finalName = strategy === "namespace" ? namespace(label, tag.name) : tag.name;
|
|
93
|
+
if (!seen.has(finalName)) {
|
|
94
|
+
seen.set(finalName, { ...tag, name: finalName });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return [...seen.values()];
|
|
99
|
+
}
|
|
100
|
+
function mergeServers(sources, policy = {}) {
|
|
101
|
+
const strategy = policy.strategy ?? "union";
|
|
102
|
+
if (strategy === "first")
|
|
103
|
+
return sources[0]?.spec.servers ?? [];
|
|
104
|
+
if (strategy === "last") {
|
|
105
|
+
return sources[sources.length - 1]?.spec.servers ?? [];
|
|
106
|
+
}
|
|
107
|
+
const seen = new Set();
|
|
108
|
+
const out = [];
|
|
109
|
+
for (const { spec } of sources) {
|
|
110
|
+
for (const server of spec.servers ?? []) {
|
|
111
|
+
if (seen.has(server.url))
|
|
112
|
+
continue;
|
|
113
|
+
seen.add(server.url);
|
|
114
|
+
out.push(server);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
function mergeSecurity(sources) {
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
const out = [];
|
|
122
|
+
for (const { spec } of sources) {
|
|
123
|
+
for (const req of spec.security ?? []) {
|
|
124
|
+
const key = JSON.stringify(req);
|
|
125
|
+
if (seen.has(key))
|
|
126
|
+
continue;
|
|
127
|
+
seen.add(key);
|
|
128
|
+
out.push(req);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
function mergeWebhooks(sources) {
|
|
134
|
+
const out = {};
|
|
135
|
+
for (const { spec } of sources) {
|
|
136
|
+
for (const [name, item] of Object.entries(spec.webhooks ?? {})) {
|
|
137
|
+
if (!(name in out))
|
|
138
|
+
out[name] = item;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
function resolveOperationIdConflicts(sources, policy = {}) {
|
|
144
|
+
const onConflict = policy.onConflict ?? "namespace";
|
|
145
|
+
const namespace = policy.namespace ?? ((label, id) => `${label}_${id}`);
|
|
146
|
+
const claimed = new Map();
|
|
147
|
+
for (const { label, spec } of sources) {
|
|
148
|
+
for (const item of Object.values(spec.paths ?? {})) {
|
|
149
|
+
if (!item)
|
|
150
|
+
continue;
|
|
151
|
+
for (const method of HTTP_METHODS) {
|
|
152
|
+
const op = item[method];
|
|
153
|
+
if (!op?.operationId)
|
|
154
|
+
continue;
|
|
155
|
+
const id = op.operationId;
|
|
156
|
+
if (onConflict === "namespace") {
|
|
157
|
+
op.operationId = namespace(label, id);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const owner = claimed.get(id);
|
|
161
|
+
if (!owner) {
|
|
162
|
+
claimed.set(id, label);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (owner === label)
|
|
166
|
+
continue;
|
|
167
|
+
switch (onConflict) {
|
|
168
|
+
case "error":
|
|
169
|
+
throw new MergeConflictError(`operationId "${id}" appears in both "${owner}" and "${label}"`);
|
|
170
|
+
case "first-wins":
|
|
171
|
+
delete op.operationId;
|
|
172
|
+
continue;
|
|
173
|
+
case "last-wins":
|
|
174
|
+
claimed.set(id, label);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/merge/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAUxC,MAAM,YAAY,GAAG;IACnB,KAAK;IACL,KAAK;IACL,MAAM;IACN,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SAAS;gBACb,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Document, MergeSource, PathPolicy } from "./types.js";
|
|
2
|
+
export declare function mergePaths(sources: MergeSource[], policy?: PathPolicy): {
|
|
3
|
+
paths: Document["paths"];
|
|
4
|
+
pathPrefixes: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
export declare class MergeConflictError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/merge/paths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAY,UAAU,EAAE,MAAM,YAAY,CAAC;AAO9E,wBAAgB,UAAU,CACxB,OAAO,EAAE,WAAW,EAAE,EACtB,MAAM,GAAE,UAAe,GACtB;IACD,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAsCA;AAED,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const DEFAULTS = {
|
|
2
|
+
onConflict: "error",
|
|
3
|
+
prefix: (label) => `/${label}`,
|
|
4
|
+
};
|
|
5
|
+
export function mergePaths(sources, policy = {}) {
|
|
6
|
+
const cfg = { ...DEFAULTS, ...policy };
|
|
7
|
+
const out = {};
|
|
8
|
+
const pathPrefixes = {};
|
|
9
|
+
for (const { label, spec } of sources) {
|
|
10
|
+
const sourcePaths = spec.paths ?? {};
|
|
11
|
+
const prefix = cfg.onConflict === "prefix" ? cfg.prefix(label) : "";
|
|
12
|
+
if (prefix)
|
|
13
|
+
pathPrefixes[label] = prefix;
|
|
14
|
+
for (const [path, item] of Object.entries(sourcePaths)) {
|
|
15
|
+
if (!item)
|
|
16
|
+
continue;
|
|
17
|
+
const fullPath = `${prefix}${path}`;
|
|
18
|
+
if (!(fullPath in out)) {
|
|
19
|
+
out[fullPath] = item;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
switch (cfg.onConflict) {
|
|
23
|
+
case "error":
|
|
24
|
+
throw new MergeConflictError(`path collision at "${fullPath}" (source: ${label})`);
|
|
25
|
+
case "first-wins":
|
|
26
|
+
continue;
|
|
27
|
+
case "last-wins":
|
|
28
|
+
out[fullPath] = item;
|
|
29
|
+
continue;
|
|
30
|
+
case "prefix":
|
|
31
|
+
throw new MergeConflictError(`path collision after prefixing at "${fullPath}" — duplicate label "${label}"?`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { paths: out, pathPrefixes };
|
|
36
|
+
}
|
|
37
|
+
export class MergeConflictError extends Error {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "MergeConflictError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/merge/paths.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAyB;IACrC,UAAU,EAAE,OAAO;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE;CAC/B,CAAC;AAEF,MAAM,UAAU,UAAU,CACxB,OAAsB,EACtB,SAAqB,EAAE;IAKvB,MAAM,GAAG,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAC;IACvC,MAAM,GAAG,GAA6B,EAAE,CAAC;IACzC,MAAM,YAAY,GAA2B,EAAE,CAAC;IAEhD,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,OAAO,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../src/merge/refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,GAAG,CAAC,CAc7D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function rewriteRefs(node, renames) {
|
|
2
|
+
if (node === null || typeof node !== "object")
|
|
3
|
+
return node;
|
|
4
|
+
if (Array.isArray(node)) {
|
|
5
|
+
return node.map((v) => rewriteRefs(v, renames));
|
|
6
|
+
}
|
|
7
|
+
const out = {};
|
|
8
|
+
for (const [k, v] of Object.entries(node)) {
|
|
9
|
+
if (k === "$ref" && typeof v === "string") {
|
|
10
|
+
out[k] = rewriteRef(v, renames);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
out[k] = rewriteRefs(v, renames);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
const REF_PREFIX = "#/components/";
|
|
19
|
+
function rewriteRef(ref, renames) {
|
|
20
|
+
if (!ref.startsWith(REF_PREFIX))
|
|
21
|
+
return ref;
|
|
22
|
+
const tail = ref.slice(REF_PREFIX.length);
|
|
23
|
+
const slash = tail.indexOf("/");
|
|
24
|
+
if (slash === -1)
|
|
25
|
+
return ref;
|
|
26
|
+
const section = tail.slice(0, slash);
|
|
27
|
+
const rest = tail.slice(slash + 1);
|
|
28
|
+
const nameEnd = rest.indexOf("/");
|
|
29
|
+
const name = nameEnd === -1 ? rest : rest.slice(0, nameEnd);
|
|
30
|
+
const remainder = nameEnd === -1 ? "" : rest.slice(nameEnd);
|
|
31
|
+
const next = renames[section]?.[name];
|
|
32
|
+
return next ? `${REF_PREFIX}${section}/${next}${remainder}` : ref;
|
|
33
|
+
}
|
|
34
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CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from "@hey-api/spec-types";
|
|
2
|
+
export type Document = OpenAPIV3_1.Document;
|
|
3
|
+
export type PathItem = OpenAPIV3_1.PathItemObject;
|
|
4
|
+
export type Components = NonNullable<Document["components"]>;
|
|
5
|
+
export interface MergeSource {
|
|
6
|
+
/** Stable identifier used for namespacing/prefixing on conflict. */
|
|
7
|
+
label: string;
|
|
8
|
+
spec: Document;
|
|
9
|
+
}
|
|
10
|
+
export interface PathPolicy {
|
|
11
|
+
/** Default: `error`. `prefix` rewrites every path with `prefix(label)`. */
|
|
12
|
+
onConflict?: "error" | "first-wins" | "last-wins" | "prefix";
|
|
13
|
+
/** Default: `(label) => "/" + label`. Only used when `onConflict === "prefix"`. */
|
|
14
|
+
prefix?: (label: string) => string;
|
|
15
|
+
}
|
|
16
|
+
export interface ComponentPolicy {
|
|
17
|
+
/**
|
|
18
|
+
* Default: `namespace`. `namespace` always renames *every* component name
|
|
19
|
+
* with `namespace(label, name)`. `error` throws on collision.
|
|
20
|
+
*/
|
|
21
|
+
onConflict?: "error" | "namespace" | "first-wins" | "last-wins";
|
|
22
|
+
/** Default: `(label, name) => label + "_" + name`. */
|
|
23
|
+
namespace?: (label: string, name: string) => string;
|
|
24
|
+
}
|
|
25
|
+
export interface TagPolicy {
|
|
26
|
+
/** Default: `union`. `namespace` prefixes each tag with the source label. */
|
|
27
|
+
strategy?: "union" | "namespace";
|
|
28
|
+
/** Default: `(label, tag) => label + ":" + tag`. */
|
|
29
|
+
namespace?: (label: string, tag: string) => string;
|
|
30
|
+
}
|
|
31
|
+
export interface ServerPolicy {
|
|
32
|
+
/** Default: `union`. */
|
|
33
|
+
strategy?: "union" | "first" | "last";
|
|
34
|
+
}
|
|
35
|
+
export interface OperationIdPolicy {
|
|
36
|
+
/** Default: `namespace`. */
|
|
37
|
+
onConflict?: "error" | "namespace" | "first-wins" | "last-wins";
|
|
38
|
+
/** Default: `(label, id) => label + "_" + id`. */
|
|
39
|
+
namespace?: (label: string, operationId: string) => string;
|
|
40
|
+
}
|
|
41
|
+
export interface MergeOptions {
|
|
42
|
+
paths?: PathPolicy;
|
|
43
|
+
components?: ComponentPolicy;
|
|
44
|
+
tags?: TagPolicy;
|
|
45
|
+
servers?: ServerPolicy;
|
|
46
|
+
operationIds?: OperationIdPolicy;
|
|
47
|
+
/** Override `info` on the output. Defaults to the first source's `info`. */
|
|
48
|
+
info?: Partial<OpenAPIV3_1.InfoObject>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Per-component-section rename map: `{ schemas: { Pet: "apiA_Pet" }, ... }`.
|
|
52
|
+
* Used to rewrite `$ref` strings consistently after a rename.
|
|
53
|
+
*/
|
|
54
|
+
export type RenameMap = Record<string, Record<string, string>>;
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/merge/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,cAAc,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC7D,mFAAmF;IACnF,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,CAAC;IAChE,sDAAsD;IACtD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACrD;AAED,MAAM,WAAW,SAAS;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IACjC,oDAAoD;IACpD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACpD;AAED,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;CACvC;AAED,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,UAAU,CAAC,EAAE,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,CAAC;IAChE,kDAAkD;IAClD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;CAC5D;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,4EAA4E;IAC5E,IAAI,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/merge/types.ts"],"names":[],"mappings":""}
|
package/dist/merge.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { merge } from "./merge/core.js";
|
|
2
|
+
export { MergeConflictError } from "./merge/paths.js";
|
|
3
|
+
export { rewriteRefs } from "./merge/refs.js";
|
|
4
|
+
export type { ComponentPolicy, Document, MergeOptions, MergeSource, OperationIdPolicy, PathPolicy, RenameMap, ServerPolicy, TagPolicy, } from "./merge/types.js";
|
|
5
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,SAAS,GACV,MAAM,kBAAkB,CAAC"}
|
package/dist/merge.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAE,EAAoB,MAAM,iBAAiB,CAAC;AAEhF;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAgBjE;AAED,YAAY,EAAE,EAAE,EAAE,CAAC"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Logger, Project } from "@hey-api/codegen-core";
|
|
2
|
+
import { Context, getParser, parseOpenApiSpec } from "@hey-api/shared";
|
|
3
|
+
/**
|
|
4
|
+
* Parse an OpenAPI spec (2.0, 3.0, or 3.1) into hey-api's normalized IR.
|
|
5
|
+
*/
|
|
6
|
+
export function parseSpec(spec) {
|
|
7
|
+
const context = new Context({
|
|
8
|
+
config: {
|
|
9
|
+
dryRun: true,
|
|
10
|
+
input: [],
|
|
11
|
+
parser: getParser({}),
|
|
12
|
+
plugins: {},
|
|
13
|
+
pluginOrder: [],
|
|
14
|
+
},
|
|
15
|
+
dependencies: {},
|
|
16
|
+
logger: new Logger(),
|
|
17
|
+
project: new Project({ root: "" }),
|
|
18
|
+
spec,
|
|
19
|
+
});
|
|
20
|
+
parseOpenApiSpec(context);
|
|
21
|
+
return context.ir;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAW,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEhF;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAA6B;IACrD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;QAC1B,MAAM,EAAE;YACN,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;YACrB,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;SACiD;QAClE,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,IAAI,MAAM,EAAE;QACpB,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAClC,IAAI;KACL,CAAC,CAAC;IACH,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC1B,OAAO,OAAO,CAAC,EAAE,CAAC;AACpB,CAAC"}
|
package/dist/route.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A route descriptor — the minimal data needed to match an inbound request
|
|
3
|
+
* against an OpenAPI operation. Designed to be tree-shakable: each route
|
|
4
|
+
* generated by the codegen plugin is its own named export, so unused routes
|
|
5
|
+
* disappear from the bundle.
|
|
6
|
+
*/
|
|
7
|
+
export interface Route<TSpec extends string = string, TMethod extends string = string> {
|
|
8
|
+
/** OpenAPI path template, e.g. `/pets/{petId}` */
|
|
9
|
+
spec: TSpec;
|
|
10
|
+
/** URLPattern-ready pathname, e.g. `/pets/:petId` */
|
|
11
|
+
pattern: string;
|
|
12
|
+
/** HTTP method, lowercase. */
|
|
13
|
+
method: TMethod;
|
|
14
|
+
/** OperationId from the spec, when defined. */
|
|
15
|
+
operationId?: string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,KAAK,CACpB,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,OAAO,SAAS,MAAM,GAAG,MAAM;IAE/B,kDAAkD;IAClD,IAAI,EAAE,KAAK,CAAC;IACZ,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|