@amartus/oas-utils 0.1.0 → 0.3.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/README.md +135 -5
- package/dist/cli.js +52 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/allOfToOneOf.d.ts +23 -0
- package/dist/lib/allOfToOneOf.d.ts.map +1 -0
- package/dist/lib/allOfToOneOf.js +189 -0
- package/dist/lib/allOfToOneOf.js.map +1 -0
- package/dist/lib/cleanupDiscriminatorMappings.d.ts +21 -0
- package/dist/lib/cleanupDiscriminatorMappings.d.ts.map +1 -0
- package/dist/lib/cleanupDiscriminatorMappings.js +64 -0
- package/dist/lib/cleanupDiscriminatorMappings.js.map +1 -0
- package/dist/lib/cliActions.d.ts +37 -2
- package/dist/lib/cliActions.d.ts.map +1 -1
- package/dist/lib/cliActions.js +108 -12
- package/dist/lib/cliActions.js.map +1 -1
- package/dist/lib/oasUtils.d.ts +27 -0
- package/dist/lib/oasUtils.d.ts.map +1 -1
- package/dist/lib/oasUtils.js +92 -0
- package/dist/lib/oasUtils.js.map +1 -1
- package/dist/lib/removeFromOneOfByName.d.ts +1 -0
- package/dist/lib/removeFromOneOfByName.d.ts.map +1 -1
- package/dist/lib/removeFromOneOfByName.js +10 -48
- package/dist/lib/removeFromOneOfByName.js.map +1 -1
- package/dist/lib/schemaTransformUtils.d.ts +83 -0
- package/dist/lib/schemaTransformUtils.d.ts.map +1 -0
- package/dist/lib/schemaTransformUtils.js +192 -0
- package/dist/lib/schemaTransformUtils.js.map +1 -0
- package/dist/lib/sealSchema.d.ts +22 -0
- package/dist/lib/sealSchema.d.ts.map +1 -0
- package/dist/lib/sealSchema.js +354 -0
- package/dist/lib/sealSchema.js.map +1 -0
- package/dist/redocly/allof-to-oneof-decorator.d.ts +6 -0
- package/dist/redocly/allof-to-oneof-decorator.d.ts.map +1 -0
- package/dist/redocly/allof-to-oneof-decorator.js +15 -0
- package/dist/redocly/allof-to-oneof-decorator.js.map +1 -0
- package/dist/redocly/cleanup-discriminator-decorator.d.ts +6 -0
- package/dist/redocly/cleanup-discriminator-decorator.d.ts.map +1 -0
- package/dist/redocly/cleanup-discriminator-decorator.js +17 -0
- package/dist/redocly/cleanup-discriminator-decorator.js.map +1 -0
- package/dist/redocly/plugin.d.ts +9 -0
- package/dist/redocly/plugin.d.ts.map +1 -1
- package/dist/redocly/plugin.js +9 -0
- package/dist/redocly/plugin.js.map +1 -1
- package/dist/redocly/seal-schema-decorator.d.ts +6 -0
- package/dist/redocly/seal-schema-decorator.d.ts.map +1 -0
- package/dist/redocly/seal-schema-decorator.js +13 -0
- package/dist/redocly/seal-schema-decorator.js.map +1 -0
- package/package.json +1 -1
package/dist/lib/cliActions.d.ts
CHANGED
|
@@ -13,10 +13,45 @@ export declare function runRemoveOneOf(opts: {
|
|
|
13
13
|
/**
|
|
14
14
|
* Optimizes allOf composition in the provided OpenAPI document.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
16
|
+
* @param opts - Options including output path
|
|
17
|
+
* @param format - Function to format output
|
|
18
|
+
* @param reader - Function to read input
|
|
18
19
|
*/
|
|
19
20
|
export declare function optimizeAllOf(opts: {
|
|
20
21
|
output?: string;
|
|
21
22
|
}, format: (doc: any, target?: string) => string, reader: () => Promise<string>): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Converts allOf + discriminator patterns to oneOf + discriminator.
|
|
25
|
+
*
|
|
26
|
+
* @param opts - Options including output path and transformation options
|
|
27
|
+
* @param format - Function to format output
|
|
28
|
+
* @param reader - Function to read input
|
|
29
|
+
*/
|
|
30
|
+
export declare function runAllOfToOneOf(opts: {
|
|
31
|
+
output?: string;
|
|
32
|
+
removeDiscriminatorFromBase?: boolean;
|
|
33
|
+
addDiscriminatorConst?: boolean;
|
|
34
|
+
ignoreSingleSpecialization?: boolean;
|
|
35
|
+
}, format: (doc: any, target?: string) => string, reader: () => Promise<string>): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Seals object schemas to prevent additional properties.
|
|
38
|
+
*
|
|
39
|
+
* @param opts - Options including output path and sealing options
|
|
40
|
+
* @param format - Function to format output
|
|
41
|
+
* @param reader - Function to read input
|
|
42
|
+
*/
|
|
43
|
+
export declare function runSealSchema(opts: {
|
|
44
|
+
output?: string;
|
|
45
|
+
useUnevaluatedProperties?: boolean;
|
|
46
|
+
}, format: (doc: any, target?: string) => string, reader: () => Promise<string>): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Cleans up discriminator mappings by removing entries pointing to non-existent schemas.
|
|
49
|
+
*
|
|
50
|
+
* @param opts - Options including output path
|
|
51
|
+
* @param format - Function to format output
|
|
52
|
+
* @param reader - Function to read input
|
|
53
|
+
*/
|
|
54
|
+
export declare function runCleanupDiscriminators(opts: {
|
|
55
|
+
output?: string;
|
|
56
|
+
}, format: (doc: any, target?: string) => string, reader: () => Promise<string>): Promise<void>;
|
|
22
57
|
//# sourceMappingURL=cliActions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliActions.d.ts","sourceRoot":"","sources":["../../src/lib/cliActions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cliActions.d.ts","sourceRoot":"","sources":["../../src/lib/cliActions.ts"],"names":[],"mappings":"AAyEA,wBAAsB,eAAe,CACnC,IAAI,EAAE;IACJ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,EACD,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,EAC7C,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,iBAiB9B;AAQ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BAAwB,CAC5C,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EACzB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,EAC7C,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,iBAuB9B"}
|
package/dist/lib/cliActions.js
CHANGED
|
@@ -4,6 +4,9 @@ import YAML from "yaml";
|
|
|
4
4
|
import { optimizeAllOfComposition } from "./optimizeAllOfComposition.js";
|
|
5
5
|
import { removeUnusedSchemas } from "./removeUnusedSchemas.js";
|
|
6
6
|
import { removeFromOneOfByName, removeFromOneOfGlobally, } from "./removeFromOneOfByName.js";
|
|
7
|
+
import { allOfToOneOf } from "./allOfToOneOf.js";
|
|
8
|
+
import { sealSchema } from "./sealSchema.js";
|
|
9
|
+
import { cleanupDiscriminatorMappings } from "./cleanupDiscriminatorMappings.js";
|
|
7
10
|
function parseYamlOrJson(data) {
|
|
8
11
|
// Accept pre-parsed objects (useful in tests)
|
|
9
12
|
if (data && typeof data === "object")
|
|
@@ -43,17 +46,34 @@ function logSchemaChanges(before, after) {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Helper to validate that a document has components.schemas
|
|
51
|
+
* Logs error and returns false if invalid
|
|
52
|
+
*/
|
|
53
|
+
function validateComponentSchemas(doc) {
|
|
54
|
+
if (!doc.components || !doc.components.schemas) {
|
|
55
|
+
console.error("[ERROR] The input document does not contain valid components.schemas.");
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Helper to convert option values to arrays if needed
|
|
62
|
+
*/
|
|
63
|
+
function toArray(value) {
|
|
64
|
+
if (Array.isArray(value))
|
|
65
|
+
return value;
|
|
66
|
+
return value ? String(value).split(",").map(s => s.trim()).filter(Boolean) : [];
|
|
67
|
+
}
|
|
46
68
|
export async function runRemoveUnused(opts, format, reader) {
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const ignoreParents = Array.isArray(opts.ignoreParents) ? opts.ignoreParents : (opts.ignoreParents ? String(opts.ignoreParents).split(",").map(s => s.trim()).filter(Boolean) : []);
|
|
69
|
+
const keep = toArray(opts.keep);
|
|
70
|
+
const ignoreParents = toArray(opts.ignoreParents);
|
|
50
71
|
const ropts = {
|
|
51
72
|
keep,
|
|
52
73
|
aggressive: Boolean(opts.aggressive),
|
|
53
74
|
ignoreParents,
|
|
54
75
|
};
|
|
55
|
-
|
|
56
|
-
doc = parseYamlOrJson(await reader());
|
|
76
|
+
const doc = parseYamlOrJson(await reader());
|
|
57
77
|
const beforeSchemas = Object.keys(doc?.components?.schemas ?? {});
|
|
58
78
|
removeUnusedSchemas(doc, ropts);
|
|
59
79
|
const afterSchemas = Object.keys(doc?.components?.schemas ?? {});
|
|
@@ -66,10 +86,8 @@ function guess(name, doc) {
|
|
|
66
86
|
}
|
|
67
87
|
export async function runRemoveOneOf(opts, format, reader) {
|
|
68
88
|
const doc = parseYamlOrJson(await reader());
|
|
69
|
-
if (!doc
|
|
70
|
-
console.error("[ERROR] The input document does not contain valid components.schemas.");
|
|
89
|
+
if (!validateComponentSchemas(doc))
|
|
71
90
|
return;
|
|
72
|
-
}
|
|
73
91
|
const toRemove = opts.guess ? opts.remove.flatMap((name) => guess(name, doc)) : opts.remove;
|
|
74
92
|
if (opts.parent) {
|
|
75
93
|
let anyChanged = false;
|
|
@@ -108,13 +126,91 @@ export async function runRemoveOneOf(opts, format, reader) {
|
|
|
108
126
|
/**
|
|
109
127
|
* Optimizes allOf composition in the provided OpenAPI document.
|
|
110
128
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @param
|
|
129
|
+
* @param opts - Options including output path
|
|
130
|
+
* @param format - Function to format output
|
|
131
|
+
* @param reader - Function to read input
|
|
113
132
|
*/
|
|
114
133
|
export async function optimizeAllOf(opts, format, reader) {
|
|
115
|
-
const
|
|
116
|
-
const doc = parseYamlOrJson(data);
|
|
134
|
+
const doc = parseYamlOrJson(await reader());
|
|
117
135
|
optimizeAllOfComposition(doc);
|
|
118
136
|
await writeOutput(doc, opts.output, format);
|
|
119
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Converts allOf + discriminator patterns to oneOf + discriminator.
|
|
140
|
+
*
|
|
141
|
+
* @param opts - Options including output path and transformation options
|
|
142
|
+
* @param format - Function to format output
|
|
143
|
+
* @param reader - Function to read input
|
|
144
|
+
*/
|
|
145
|
+
export async function runAllOfToOneOf(opts, format, reader) {
|
|
146
|
+
const doc = parseYamlOrJson(await reader());
|
|
147
|
+
if (!validateComponentSchemas(doc))
|
|
148
|
+
return;
|
|
149
|
+
const beforeSchemas = Object.keys(doc.components.schemas);
|
|
150
|
+
const topts = {
|
|
151
|
+
removeDiscriminatorFromBase: Boolean(opts.removeDiscriminatorFromBase),
|
|
152
|
+
addDiscriminatorConst: opts.addDiscriminatorConst !== false,
|
|
153
|
+
ignoreSingleSpecialization: Boolean(opts.ignoreSingleSpecialization),
|
|
154
|
+
};
|
|
155
|
+
allOfToOneOf(doc, topts);
|
|
156
|
+
const afterSchemas = Object.keys(doc.components.schemas);
|
|
157
|
+
const newSchemas = afterSchemas.filter(s => !beforeSchemas.includes(s));
|
|
158
|
+
if (newSchemas.length > 0) {
|
|
159
|
+
console.error(`[ALLOF-TO-ONEOF] Created wrapper schema(s): ${newSchemas.join(", ")}`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
console.error("[INFO] No allOf + discriminator patterns found to convert.");
|
|
163
|
+
}
|
|
164
|
+
await writeOutput(doc, opts.output, format);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Seals object schemas to prevent additional properties.
|
|
168
|
+
*
|
|
169
|
+
* @param opts - Options including output path and sealing options
|
|
170
|
+
* @param format - Function to format output
|
|
171
|
+
* @param reader - Function to read input
|
|
172
|
+
*/
|
|
173
|
+
export async function runSealSchema(opts, format, reader) {
|
|
174
|
+
const doc = parseYamlOrJson(await reader());
|
|
175
|
+
if (!validateComponentSchemas(doc))
|
|
176
|
+
return;
|
|
177
|
+
const beforeSchemaCount = Object.keys(doc.components.schemas).length;
|
|
178
|
+
const sopts = {
|
|
179
|
+
useUnevaluatedProperties: opts.useUnevaluatedProperties !== false,
|
|
180
|
+
};
|
|
181
|
+
sealSchema(doc, sopts);
|
|
182
|
+
const afterSchemaCount = Object.keys(doc.components.schemas).length;
|
|
183
|
+
const sealingKeyword = sopts.useUnevaluatedProperties ? "unevaluatedProperties" : "additionalProperties";
|
|
184
|
+
console.error(`[SEAL-SCHEMA] Sealed schemas (${sealingKeyword}). Total schemas: ${beforeSchemaCount} -> ${afterSchemaCount}`);
|
|
185
|
+
await writeOutput(doc, opts.output, format);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Cleans up discriminator mappings by removing entries pointing to non-existent schemas.
|
|
189
|
+
*
|
|
190
|
+
* @param opts - Options including output path
|
|
191
|
+
* @param format - Function to format output
|
|
192
|
+
* @param reader - Function to read input
|
|
193
|
+
*/
|
|
194
|
+
export async function runCleanupDiscriminators(opts, format, reader) {
|
|
195
|
+
const doc = parseYamlOrJson(await reader());
|
|
196
|
+
if (!validateComponentSchemas(doc))
|
|
197
|
+
return;
|
|
198
|
+
const result = cleanupDiscriminatorMappings(doc);
|
|
199
|
+
if (result.schemasChecked > 0) {
|
|
200
|
+
console.error(`[CLEANUP-DISCRIMINATORS] Checked ${result.schemasChecked} schema(s) with discriminators.`);
|
|
201
|
+
if (result.mappingsRemoved > 0) {
|
|
202
|
+
console.error(`[CLEANUP-DISCRIMINATORS] Removed ${result.mappingsRemoved} mapping(s).`);
|
|
203
|
+
for (const detail of result.details) {
|
|
204
|
+
console.error(`[CLEANUP-DISCRIMINATORS] Schema '${detail.schema}': removed mappings [${detail.removed.join(", ")}]`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
console.error("[INFO] All discriminator mappings are valid (no changes needed).");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
console.error("[INFO] No schemas with discriminators found.");
|
|
213
|
+
}
|
|
214
|
+
await writeOutput(doc, opts.output, format);
|
|
215
|
+
}
|
|
120
216
|
//# sourceMappingURL=cliActions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliActions.js","sourceRoot":"","sources":["../../src/lib/cliActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAiB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"cliActions.js","sourceRoot":"","sources":["../../src/lib/cliActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAiB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAqB,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,SAAS,eAAe,CAAC,IAAS;IAChC,8CAA8C;IAC9C,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QA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IAAI,MAAM,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,oCAAoC,MAAM,CAAC,eAAe,cAAc,CAAC,CAAC;YACxF,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpC,OAAO,CAAC,KAAK,CAAC,sCAAsC,MAAM,CAAC,MAAM,wBAAwB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACzH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACpF,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/lib/oasUtils.d.ts
CHANGED
|
@@ -2,4 +2,31 @@
|
|
|
2
2
|
* Helper to extract a components/schemas ref name from a $ref string.
|
|
3
3
|
*/
|
|
4
4
|
export declare function refToName(ref: string): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Builds an inheritance/composition graph from OpenAPI schemas.
|
|
7
|
+
*
|
|
8
|
+
* Returns a Map where:
|
|
9
|
+
* - Key: schema name (parent type)
|
|
10
|
+
* - Value: Set of schema names that extend/compose this parent via allOf
|
|
11
|
+
*
|
|
12
|
+
* @param schemas - The components.schemas object from an OpenAPI document
|
|
13
|
+
* @returns Map<string, Set<string>> - Parent schema to child schemas mapping
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildInheritanceGraph(schemas: Record<string, any>): Map<string, Set<string>>;
|
|
16
|
+
/**
|
|
17
|
+
* Gets all descendants (direct and transitive) of a schema in the inheritance graph.
|
|
18
|
+
*
|
|
19
|
+
* @param parentName - The schema name to find descendants for
|
|
20
|
+
* @param graph - The inheritance graph from buildInheritanceGraph()
|
|
21
|
+
* @returns Set<string> - All descendant schema names
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDescendants(parentName: string, graph: Map<string, Set<string>>): Set<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Gets all ancestors (direct and transitive) of a schema in the inheritance hierarchy.
|
|
26
|
+
*
|
|
27
|
+
* @param childName - The schema name to find ancestors for
|
|
28
|
+
* @param schemas - The components.schemas object from an OpenAPI document
|
|
29
|
+
* @returns Set<string> - All ancestor schema names
|
|
30
|
+
*/
|
|
31
|
+
export declare function getAncestors(childName: string, schemas: Record<string, any>): Set<string>;
|
|
5
32
|
//# sourceMappingURL=oasUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oasUtils.d.ts","sourceRoot":"","sources":["../../src/lib/oasUtils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGzD"}
|
|
1
|
+
{"version":3,"file":"oasUtils.d.ts","sourceRoot":"","sources":["../../src/lib/oasUtils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CA6B5F;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAmB/F;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAyBzF"}
|
package/dist/lib/oasUtils.js
CHANGED
|
@@ -6,4 +6,96 @@ export function refToName(ref) {
|
|
|
6
6
|
const m = ref.match(/^#\/(?:components\/)?schemas\/([^#/]+)$/);
|
|
7
7
|
return m ? decodeURIComponent(m[1]) : undefined;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Builds an inheritance/composition graph from OpenAPI schemas.
|
|
11
|
+
*
|
|
12
|
+
* Returns a Map where:
|
|
13
|
+
* - Key: schema name (parent type)
|
|
14
|
+
* - Value: Set of schema names that extend/compose this parent via allOf
|
|
15
|
+
*
|
|
16
|
+
* @param schemas - The components.schemas object from an OpenAPI document
|
|
17
|
+
* @returns Map<string, Set<string>> - Parent schema to child schemas mapping
|
|
18
|
+
*/
|
|
19
|
+
export function buildInheritanceGraph(schemas) {
|
|
20
|
+
const graph = new Map();
|
|
21
|
+
if (!schemas || typeof schemas !== "object") {
|
|
22
|
+
return graph;
|
|
23
|
+
}
|
|
24
|
+
// Iterate through all schemas
|
|
25
|
+
for (const [childName, schema] of Object.entries(schemas)) {
|
|
26
|
+
if (!schema || typeof schema !== "object")
|
|
27
|
+
continue;
|
|
28
|
+
// Look for allOf references in this schema
|
|
29
|
+
if (Array.isArray(schema.allOf)) {
|
|
30
|
+
for (const item of schema.allOf) {
|
|
31
|
+
if (item && typeof item === "object" && typeof item.$ref === "string") {
|
|
32
|
+
const parentName = refToName(item.$ref);
|
|
33
|
+
if (parentName) {
|
|
34
|
+
// Add this child to the parent's set
|
|
35
|
+
if (!graph.has(parentName)) {
|
|
36
|
+
graph.set(parentName, new Set());
|
|
37
|
+
}
|
|
38
|
+
graph.get(parentName).add(childName);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return graph;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets all descendants (direct and transitive) of a schema in the inheritance graph.
|
|
48
|
+
*
|
|
49
|
+
* @param parentName - The schema name to find descendants for
|
|
50
|
+
* @param graph - The inheritance graph from buildInheritanceGraph()
|
|
51
|
+
* @returns Set<string> - All descendant schema names
|
|
52
|
+
*/
|
|
53
|
+
export function getDescendants(parentName, graph) {
|
|
54
|
+
const descendants = new Set();
|
|
55
|
+
const queue = [parentName];
|
|
56
|
+
while (queue.length > 0) {
|
|
57
|
+
const current = queue.shift();
|
|
58
|
+
const children = graph.get(current);
|
|
59
|
+
if (children) {
|
|
60
|
+
for (const child of children) {
|
|
61
|
+
if (!descendants.has(child)) {
|
|
62
|
+
descendants.add(child);
|
|
63
|
+
queue.push(child);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return descendants;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets all ancestors (direct and transitive) of a schema in the inheritance hierarchy.
|
|
72
|
+
*
|
|
73
|
+
* @param childName - The schema name to find ancestors for
|
|
74
|
+
* @param schemas - The components.schemas object from an OpenAPI document
|
|
75
|
+
* @returns Set<string> - All ancestor schema names
|
|
76
|
+
*/
|
|
77
|
+
export function getAncestors(childName, schemas) {
|
|
78
|
+
const ancestors = new Set();
|
|
79
|
+
const queue = [childName];
|
|
80
|
+
const visited = new Set();
|
|
81
|
+
while (queue.length > 0) {
|
|
82
|
+
const current = queue.shift();
|
|
83
|
+
if (visited.has(current))
|
|
84
|
+
continue;
|
|
85
|
+
visited.add(current);
|
|
86
|
+
const schema = schemas[current];
|
|
87
|
+
if (!schema || typeof schema !== "object" || !Array.isArray(schema.allOf))
|
|
88
|
+
continue;
|
|
89
|
+
for (const item of schema.allOf) {
|
|
90
|
+
if (item && typeof item === "object" && typeof item.$ref === "string") {
|
|
91
|
+
const parentName = refToName(item.$ref);
|
|
92
|
+
if (parentName && !ancestors.has(parentName)) {
|
|
93
|
+
ancestors.add(parentName);
|
|
94
|
+
queue.push(parentName);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return ancestors;
|
|
100
|
+
}
|
|
9
101
|
//# sourceMappingURL=oasUtils.js.map
|
package/dist/lib/oasUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oasUtils.js","sourceRoot":"","sources":["../../src/lib/oasUtils.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAElC;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,OAAO,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC"}
|
|
1
|
+
{"version":3,"file":"oasUtils.js","sourceRoot":"","sources":["../../src/lib/oasUtils.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAElC;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,OAAO,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA4B;IAChE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IAE7C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,8BAA8B;IAC9B,KAAK,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,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OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -10,6 +10,7 @@ export declare function removeFromOneOfGlobally(doc: any, removeName: string): n
|
|
|
10
10
|
* @param doc OpenAPI document
|
|
11
11
|
* @param parentSchemaName Name of the parent schema containing oneOf
|
|
12
12
|
* @param removeName Name of the schema to remove from oneOf
|
|
13
|
+
* @returns true if schema was removed
|
|
13
14
|
*/
|
|
14
15
|
export declare function removeFromOneOfByName(doc: any, parentSchemaName: string, removeName: string): boolean;
|
|
15
16
|
//# sourceMappingURL=removeFromOneOfByName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeFromOneOfByName.d.ts","sourceRoot":"","sources":["../../src/lib/removeFromOneOfByName.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"removeFromOneOfByName.d.ts","sourceRoot":"","sources":["../../src/lib/removeFromOneOfByName.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAU5E;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAOrG"}
|
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (node.discriminator && node.discriminator.mapping) {
|
|
3
|
-
for (const [key, ref] of Object.entries(node.discriminator.mapping)) {
|
|
4
|
-
const name = refToName(ref);
|
|
5
|
-
if (name === removeName) {
|
|
6
|
-
delete node.discriminator.mapping[key];
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
function updateOneOf(node, removeName) {
|
|
14
|
-
if (!node || !Array.isArray(node.oneOf)) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const beforeLength = node.oneOf.length;
|
|
18
|
-
node.oneOf = node.oneOf.filter((item) => {
|
|
19
|
-
if (typeof item?.$ref === "string") {
|
|
20
|
-
const name = refToName(item.$ref);
|
|
21
|
-
return name !== removeName;
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
});
|
|
25
|
-
return beforeLength !== node.oneOf.length;
|
|
26
|
-
}
|
|
1
|
+
import { removeFromCollectionAndUpdateDiscriminator, traverseAndTransform } from "./schemaTransformUtils.js";
|
|
27
2
|
/**
|
|
28
3
|
* Remove a schema from all oneOfs in the OAS and update discriminator mappings globally.
|
|
29
4
|
* @param doc OpenAPI document
|
|
@@ -31,40 +6,27 @@ function updateOneOf(node, removeName) {
|
|
|
31
6
|
* @returns Number of schemas modified
|
|
32
7
|
*/
|
|
33
8
|
export function removeFromOneOfGlobally(doc, removeName) {
|
|
9
|
+
const schemaNames = new Set([removeName]);
|
|
34
10
|
let modified = 0;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
node.forEach(traverse);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (updateOneOf(node, removeName)) {
|
|
43
|
-
updateDiscriminator(node, removeName);
|
|
44
|
-
modified++;
|
|
45
|
-
}
|
|
46
|
-
for (const k of Object.keys(node)) {
|
|
47
|
-
traverse(node[k]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
traverse(doc);
|
|
11
|
+
const transformer = (node) => {
|
|
12
|
+
return removeFromCollectionAndUpdateDiscriminator(node, "oneOf", schemaNames);
|
|
13
|
+
};
|
|
14
|
+
modified = traverseAndTransform(doc, transformer);
|
|
51
15
|
return modified;
|
|
52
16
|
}
|
|
53
|
-
import { refToName } from './oasUtils.js';
|
|
54
17
|
/**
|
|
55
18
|
* Remove a schema from oneOf by name and update discriminator mappings.
|
|
56
19
|
* @param doc OpenAPI document
|
|
57
20
|
* @param parentSchemaName Name of the parent schema containing oneOf
|
|
58
21
|
* @param removeName Name of the schema to remove from oneOf
|
|
22
|
+
* @returns true if schema was removed
|
|
59
23
|
*/
|
|
60
24
|
export function removeFromOneOfByName(doc, parentSchemaName, removeName) {
|
|
61
25
|
if (!doc?.components?.schemas)
|
|
62
26
|
return false;
|
|
63
27
|
const parentSchema = doc.components.schemas[parentSchemaName];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
28
|
+
if (!parentSchema)
|
|
29
|
+
return false;
|
|
30
|
+
return removeFromCollectionAndUpdateDiscriminator(parentSchema, "oneOf", new Set([removeName]));
|
|
69
31
|
}
|
|
70
32
|
//# sourceMappingURL=removeFromOneOfByName.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeFromOneOfByName.js","sourceRoot":"","sources":["../../src/lib/removeFromOneOfByName.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"removeFromOneOfByName.js","sourceRoot":"","sources":["../../src/lib/removeFromOneOfByName.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0CAA0C,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAE7G;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAQ,EAAE,UAAkB;IAClE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1C,IAAI,QAAQ,GAAG,CAAC,CAAC;IAEjB,MAAM,WAAW,GAAG,CAAC,IAAS,EAAW,EAAE;QACzC,OAAO,0CAA0C,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IAChF,CAAC,CAAC;IAEF,QAAQ,GAAG,oBAAoB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAClD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAQ,EAAE,gBAAwB,EAAE,UAAkB;IAC1F,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO;QAAE,OAAO,KAAK,CAAC;IAE5C,MAAM,YAAY,GAAG,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC9D,IAAI,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAEhC,OAAO,0CAA0C,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common patterns and utilities for schema traversal and transformation algorithms.
|
|
3
|
+
* Provides reusable building blocks for schema manipulation operations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Callback for schema transformation during traversal.
|
|
7
|
+
* Return true if schema was modified.
|
|
8
|
+
*/
|
|
9
|
+
export type SchemaTransformer = (node: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Predicate to filter schemas during traversal
|
|
12
|
+
*/
|
|
13
|
+
export type SchemaPredicate = (node: any) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Traverses all nodes in an OAS document recursively (depth-first).
|
|
16
|
+
* Applies transformer callback to each node, counts modifications.
|
|
17
|
+
*
|
|
18
|
+
* @param node - Root node to traverse
|
|
19
|
+
* @param transformer - Function called on each node, returns true if modified
|
|
20
|
+
* @returns Number of nodes modified
|
|
21
|
+
*/
|
|
22
|
+
export declare function traverseAndTransform(node: any, transformer: SchemaTransformer): number;
|
|
23
|
+
/**
|
|
24
|
+
* Collects all schemas matching a predicate during traversal.
|
|
25
|
+
*
|
|
26
|
+
* @param node - Root node to traverse
|
|
27
|
+
* @param predicate - Function to test each node
|
|
28
|
+
* @returns Array of matching nodes
|
|
29
|
+
*/
|
|
30
|
+
export declare function collectMatching(node: any, predicate: SchemaPredicate): any[];
|
|
31
|
+
/**
|
|
32
|
+
* Updates discriminator mappings in a schema node.
|
|
33
|
+
* Removes mapping entries where the predicate returns false.
|
|
34
|
+
*
|
|
35
|
+
* @param node - Schema node with discriminator
|
|
36
|
+
* @param keepPredicate - Returns true if mapping entry should be kept
|
|
37
|
+
* @returns Number of mappings removed
|
|
38
|
+
*/
|
|
39
|
+
export declare function updateDiscriminatorMappings(node: any, keepPredicate: (key: string, ref: string) => boolean): number;
|
|
40
|
+
/**
|
|
41
|
+
* Filters a collection within a schema node by predicate.
|
|
42
|
+
* Mutates the array in place.
|
|
43
|
+
*
|
|
44
|
+
* @param node - Schema node with collection property
|
|
45
|
+
* @param propertyName - Name of array property (e.g., 'oneOf', 'anyOf')
|
|
46
|
+
* @param keepPredicate - Returns true if item should be kept
|
|
47
|
+
* @returns Number of items removed
|
|
48
|
+
*/
|
|
49
|
+
export declare function filterSchemaCollection(node: any, propertyName: string, keepPredicate: (item: any) => boolean): number;
|
|
50
|
+
/**
|
|
51
|
+
* Extracts schema name from a $ref string in a collection item.
|
|
52
|
+
* Returns undefined if item is not a $ref or is invalid.
|
|
53
|
+
*
|
|
54
|
+
* @param item - Item from schema collection (e.g., from oneOf, anyOf)
|
|
55
|
+
* @returns Schema name or undefined
|
|
56
|
+
*/
|
|
57
|
+
export declare function getRefFromCollectionItem(item: any): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Removes items from a schema collection that reference specific schemas.
|
|
60
|
+
* Also updates discriminator mappings for the removed schema names.
|
|
61
|
+
*
|
|
62
|
+
* @param node - Parent schema node
|
|
63
|
+
* @param propertyName - Collection property name (e.g., 'oneOf')
|
|
64
|
+
* @param schemaNames - Set of schema names to remove
|
|
65
|
+
* @returns true if any modifications were made
|
|
66
|
+
*/
|
|
67
|
+
export declare function removeFromCollectionAndUpdateDiscriminator(node: any, propertyName: string, schemaNames: Set<string>): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Clones a schema object with all its nested properties.
|
|
70
|
+
*
|
|
71
|
+
* @param schema - Schema to clone
|
|
72
|
+
* @returns Deep clone of schema
|
|
73
|
+
*/
|
|
74
|
+
export declare function cloneSchema<T extends any>(schema: T): T;
|
|
75
|
+
/**
|
|
76
|
+
* Gets all schemas that reference a given schema name via $ref.
|
|
77
|
+
*
|
|
78
|
+
* @param schemas - Map of schemas
|
|
79
|
+
* @param targetName - Name of schema to find references to
|
|
80
|
+
* @returns Set of schema names that reference the target
|
|
81
|
+
*/
|
|
82
|
+
export declare function getSchemaReferencers(schemas: Record<string, any>, targetName: string): Set<string>;
|
|
83
|
+
//# sourceMappingURL=schemaTransformUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaTransformUtils.d.ts","sourceRoot":"","sources":["../../src/lib/schemaTransformUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,iBAAiB,GAAG,MAAM,CAoBtF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,GAAG,GAAG,EAAE,CAmB5E;AAED;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,GAAG,EACT,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,GACnD,MAAM,CAgBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,GAAG,EACT,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,GACpC,MAAM,CAQR;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,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