@nestia/migrate 11.0.0-dev.20260313-4 → 11.0.0-dev.20260314

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.
@@ -1,134 +1,134 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- /**
4
- * Recursively walk a JSON object and invoke a callback function on each `{
5
- * "$ref" : "path" }` object found
6
- */
7
-
8
- /**
9
- * Represents a JSON Reference object, such as `{"$ref":
10
- * "#/components/schemas/problemResponse" }`
11
- */
12
- export interface RefObject {
13
- $ref: string;
14
- }
15
-
16
- /** JsonNode represents a node within the OpenAPI object */
17
- export type JsonNode = object | [] | string | boolean | null | number;
18
-
19
- /** A JSON Schema object in an API def */
20
- export type SchemaObject = object;
21
-
22
- /** Function signature for the visitRefObjects callback */
23
- export type RefVisitor = (node: RefObject) => JsonNode;
24
- /** Function signature for the visitSchemaObjects callback */
25
- export type SchemaVisitor = (node: SchemaObject) => SchemaObject;
26
-
27
- /** /** Function signature for the walkObject callback */
28
- export type ObjectVisitor = (node: object) => JsonNode;
29
-
30
- /** Test if a JSON node is a `{ $ref: "uri" }` object */
31
- export function isRef(node: any): boolean {
32
- return (
33
- node !== null &&
34
- typeof node === "object" &&
35
- node.hasOwnProperty("$ref") &&
36
- typeof node["$ref"] === "string"
37
- );
38
- }
39
-
40
- /**
41
- * Walk a JSON object and apply `schemaCallback` when a JSON schema is found.
42
- * JSON Schema objects are items in components/schemas or in an item named
43
- * `schema`
44
- *
45
- * @param node A node in the OpenAPI document
46
- * @param schemaCallback The function to call on JSON schema objects
47
- * @returns The modified (annotated) node
48
- */
49
- export function visitSchemaObjects(
50
- node: any,
51
- schemaCallback: SchemaVisitor,
52
- ): any {
53
- const objectVisitor = (node: any): JsonNode => {
54
- if (node.hasOwnProperty("schema")) {
55
- const schema = node["schema"];
56
- if (schema != null && typeof schema === "object") {
57
- node["schema"] = schemaCallback(schema);
58
- }
59
- } else if (node.hasOwnProperty("schemas")) {
60
- const schemas = node["schemas"];
61
- if (schemas != null && typeof schemas === "object") {
62
- for (const schemaName in schemas) {
63
- const schema = schemas[schemaName];
64
- const newSchema = schemaCallback(schema);
65
- schemas[schemaName] = newSchema;
66
- }
67
- }
68
- }
69
- return node;
70
- };
71
- return walkObject(node, objectVisitor);
72
- }
73
-
74
- /**
75
- * Walk a JSON object and apply `refCallback` when a JSON `{$ref: url }` is
76
- * found
77
- *
78
- * @param node A node in the OpenAPI document
79
- * @param refCallback The function to call on JSON `$ref` objects
80
- * @returns The modified (annotated) node
81
- */
82
- export function visitRefObjects(node: any, refCallback: RefVisitor): any {
83
- const objectVisitor = (node: object): JsonNode => {
84
- if (isRef(node)) {
85
- return refCallback(node as RefObject);
86
- }
87
- return node;
88
- };
89
- return walkObject(node, objectVisitor);
90
- }
91
-
92
- /**
93
- * Walk a JSON object or array and apply objectCallback when a JSON object is
94
- * found
95
- *
96
- * @param node A node in the OpenAPI document
97
- * @param objectCallback The function to call on JSON objects
98
- * @param nav Tracks where we are in the original document
99
- * @returns The modified (annotated) node
100
- */
101
- export function walkObject(
102
- node: object,
103
- objectCallback: ObjectVisitor,
104
- ): JsonNode {
105
- return walkObj(node);
106
-
107
- function walkObj(node: any): JsonNode {
108
- const object = objectCallback(node);
109
- if (object !== null && typeof object === "object") {
110
- const keys = [...Object.keys(node)]; // make copy since this code may re-enter objects
111
- for (const key of keys) {
112
- const val = node[key];
113
- if (Array.isArray(val)) {
114
- node[key] = walkArray(val as []);
115
- } else if (val !== null && typeof val === "object") {
116
- node[key] = walkObj(val);
117
- }
118
- }
119
- }
120
- return object;
121
- }
122
-
123
- function walkArray(array: JsonNode[]): JsonNode[] {
124
- for (let index = 0; index < array.length; index += 1) {
125
- const val = array[index] as JsonNode;
126
- if (val !== null && typeof val === "object") {
127
- array[index] = walkObj(val) as object;
128
- } else if (Array.isArray(val)) {
129
- array[index] = walkArray(val as JsonNode[]) as [];
130
- }
131
- }
132
- return array;
133
- }
134
- }
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ /**
4
+ * Recursively walk a JSON object and invoke a callback function on each `{
5
+ * "$ref" : "path" }` object found
6
+ */
7
+
8
+ /**
9
+ * Represents a JSON Reference object, such as `{"$ref":
10
+ * "#/components/schemas/problemResponse" }`
11
+ */
12
+ export interface RefObject {
13
+ $ref: string;
14
+ }
15
+
16
+ /** JsonNode represents a node within the OpenAPI object */
17
+ export type JsonNode = object | [] | string | boolean | null | number;
18
+
19
+ /** A JSON Schema object in an API def */
20
+ export type SchemaObject = object;
21
+
22
+ /** Function signature for the visitRefObjects callback */
23
+ export type RefVisitor = (node: RefObject) => JsonNode;
24
+ /** Function signature for the visitSchemaObjects callback */
25
+ export type SchemaVisitor = (node: SchemaObject) => SchemaObject;
26
+
27
+ /** /** Function signature for the walkObject callback */
28
+ export type ObjectVisitor = (node: object) => JsonNode;
29
+
30
+ /** Test if a JSON node is a `{ $ref: "uri" }` object */
31
+ export function isRef(node: any): boolean {
32
+ return (
33
+ node !== null &&
34
+ typeof node === "object" &&
35
+ node.hasOwnProperty("$ref") &&
36
+ typeof node["$ref"] === "string"
37
+ );
38
+ }
39
+
40
+ /**
41
+ * Walk a JSON object and apply `schemaCallback` when a JSON schema is found.
42
+ * JSON Schema objects are items in components/schemas or in an item named
43
+ * `schema`
44
+ *
45
+ * @param node A node in the OpenAPI document
46
+ * @param schemaCallback The function to call on JSON schema objects
47
+ * @returns The modified (annotated) node
48
+ */
49
+ export function visitSchemaObjects(
50
+ node: any,
51
+ schemaCallback: SchemaVisitor,
52
+ ): any {
53
+ const objectVisitor = (node: any): JsonNode => {
54
+ if (node.hasOwnProperty("schema")) {
55
+ const schema = node["schema"];
56
+ if (schema != null && typeof schema === "object") {
57
+ node["schema"] = schemaCallback(schema);
58
+ }
59
+ } else if (node.hasOwnProperty("schemas")) {
60
+ const schemas = node["schemas"];
61
+ if (schemas != null && typeof schemas === "object") {
62
+ for (const schemaName in schemas) {
63
+ const schema = schemas[schemaName];
64
+ const newSchema = schemaCallback(schema);
65
+ schemas[schemaName] = newSchema;
66
+ }
67
+ }
68
+ }
69
+ return node;
70
+ };
71
+ return walkObject(node, objectVisitor);
72
+ }
73
+
74
+ /**
75
+ * Walk a JSON object and apply `refCallback` when a JSON `{$ref: url }` is
76
+ * found
77
+ *
78
+ * @param node A node in the OpenAPI document
79
+ * @param refCallback The function to call on JSON `$ref` objects
80
+ * @returns The modified (annotated) node
81
+ */
82
+ export function visitRefObjects(node: any, refCallback: RefVisitor): any {
83
+ const objectVisitor = (node: object): JsonNode => {
84
+ if (isRef(node)) {
85
+ return refCallback(node as RefObject);
86
+ }
87
+ return node;
88
+ };
89
+ return walkObject(node, objectVisitor);
90
+ }
91
+
92
+ /**
93
+ * Walk a JSON object or array and apply objectCallback when a JSON object is
94
+ * found
95
+ *
96
+ * @param node A node in the OpenAPI document
97
+ * @param objectCallback The function to call on JSON objects
98
+ * @param nav Tracks where we are in the original document
99
+ * @returns The modified (annotated) node
100
+ */
101
+ export function walkObject(
102
+ node: object,
103
+ objectCallback: ObjectVisitor,
104
+ ): JsonNode {
105
+ return walkObj(node);
106
+
107
+ function walkObj(node: any): JsonNode {
108
+ const object = objectCallback(node);
109
+ if (object !== null && typeof object === "object") {
110
+ const keys = [...Object.keys(node)]; // make copy since this code may re-enter objects
111
+ for (const key of keys) {
112
+ const val = node[key];
113
+ if (Array.isArray(val)) {
114
+ node[key] = walkArray(val as []);
115
+ } else if (val !== null && typeof val === "object") {
116
+ node[key] = walkObj(val);
117
+ }
118
+ }
119
+ }
120
+ return object;
121
+ }
122
+
123
+ function walkArray(array: JsonNode[]): JsonNode[] {
124
+ for (let index = 0; index < array.length; index += 1) {
125
+ const val = array[index] as JsonNode;
126
+ if (val !== null && typeof val === "object") {
127
+ array[index] = walkObj(val) as object;
128
+ } else if (Array.isArray(val)) {
129
+ array[index] = walkArray(val as JsonNode[]) as [];
130
+ }
131
+ }
132
+ return array;
133
+ }
134
+ }