@mintlify/validation 0.1.492 → 0.1.494
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/dist/openapi/v2/mapExample.d.ts +8 -0
- package/dist/openapi/v2/mapExample.js +20 -0
- package/dist/openapi/v2/mapExampleComponents.d.ts +8 -0
- package/dist/openapi/v2/mapExampleComponents.js +15 -0
- package/dist/openapi/v2/mapHeader.d.ts +8 -0
- package/dist/openapi/v2/mapHeader.js +57 -0
- package/dist/openapi/v2/mapHeaderComponents.d.ts +8 -0
- package/dist/openapi/v2/mapHeaderComponents.js +13 -0
- package/dist/openapi/v2/mapMedia.d.ts +8 -0
- package/dist/openapi/v2/mapMedia.js +36 -0
- package/dist/openapi/v2/mapParameter.d.ts +8 -0
- package/dist/openapi/v2/mapParameter.js +53 -0
- package/dist/openapi/v2/mapParameterComponents.d.ts +8 -0
- package/dist/openapi/v2/mapParameterComponents.js +20 -0
- package/dist/openapi/v2/mapRequestBody.d.ts +8 -0
- package/dist/openapi/v2/mapRequestBody.js +31 -0
- package/dist/openapi/v2/mapRequestBodyComponents.d.ts +8 -0
- package/dist/openapi/v2/mapRequestBodyComponents.js +15 -0
- package/dist/openapi/v2/mapResponseComponents.d.ts +8 -0
- package/dist/openapi/v2/mapResponseComponents.js +51 -0
- package/dist/openapi/v2/mapSchema.d.ts +8 -0
- package/dist/openapi/v2/mapSchema.js +15 -0
- package/dist/openapi/v2/mapSchemaComponents.d.ts +8 -0
- package/dist/openapi/v2/mapSchemaComponents.js +22 -0
- package/dist/openapi/v2/mapSecuritySchemeComponents.d.ts +8 -0
- package/dist/openapi/v2/mapSecuritySchemeComponents.js +20 -0
- package/dist/openapi/v2/openApiToSchemaGraph.js +16 -2
- package/dist/openapi/v2/replaceSchemaRefs.d.ts +5 -0
- package/dist/openapi/v2/replaceSchemaRefs.js +34 -0
- package/dist/openapi/v2/types/index.d.ts +55 -44
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExampleOrRefObject, RefUuidMap, UUIDObjectHashMap, HashedNodeMap, UUID } from './types/index.js';
|
|
2
|
+
export declare const mapExample: ({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
|
|
3
|
+
example: ExampleOrRefObject;
|
|
4
|
+
refUuidMap: RefUuidMap;
|
|
5
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
6
|
+
hashedNodeMap: HashedNodeMap;
|
|
7
|
+
uuid: UUID;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
export const mapExample = ({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
|
|
4
|
+
const objectHash = hash(example);
|
|
5
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
6
|
+
// if we've seen this exact object before, skip processing
|
|
7
|
+
if (objectHash in hashedNodeMap) {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
example = objectHash;
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// if ref, replace with uuid
|
|
13
|
+
if ('$ref' in example) {
|
|
14
|
+
const refId = example.$ref;
|
|
15
|
+
const refUuid = refUuidMap[refId] || uuidv4();
|
|
16
|
+
example.$ref = refUuid;
|
|
17
|
+
}
|
|
18
|
+
// add to hashedNodeMap
|
|
19
|
+
hashedNodeMap[objectHash] = example;
|
|
20
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { HashedNodeMap, RefUuidMap, UUIDObjectHashMap } from './types/index.js';
|
|
3
|
+
export declare const mapExampleComponents: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }: {
|
|
4
|
+
spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
5
|
+
refUuidMap: RefUuidMap;
|
|
6
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
7
|
+
hashedNodeMap: HashedNodeMap;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import { mapExample } from './mapExample.js';
|
|
3
|
+
export const mapExampleComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const exampleComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.examples;
|
|
6
|
+
if (!exampleComponents)
|
|
7
|
+
return;
|
|
8
|
+
// for each example component
|
|
9
|
+
Object.entries(exampleComponents).forEach(([exampleName, example]) => {
|
|
10
|
+
// match the refId to uuid
|
|
11
|
+
const refId = `#/components/examples/${exampleName}`;
|
|
12
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
13
|
+
mapExample({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HashedNodeMap, HeaderOrRefObject, RefUuidMap, UUIDObjectHashMap, UUID } from './types/index.js';
|
|
2
|
+
export declare const mapHeader: ({ header, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
|
|
3
|
+
header: HeaderOrRefObject;
|
|
4
|
+
refUuidMap: RefUuidMap;
|
|
5
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
6
|
+
hashedNodeMap: HashedNodeMap;
|
|
7
|
+
uuid: UUID;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { mapExample } from './mapExample.js';
|
|
4
|
+
import { mapMedia } from './mapMedia.js';
|
|
5
|
+
import { mapSchema } from './mapSchema.js';
|
|
6
|
+
export const mapHeader = ({ header, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
|
|
7
|
+
// hash the raw object
|
|
8
|
+
const objectHash = hash(header);
|
|
9
|
+
// map uuid and hash to uuidObjectHashMap
|
|
10
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
11
|
+
// if ref, replace with uuid
|
|
12
|
+
if ('$ref' in header) {
|
|
13
|
+
const refId = header.$ref;
|
|
14
|
+
const refUuid = refUuidMap[refId] || uuidv4();
|
|
15
|
+
header.$ref = refUuid;
|
|
16
|
+
}
|
|
17
|
+
// if not ref
|
|
18
|
+
// if schema in header, create SchemaOrRef node
|
|
19
|
+
if ('schema' in header && header.schema && typeof header.schema === 'object') {
|
|
20
|
+
const uuid = uuidv4();
|
|
21
|
+
mapSchema({
|
|
22
|
+
schema: header.schema,
|
|
23
|
+
refUuidMap,
|
|
24
|
+
uuidObjectHashMap,
|
|
25
|
+
hashedNodeMap,
|
|
26
|
+
uuid,
|
|
27
|
+
});
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
header.schema = uuid;
|
|
30
|
+
}
|
|
31
|
+
// if examples in header, create ExampleOrRef node
|
|
32
|
+
if ('examples' in header && header.examples && typeof header.examples === 'object') {
|
|
33
|
+
Object.entries(header.examples).forEach(([exampleName, example]) => {
|
|
34
|
+
const uuid = uuidv4();
|
|
35
|
+
mapExample({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
36
|
+
if (header.examples) {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
header.examples[exampleName] = uuid;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// if content in header, create Media node
|
|
43
|
+
if ('content' in header && header.content && typeof header.content === 'object') {
|
|
44
|
+
Object.entries(header.content).forEach(([contentType, content]) => {
|
|
45
|
+
const uuid = uuidv4();
|
|
46
|
+
mapMedia({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
47
|
+
if (header.content) {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
header.content[contentType] = uuid;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// if encoding in header, create Encoding node
|
|
54
|
+
// TODO: add support for encoding
|
|
55
|
+
// add to hashedNodeMap
|
|
56
|
+
hashedNodeMap[objectHash] = header;
|
|
57
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { HashedNodeMap, RefUuidMap, UUIDObjectHashMap } from './types/index.js';
|
|
3
|
+
export declare const mapHeaderComponents: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }: {
|
|
4
|
+
spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
5
|
+
refUuidMap: RefUuidMap;
|
|
6
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
7
|
+
hashedNodeMap: HashedNodeMap;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import { mapHeader } from './mapHeader.js';
|
|
3
|
+
export const mapHeaderComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const headerComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.headers;
|
|
6
|
+
if (!headerComponents)
|
|
7
|
+
return;
|
|
8
|
+
Object.entries(headerComponents).forEach(([headerName, header]) => {
|
|
9
|
+
const refId = `#/components/headers/${headerName}`;
|
|
10
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
11
|
+
mapHeader({ header, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HashedNodeMap, MediaObject, RefUuidMap, UUIDObjectHashMap, UUID } from './types/index.js';
|
|
2
|
+
export declare const mapMedia: ({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
|
|
3
|
+
content: MediaObject;
|
|
4
|
+
refUuidMap: RefUuidMap;
|
|
5
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
6
|
+
hashedNodeMap: HashedNodeMap;
|
|
7
|
+
uuid: UUID;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { mapExample } from './mapExample.js';
|
|
4
|
+
import { mapSchema } from './mapSchema.js';
|
|
5
|
+
export const mapMedia = ({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
|
|
6
|
+
const objectHash = hash(content);
|
|
7
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
8
|
+
// if we've seen this exact object before, skip processing
|
|
9
|
+
if (objectHash in hashedNodeMap) {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
content = objectHash;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// if schema in media, create SchemaOrRef node
|
|
15
|
+
if ('schema' in content && content.schema && typeof content.schema === 'object') {
|
|
16
|
+
const uuid = uuidv4();
|
|
17
|
+
mapSchema({ schema: content.schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
content.schema = uuid;
|
|
20
|
+
}
|
|
21
|
+
// if examples in media, create ExampleOrRef node
|
|
22
|
+
if ('examples' in content && content.examples && typeof content.examples === 'object') {
|
|
23
|
+
Object.entries(content.examples).forEach(([exampleName, example]) => {
|
|
24
|
+
const uuid = uuidv4();
|
|
25
|
+
mapExample({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
26
|
+
if (content.examples) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
content.examples[exampleName] = uuid;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// if encoding in media, create Encoding node
|
|
33
|
+
// TODO: add support for encoding
|
|
34
|
+
// add to hashedNodeMap
|
|
35
|
+
hashedNodeMap[objectHash] = content;
|
|
36
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HashedNodeMap, ParameterOrRefObject, RefUuidMap, UUID, UUIDObjectHashMap } from './types/index.js';
|
|
2
|
+
export declare const mapParameter: ({ parameter, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
|
|
3
|
+
parameter: ParameterOrRefObject;
|
|
4
|
+
refUuidMap: RefUuidMap;
|
|
5
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
6
|
+
hashedNodeMap: HashedNodeMap;
|
|
7
|
+
uuid: UUID;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { mapExample } from './mapExample.js';
|
|
4
|
+
import { mapMedia } from './mapMedia.js';
|
|
5
|
+
import { mapSchema } from './mapSchema.js';
|
|
6
|
+
export const mapParameter = ({ parameter, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
|
|
7
|
+
const objectHash = hash(parameter);
|
|
8
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
9
|
+
// if we've seen this exact object before, skip processing
|
|
10
|
+
if (objectHash in hashedNodeMap) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
parameter = objectHash;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// if ref, replace with uuid
|
|
16
|
+
if ('$ref' in parameter) {
|
|
17
|
+
const refId = parameter.$ref;
|
|
18
|
+
const refUuid = refUuidMap[refId] || uuidv4();
|
|
19
|
+
parameter.$ref = refUuid;
|
|
20
|
+
}
|
|
21
|
+
// if not ref
|
|
22
|
+
// if schema in parameter, create SchemaOrRef node
|
|
23
|
+
if ('schema' in parameter && parameter.schema && typeof parameter.schema === 'object') {
|
|
24
|
+
const uuid = uuidv4();
|
|
25
|
+
mapSchema({ schema: parameter.schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
parameter.schema = uuid;
|
|
28
|
+
}
|
|
29
|
+
// if examples in parameter, create ExampleOrRef node
|
|
30
|
+
if ('examples' in parameter && parameter.examples && typeof parameter.examples === 'object') {
|
|
31
|
+
Object.entries(parameter.examples).forEach(([exampleName, example]) => {
|
|
32
|
+
const uuid = uuidv4();
|
|
33
|
+
mapExample({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
34
|
+
if (parameter.examples) {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
parameter.examples[exampleName] = uuid;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// if content in parameter, create Media node
|
|
41
|
+
if ('content' in parameter && parameter.content && typeof parameter.content === 'object') {
|
|
42
|
+
Object.entries(parameter.content).forEach(([contentType, content]) => {
|
|
43
|
+
const uuid = uuidv4();
|
|
44
|
+
mapMedia({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
45
|
+
if (parameter.content) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
parameter.content[contentType] = uuid;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// add to hashedNodeMap
|
|
52
|
+
hashedNodeMap[objectHash] = parameter;
|
|
53
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { RefUuidMap, UUIDObjectHashMap, HashedNodeMap } from './types/index.js';
|
|
3
|
+
export declare const mapParameterComponents: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }: {
|
|
4
|
+
spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
5
|
+
refUuidMap: RefUuidMap;
|
|
6
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
7
|
+
hashedNodeMap: HashedNodeMap;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { mapParameter } from './mapParameter.js';
|
|
4
|
+
export const mapParameterComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
|
|
5
|
+
var _a;
|
|
6
|
+
const parameterComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.parameters;
|
|
7
|
+
if (!parameterComponents)
|
|
8
|
+
return;
|
|
9
|
+
// for each parameter component
|
|
10
|
+
Object.entries(parameterComponents).forEach(([parameterName, parameter]) => {
|
|
11
|
+
// match the refId to uuid
|
|
12
|
+
const refId = `#/components/parameters/${parameterName}`;
|
|
13
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
14
|
+
// hash the raw object
|
|
15
|
+
const objectHash = hash(parameter);
|
|
16
|
+
// map uuid and hash to uuidObjectHashMap
|
|
17
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
18
|
+
mapParameter({ parameter, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HashedNodeMap, RequestBodyOrRef, RefUuidMap, UUID, UUIDObjectHashMap } from './types/index.js';
|
|
2
|
+
export declare const mapRequestBody: ({ requestBody, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
|
|
3
|
+
requestBody: RequestBodyOrRef;
|
|
4
|
+
refUuidMap: RefUuidMap;
|
|
5
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
6
|
+
hashedNodeMap: HashedNodeMap;
|
|
7
|
+
uuid: UUID;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { mapMedia } from './mapMedia.js';
|
|
4
|
+
export const mapRequestBody = ({ requestBody, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
|
|
5
|
+
// hash the raw object
|
|
6
|
+
const objectHash = hash(requestBody);
|
|
7
|
+
// map uuid and hash to uuidObjectHashMap
|
|
8
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
9
|
+
// if we've seen this exact object before, skip processing
|
|
10
|
+
if (objectHash in hashedNodeMap) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
requestBody = objectHash;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// if ref, replace with uuid
|
|
16
|
+
if ('$ref' in requestBody) {
|
|
17
|
+
const refId = requestBody.$ref;
|
|
18
|
+
const refUuid = refUuidMap[refId] || uuidv4();
|
|
19
|
+
requestBody.$ref = refUuid;
|
|
20
|
+
}
|
|
21
|
+
// for each content in request body, create Media node
|
|
22
|
+
if ('content' in requestBody) {
|
|
23
|
+
Object.entries(requestBody.content).forEach(([contentType, content]) => {
|
|
24
|
+
const uuid = uuidv4();
|
|
25
|
+
mapMedia({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
26
|
+
requestBody.content[contentType] = uuid;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// add to hashedNodeMap
|
|
30
|
+
hashedNodeMap[objectHash] = requestBody;
|
|
31
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { HashedNodeMap, RefUuidMap, UUIDObjectHashMap } from './types/index.js';
|
|
3
|
+
export declare const mapRequestBodyComponents: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }: {
|
|
4
|
+
spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
5
|
+
refUuidMap: RefUuidMap;
|
|
6
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
7
|
+
hashedNodeMap: HashedNodeMap;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import { mapRequestBody } from './mapRequestBody.js';
|
|
3
|
+
export const mapRequestBodyComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const requestBodyComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.requestBodies;
|
|
6
|
+
if (!requestBodyComponents)
|
|
7
|
+
return;
|
|
8
|
+
// for each request body component
|
|
9
|
+
Object.entries(requestBodyComponents).forEach(([requestBodyName, requestBody]) => {
|
|
10
|
+
// match the refId to uuid
|
|
11
|
+
const refId = `#/components/requestBodies/${requestBodyName}`;
|
|
12
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
13
|
+
mapRequestBody({ requestBody, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { RefUuidMap, UUIDObjectHashMap, HashedNodeMap } from './types/index.js';
|
|
3
|
+
export declare const mapResponseComponents: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }: {
|
|
4
|
+
spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
5
|
+
refUuidMap: RefUuidMap;
|
|
6
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
7
|
+
hashedNodeMap: HashedNodeMap;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { mapHeader } from './mapHeader.js';
|
|
4
|
+
import { mapMedia } from './mapMedia.js';
|
|
5
|
+
export const mapResponseComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const responseComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.responses;
|
|
8
|
+
if (!responseComponents)
|
|
9
|
+
return;
|
|
10
|
+
// for each response component
|
|
11
|
+
Object.entries(responseComponents).forEach(([responseName, response]) => {
|
|
12
|
+
// match the refId to uuid
|
|
13
|
+
const refId = `#/components/responses/${responseName}`;
|
|
14
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
15
|
+
// hash the raw object
|
|
16
|
+
const objectHash = hash(response);
|
|
17
|
+
// map uuid and hash to uuidObjectHashMap
|
|
18
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
19
|
+
// if ref, replace with uuid
|
|
20
|
+
if ('$ref' in response) {
|
|
21
|
+
const refId = response.$ref;
|
|
22
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
23
|
+
response.$ref = uuid;
|
|
24
|
+
}
|
|
25
|
+
// if not ref
|
|
26
|
+
// if headers, convert headers to HeaderOrRef nodes
|
|
27
|
+
if ('headers' in response && response.headers && typeof response.headers === 'object') {
|
|
28
|
+
Object.entries(response.headers).forEach(([headerName, header]) => {
|
|
29
|
+
const uuid = uuidv4();
|
|
30
|
+
mapHeader({ header, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
31
|
+
if (response.headers) {
|
|
32
|
+
response.headers[headerName] = uuid;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// if content, convert content to Media nodes
|
|
37
|
+
if ('content' in response && response.content && typeof response.content === 'object') {
|
|
38
|
+
Object.entries(response.content).forEach(([contentType, content]) => {
|
|
39
|
+
const uuid = uuidv4();
|
|
40
|
+
mapMedia({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
|
|
41
|
+
if (response.content) {
|
|
42
|
+
response.content[contentType] = uuid;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// if links, convert links to Link nodes
|
|
47
|
+
// TODO: add support for links
|
|
48
|
+
// add to hashedNodeMap
|
|
49
|
+
hashedNodeMap[objectHash] = response;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SchemaOrRefObject, RefUuidMap, UUIDObjectHashMap, HashedNodeMap, UUID } from './types/index.js';
|
|
2
|
+
export declare const mapSchema: ({ schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
|
|
3
|
+
schema: SchemaOrRefObject;
|
|
4
|
+
refUuidMap: RefUuidMap;
|
|
5
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
6
|
+
hashedNodeMap: HashedNodeMap;
|
|
7
|
+
uuid: UUID;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { replaceSchemaRefs } from './replaceSchemaRefs.js';
|
|
3
|
+
export const mapSchema = ({ schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
|
|
4
|
+
const objectHash = hash(schema);
|
|
5
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
6
|
+
// if objectHash already exists, replace with hash ref
|
|
7
|
+
if (objectHash in hashedNodeMap) {
|
|
8
|
+
// if we found a duplicate hash we can assume the schema has already been processed to remove refs, so we can quit here and don't need to process it again or add a new entry
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
schema = objectHash;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
replaceSchemaRefs({ schema, refUuidMap });
|
|
14
|
+
hashedNodeMap[objectHash] = schema;
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { RefUuidMap, UUIDObjectHashMap, HashedNodeMap } from './types/index.js';
|
|
3
|
+
export declare const mapSchemaComponents: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }: {
|
|
4
|
+
spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
5
|
+
refUuidMap: RefUuidMap;
|
|
6
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
7
|
+
hashedNodeMap: HashedNodeMap;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { replaceSchemaRefs } from './replaceSchemaRefs.js';
|
|
4
|
+
export const mapSchemaComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
|
|
5
|
+
var _a;
|
|
6
|
+
const schemaComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
7
|
+
if (!schemaComponents)
|
|
8
|
+
return;
|
|
9
|
+
Object.entries(schemaComponents).forEach(([schemaName, schema]) => {
|
|
10
|
+
// match the refId to uuid
|
|
11
|
+
const refId = `#/components/schemas/${schemaName}`;
|
|
12
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
13
|
+
// hash the raw object
|
|
14
|
+
const objectHash = hash(schema);
|
|
15
|
+
// map uuid and hash to uuidObjectHashMap
|
|
16
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
17
|
+
// replace refs in schema nodes with uuids
|
|
18
|
+
replaceSchemaRefs({ schema, refUuidMap });
|
|
19
|
+
// add to hashedNodeMap
|
|
20
|
+
hashedNodeMap[objectHash] = schema;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { RefUuidMap, UUIDObjectHashMap, HashedNodeMap } from './types/index.js';
|
|
3
|
+
export declare const mapSecuritySchemeComponents: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }: {
|
|
4
|
+
spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
|
|
5
|
+
refUuidMap: RefUuidMap;
|
|
6
|
+
uuidObjectHashMap: UUIDObjectHashMap;
|
|
7
|
+
hashedNodeMap: HashedNodeMap;
|
|
8
|
+
}) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
export const mapSecuritySchemeComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const securitySchemeComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
|
|
6
|
+
if (!securitySchemeComponents)
|
|
7
|
+
return;
|
|
8
|
+
Object.entries(securitySchemeComponents).forEach(([securitySchemeName, securityScheme]) => {
|
|
9
|
+
const refId = `#/components/securitySchemes/${securitySchemeName}`;
|
|
10
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
11
|
+
const objectHash = hash(securityScheme);
|
|
12
|
+
uuidObjectHashMap[uuid] = objectHash;
|
|
13
|
+
if ('$ref' in securityScheme) {
|
|
14
|
+
const refId = securityScheme.$ref;
|
|
15
|
+
const refUuid = refUuidMap[refId] || uuidv4();
|
|
16
|
+
securityScheme.$ref = refUuid;
|
|
17
|
+
}
|
|
18
|
+
hashedNodeMap[objectHash] = securityScheme;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { buildRefUuidMap } from './buildRefUuidMap.js';
|
|
2
|
+
import { mapExampleComponents } from './mapExampleComponents.js';
|
|
3
|
+
import { mapHeaderComponents } from './mapHeaderComponents.js';
|
|
4
|
+
import { mapParameterComponents } from './mapParameterComponents.js';
|
|
5
|
+
import { mapRequestBodyComponents } from './mapRequestBodyComponents.js';
|
|
6
|
+
import { mapResponseComponents } from './mapResponseComponents.js';
|
|
7
|
+
import { mapSchemaComponents } from './mapSchemaComponents.js';
|
|
8
|
+
import { mapSecuritySchemeComponents } from './mapSecuritySchemeComponents.js';
|
|
2
9
|
export const openApiToSchemaGraph = ({ spec, filename, originalFileLocation, }) => {
|
|
3
10
|
// build map of component refs -> uuids
|
|
4
11
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
@@ -16,12 +23,19 @@ export const openApiToSchemaGraph = ({ spec, filename, originalFileLocation, })
|
|
|
16
23
|
// add to uuid and object hash maps
|
|
17
24
|
// (starting with the components section, which already have uuids in refUuidMap)
|
|
18
25
|
// document.components.schemas -> Schema
|
|
19
|
-
|
|
26
|
+
mapSchemaComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
|
|
27
|
+
// document.components.responses -> Response, possibly Header, Schema, Example, Media, Encoding
|
|
28
|
+
mapResponseComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
|
|
20
29
|
// document.components.parameters -> Parameter, possibly Schema, Example, Media, Encoding
|
|
30
|
+
mapParameterComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
|
|
21
31
|
// document.components.examples -> Example
|
|
32
|
+
mapExampleComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
|
|
22
33
|
// document.components.requestBodies -> RequestBody, possibly Media, Schema, Example, Encoding
|
|
23
|
-
|
|
34
|
+
mapRequestBodyComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
|
|
35
|
+
// document.components.headers -> Header, possibly Schema, Example, Media, Encoding
|
|
36
|
+
mapHeaderComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
|
|
24
37
|
// document.components.securitySchemes -> SecurityScheme
|
|
38
|
+
mapSecuritySchemeComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
|
|
25
39
|
// document.components.links -> TODO (unsupported)
|
|
26
40
|
// document.components.callbacks -> TODO (unsupported)
|
|
27
41
|
// document.components.pathItems -> TODO (unsupported)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
export const replaceSchemaRefs = ({ schema, refUuidMap, }) => {
|
|
3
|
+
if ('$ref' in schema) {
|
|
4
|
+
const refId = schema.$ref;
|
|
5
|
+
const uuid = refUuidMap[refId] || uuidv4();
|
|
6
|
+
schema.$ref = uuid;
|
|
7
|
+
}
|
|
8
|
+
if ('properties' in schema && schema.properties && typeof schema.properties === 'object') {
|
|
9
|
+
Object.values(schema.properties).forEach((subschema) => {
|
|
10
|
+
replaceSchemaRefs({ schema: subschema, refUuidMap });
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if ('items' in schema && schema.items && typeof schema.items === 'object') {
|
|
14
|
+
replaceSchemaRefs({ schema: schema.items, refUuidMap });
|
|
15
|
+
}
|
|
16
|
+
if ('oneOf' in schema && schema.oneOf && Array.isArray(schema.oneOf)) {
|
|
17
|
+
schema.oneOf.forEach((subschema) => {
|
|
18
|
+
replaceSchemaRefs({ schema: subschema, refUuidMap });
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if ('anyOf' in schema && schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
22
|
+
schema.anyOf.forEach((subschema) => {
|
|
23
|
+
replaceSchemaRefs({ schema: subschema, refUuidMap });
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if ('allOf' in schema && schema.allOf && Array.isArray(schema.allOf)) {
|
|
27
|
+
schema.allOf.forEach((subschema) => {
|
|
28
|
+
replaceSchemaRefs({ schema: subschema, refUuidMap });
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if ('not' in schema && schema.not && typeof schema.not === 'object') {
|
|
32
|
+
replaceSchemaRefs({ schema: schema.not, refUuidMap });
|
|
33
|
+
}
|
|
34
|
+
};
|