@mintlify/validation 0.1.493 → 0.1.495

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.
Files changed (43) hide show
  1. package/dist/openapi/v2/getObjectById.d.ts +6 -0
  2. package/dist/openapi/v2/getObjectById.js +5 -0
  3. package/dist/openapi/v2/mapDocument.d.ts +8 -0
  4. package/dist/openapi/v2/mapDocument.js +11 -0
  5. package/dist/openapi/v2/mapExample.js +1 -1
  6. package/dist/openapi/v2/mapExampleComponents.d.ts +8 -0
  7. package/dist/openapi/v2/mapExampleComponents.js +15 -0
  8. package/dist/openapi/v2/mapHeader.js +1 -1
  9. package/dist/openapi/v2/mapHeaderComponents.d.ts +8 -0
  10. package/dist/openapi/v2/mapHeaderComponents.js +13 -0
  11. package/dist/openapi/v2/mapOperation.d.ts +8 -0
  12. package/dist/openapi/v2/mapOperation.js +73 -0
  13. package/dist/openapi/v2/mapParameter.d.ts +8 -0
  14. package/dist/openapi/v2/mapParameter.js +53 -0
  15. package/dist/openapi/v2/mapParameterComponents.d.ts +8 -0
  16. package/dist/openapi/v2/mapParameterComponents.js +20 -0
  17. package/dist/openapi/v2/mapPath.d.ts +8 -0
  18. package/dist/openapi/v2/mapPath.js +42 -0
  19. package/dist/openapi/v2/mapPathComponents.d.ts +8 -0
  20. package/dist/openapi/v2/mapPathComponents.js +14 -0
  21. package/dist/openapi/v2/mapPaths.d.ts +9 -0
  22. package/dist/openapi/v2/mapPaths.js +21 -0
  23. package/dist/openapi/v2/mapRequestBody.d.ts +8 -0
  24. package/dist/openapi/v2/mapRequestBody.js +32 -0
  25. package/dist/openapi/v2/mapRequestBodyComponents.d.ts +8 -0
  26. package/dist/openapi/v2/mapRequestBodyComponents.js +15 -0
  27. package/dist/openapi/v2/mapResponse.d.ts +8 -0
  28. package/dist/openapi/v2/mapResponse.js +43 -0
  29. package/dist/openapi/v2/mapResponseComponents.js +2 -38
  30. package/dist/openapi/v2/mapSecurityRequirement.d.ts +8 -0
  31. package/dist/openapi/v2/mapSecurityRequirement.js +19 -0
  32. package/dist/openapi/v2/mapSecurityRequirements.d.ts +9 -0
  33. package/dist/openapi/v2/mapSecurityRequirements.js +30 -0
  34. package/dist/openapi/v2/mapSecuritySchemeComponents.d.ts +8 -0
  35. package/dist/openapi/v2/mapSecuritySchemeComponents.js +20 -0
  36. package/dist/openapi/v2/mapServers.d.ts +8 -0
  37. package/dist/openapi/v2/mapServers.js +18 -0
  38. package/dist/openapi/v2/mapWebhooks.d.ts +9 -0
  39. package/dist/openapi/v2/mapWebhooks.js +21 -0
  40. package/dist/openapi/v2/openApiToSchemaGraph.js +28 -6
  41. package/dist/openapi/v2/types/index.d.ts +67 -12
  42. package/dist/tsconfig.build.tsbuildinfo +1 -1
  43. package/package.json +2 -2
@@ -0,0 +1,6 @@
1
+ import { GraphNode, HashedNodeMap, UUID, UUIDObjectHashMap } from './types/index.js';
2
+ export declare const getObjectById: <T extends GraphNode>({ uuidObjectHashMap, hashedNodeMap, id, }: {
3
+ uuidObjectHashMap: UUIDObjectHashMap;
4
+ hashedNodeMap: HashedNodeMap;
5
+ id?: UUID;
6
+ }) => T | undefined;
@@ -0,0 +1,5 @@
1
+ export const getObjectById = ({ uuidObjectHashMap, hashedNodeMap, id, }) => {
2
+ if (!id || !uuidObjectHashMap[id])
3
+ return undefined;
4
+ return hashedNodeMap[uuidObjectHashMap[id]];
5
+ };
@@ -0,0 +1,8 @@
1
+ import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
2
+ import { UUIDObjectHashMap, HashedNodeMap, UUID } from './types/index.js';
3
+ export declare const mapDocument: ({ spec, uuidObjectHashMap, hashedNodeMap, uuid, }: {
4
+ spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
5
+ uuidObjectHashMap: UUIDObjectHashMap;
6
+ hashedNodeMap: HashedNodeMap;
7
+ uuid: UUID;
8
+ }) => void;
@@ -0,0 +1,11 @@
1
+ import hash from 'object-hash';
2
+ export const mapDocument = ({ spec, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
3
+ const documentNode = Object.assign(Object.assign(Object.assign(Object.assign({ openapi: spec.openapi, info: spec.info, servers: [], paths: [], webhooks: [], security: [] }, (spec.tags && { tags: spec.tags })), (spec.externalDocs && { externalDocs: spec.externalDocs })), (spec['x-express-openapi-additional-middleware'] && {
4
+ 'x-express-openapi-additional-middleware': spec['x-express-openapi-additional-middleware'],
5
+ })), (spec['x-express-openapi-validation-strict'] && {
6
+ 'x-express-openapi-validation-strict': spec['x-express-openapi-validation-strict'],
7
+ }));
8
+ const objectHash = hash(documentNode);
9
+ uuidObjectHashMap[uuid] = objectHash;
10
+ hashedNodeMap[objectHash] = documentNode;
11
+ };
@@ -10,7 +10,7 @@ export const mapExample = ({ example, refUuidMap, uuidObjectHashMap, hashedNodeM
10
10
  return;
11
11
  }
12
12
  // if ref, replace with uuid
13
- if ('$ref' in example) {
13
+ if ('$ref' in example && example.$ref) {
14
14
  const refId = example.$ref;
15
15
  const refUuid = refUuidMap[refId] || uuidv4();
16
16
  example.$ref = refUuid;
@@ -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
+ };
@@ -9,7 +9,7 @@ export const mapHeader = ({ header, refUuidMap, uuidObjectHashMap, hashedNodeMap
9
9
  // map uuid and hash to uuidObjectHashMap
10
10
  uuidObjectHashMap[uuid] = objectHash;
11
11
  // if ref, replace with uuid
12
- if ('$ref' in header) {
12
+ if ('$ref' in header && header.$ref) {
13
13
  const refId = header.$ref;
14
14
  const refUuid = refUuidMap[refId] || uuidv4();
15
15
  header.$ref = refUuid;
@@ -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 { OperationObject, RefUuidMap, UUIDObjectHashMap, HashedNodeMap, UUID } from './types/index.js';
2
+ export declare const mapOperation: ({ operation, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
3
+ operation: OperationObject;
4
+ refUuidMap: RefUuidMap;
5
+ uuidObjectHashMap: UUIDObjectHashMap;
6
+ hashedNodeMap: HashedNodeMap;
7
+ uuid: UUID;
8
+ }) => void;
@@ -0,0 +1,73 @@
1
+ import hash from 'object-hash';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { mapParameter } from './mapParameter.js';
4
+ import { mapRequestBody } from './mapRequestBody.js';
5
+ import { mapResponse } from './mapResponse.js';
6
+ import { mapSecurityRequirement } from './mapSecurityRequirement.js';
7
+ export const mapOperation = ({ operation, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
8
+ var _a;
9
+ const objectHash = hash(operation);
10
+ uuidObjectHashMap[uuid] = objectHash;
11
+ // parameters
12
+ if ('parameters' in operation) {
13
+ const parameterUuids = [];
14
+ (_a = operation.parameters) === null || _a === void 0 ? void 0 : _a.forEach((parameter) => {
15
+ const uuid = uuidv4();
16
+ mapParameter({ parameter, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
17
+ parameterUuids.push(uuid);
18
+ });
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ operation.parameters = parameterUuids;
21
+ }
22
+ // requestBody
23
+ if ('requestBody' in operation && operation.requestBody !== undefined) {
24
+ const uuid = uuidv4();
25
+ mapRequestBody({
26
+ requestBody: operation.requestBody,
27
+ refUuidMap,
28
+ uuidObjectHashMap,
29
+ hashedNodeMap,
30
+ uuid,
31
+ });
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ operation.requestBody = uuid;
34
+ }
35
+ // responses
36
+ if ('responses' in operation && operation.responses) {
37
+ Object.entries(operation.responses).forEach(([statusCode, response]) => {
38
+ const uuid = uuidv4();
39
+ mapResponse({ response, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
40
+ if (operation.responses) {
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ operation.responses[statusCode] = uuid;
43
+ }
44
+ });
45
+ }
46
+ // callbacks (TODO: add support for callbacks)
47
+ // security
48
+ if ('security' in operation && operation.security) {
49
+ const securityUuids = [];
50
+ operation.security.forEach((security) => {
51
+ const uuid = uuidv4();
52
+ mapSecurityRequirement({ security, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
53
+ securityUuids.push(uuid);
54
+ });
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ operation.security = securityUuids;
57
+ }
58
+ // servers
59
+ if ('servers' in operation && operation.servers) {
60
+ const serverUuids = [];
61
+ operation.servers.forEach((server) => {
62
+ const uuid = uuidv4();
63
+ const objectHash = hash(server);
64
+ uuidObjectHashMap[uuid] = objectHash;
65
+ hashedNodeMap[objectHash] = server;
66
+ serverUuids.push(uuid);
67
+ });
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ operation.servers = serverUuids;
70
+ }
71
+ // add to hashedNodeMap
72
+ hashedNodeMap[objectHash] = operation;
73
+ };
@@ -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 && parameter.$ref) {
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 { RefUuidMap, UUIDObjectHashMap, HashedNodeMap, UUID, PathObjectOrRef } from './types/index.js';
2
+ export declare const mapPath: ({ pathItem, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
3
+ pathItem: PathObjectOrRef;
4
+ refUuidMap: RefUuidMap;
5
+ uuidObjectHashMap: UUIDObjectHashMap;
6
+ hashedNodeMap: HashedNodeMap;
7
+ uuid: UUID;
8
+ }) => void;
@@ -0,0 +1,42 @@
1
+ import hash from 'object-hash';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { httpMethods } from '../types/endpoint.js';
4
+ import { mapOperation } from './mapOperation.js';
5
+ import { mapParameter } from './mapParameter.js';
6
+ export const mapPath = ({ pathItem, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
7
+ var _a;
8
+ const objectHash = hash(pathItem);
9
+ uuidObjectHashMap[uuid] = objectHash;
10
+ if ('$ref' in pathItem && pathItem.$ref) {
11
+ const refId = pathItem.$ref;
12
+ const refUuid = refUuidMap[refId] || uuidv4();
13
+ pathItem.$ref = refUuid;
14
+ }
15
+ // process path - Parameters
16
+ if ('parameters' in pathItem) {
17
+ const parameterUuids = [];
18
+ (_a = pathItem.parameters) === null || _a === void 0 ? void 0 : _a.forEach((parameter) => {
19
+ const uuid = uuidv4();
20
+ mapParameter({ parameter, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
21
+ parameterUuids.push(uuid);
22
+ });
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ pathItem.parameters = parameterUuids;
25
+ }
26
+ // process operations per http method
27
+ if (!('$ref' in pathItem)) {
28
+ httpMethods.forEach((method) => {
29
+ if (!(method in pathItem))
30
+ return;
31
+ const operation = pathItem[method];
32
+ if (!operation)
33
+ return;
34
+ const uuid = uuidv4();
35
+ mapOperation({ operation, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ pathItem[method] = uuid;
38
+ });
39
+ }
40
+ // store path object
41
+ hashedNodeMap[objectHash] = pathItem;
42
+ };
@@ -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 mapPathComponents: ({ 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,14 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { mapPath } from './mapPath.js';
3
+ export const mapPathComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
4
+ if (!spec.components || !('pathItems' in spec.components))
5
+ return;
6
+ const pathComponents = spec.components.pathItems;
7
+ if (!pathComponents)
8
+ return;
9
+ Object.entries(pathComponents).forEach(([name, pathItem]) => {
10
+ const refId = `#/components/pathItems/${name}`;
11
+ const uuid = refUuidMap[refId] || uuidv4();
12
+ mapPath({ pathItem, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
13
+ });
14
+ };
@@ -0,0 +1,9 @@
1
+ import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
2
+ import { RefUuidMap, UUIDObjectHashMap, HashedNodeMap, UUID } from './types/index.js';
3
+ export declare const mapPaths: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId, }: {
4
+ spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
5
+ refUuidMap: RefUuidMap;
6
+ uuidObjectHashMap: UUIDObjectHashMap;
7
+ hashedNodeMap: HashedNodeMap;
8
+ documentId: UUID;
9
+ }) => void;
@@ -0,0 +1,21 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { getObjectById } from './getObjectById.js';
3
+ import { mapPath } from './mapPath.js';
4
+ export const mapPaths = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId, }) => {
5
+ const paths = spec.paths;
6
+ if (!paths)
7
+ return;
8
+ const document = getObjectById({ uuidObjectHashMap, hashedNodeMap, id: documentId });
9
+ if (!document)
10
+ return;
11
+ Object.entries(paths).forEach(([path, pathItem]) => {
12
+ if (!pathItem)
13
+ return;
14
+ // map to refUuidMap, uuidObjectHashMap, hashedNodeMap
15
+ const uuid = uuidv4();
16
+ refUuidMap[path] = uuid;
17
+ mapPath({ pathItem, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
18
+ // add path to document
19
+ document.paths.push(uuid);
20
+ });
21
+ };
@@ -0,0 +1,8 @@
1
+ import { HashedNodeMap, RequestBodyOrRefObject, RefUuidMap, UUID, UUIDObjectHashMap } from './types/index.js';
2
+ export declare const mapRequestBody: ({ requestBody, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
3
+ requestBody: RequestBodyOrRefObject;
4
+ refUuidMap: RefUuidMap;
5
+ uuidObjectHashMap: UUIDObjectHashMap;
6
+ hashedNodeMap: HashedNodeMap;
7
+ uuid: UUID;
8
+ }) => void;
@@ -0,0 +1,32 @@
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 && requestBody.$ref) {
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
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ requestBody.content[contentType] = uuid;
28
+ });
29
+ }
30
+ // add to hashedNodeMap
31
+ hashedNodeMap[objectHash] = requestBody;
32
+ };
@@ -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 { RefUuidMap, UUIDObjectHashMap, ResponseOrRefObject, HashedNodeMap, UUID } from './types/index.js';
2
+ export declare const mapResponse: ({ response, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
3
+ response: ResponseOrRefObject;
4
+ refUuidMap: RefUuidMap;
5
+ uuidObjectHashMap: UUIDObjectHashMap;
6
+ hashedNodeMap: HashedNodeMap;
7
+ uuid: UUID;
8
+ }) => void;
@@ -0,0 +1,43 @@
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 mapResponse = ({ response, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
6
+ // hash the raw object
7
+ const objectHash = hash(response);
8
+ // map uuid and hash to uuidObjectHashMap
9
+ uuidObjectHashMap[uuid] = objectHash;
10
+ // if ref, replace with uuid
11
+ if ('$ref' in response && response.$ref) {
12
+ const refId = response.$ref;
13
+ const uuid = refUuidMap[refId] || uuidv4();
14
+ response.$ref = uuid;
15
+ }
16
+ // if not ref
17
+ // if headers, convert headers to HeaderOrRef nodes
18
+ if ('headers' in response && response.headers && typeof response.headers === 'object') {
19
+ Object.entries(response.headers).forEach(([headerName, header]) => {
20
+ const uuid = uuidv4();
21
+ mapHeader({ header, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
22
+ if (response.headers) {
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ response.headers[headerName] = uuid;
25
+ }
26
+ });
27
+ }
28
+ // if content, convert content to Media nodes
29
+ if ('content' in response && response.content && typeof response.content === 'object') {
30
+ Object.entries(response.content).forEach(([contentType, content]) => {
31
+ const uuid = uuidv4();
32
+ mapMedia({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
33
+ if (response.content) {
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ response.content[contentType] = uuid;
36
+ }
37
+ });
38
+ }
39
+ // if links, convert links to Link nodes
40
+ // TODO: add support for links
41
+ // add to hashedNodeMap
42
+ hashedNodeMap[objectHash] = response;
43
+ };
@@ -1,7 +1,5 @@
1
- import hash from 'object-hash';
2
1
  import { v4 as uuidv4 } from 'uuid';
3
- import { mapHeader } from './mapHeader.js';
4
- import { mapMedia } from './mapMedia.js';
2
+ import { mapResponse } from './mapResponse.js';
5
3
  export const mapResponseComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => {
6
4
  var _a;
7
5
  const responseComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.responses;
@@ -12,40 +10,6 @@ export const mapResponseComponents = ({ spec, refUuidMap, uuidObjectHashMap, has
12
10
  // match the refId to uuid
13
11
  const refId = `#/components/responses/${responseName}`;
14
12
  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;
13
+ mapResponse({ response, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
50
14
  });
51
15
  };
@@ -0,0 +1,8 @@
1
+ import { RefUuidMap, SecurityRequirementObject, UUIDObjectHashMap, HashedNodeMap, UUID } from './types/index.js';
2
+ export declare const mapSecurityRequirement: ({ security, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
3
+ security: SecurityRequirementObject;
4
+ refUuidMap: RefUuidMap;
5
+ uuidObjectHashMap: UUIDObjectHashMap;
6
+ hashedNodeMap: HashedNodeMap;
7
+ uuid: UUID;
8
+ }) => void;
@@ -0,0 +1,19 @@
1
+ import hash from 'object-hash';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ export const mapSecurityRequirement = ({ security, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
4
+ const securityRequirementObject = {};
5
+ Object.entries(security).forEach(([securitySchemeName, securitySchemeScopes]) => {
6
+ // create security requirement object
7
+ // add $ref to matching security scheme from components.securitySchemes
8
+ // add scopes to the security requirement object
9
+ const refId = `#/components/securitySchemes/${securitySchemeName}`;
10
+ const refUuid = refUuidMap[refId] || uuidv4();
11
+ securityRequirementObject[securitySchemeName] = {
12
+ $ref: refUuid,
13
+ scopes: securitySchemeScopes,
14
+ };
15
+ });
16
+ const objectHash = hash(securityRequirementObject);
17
+ uuidObjectHashMap[uuid] = objectHash;
18
+ hashedNodeMap[objectHash] = securityRequirementObject;
19
+ };
@@ -0,0 +1,9 @@
1
+ import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
2
+ import { UUIDObjectHashMap, HashedNodeMap, UUID, RefUuidMap } from './types/index.js';
3
+ export declare const mapSecurityRequirements: ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId, }: {
4
+ spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
5
+ refUuidMap: RefUuidMap;
6
+ uuidObjectHashMap: UUIDObjectHashMap;
7
+ hashedNodeMap: HashedNodeMap;
8
+ documentId: UUID;
9
+ }) => void;
@@ -0,0 +1,30 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { getObjectById } from './getObjectById.js';
3
+ import { mapSecurityRequirement } from './mapSecurityRequirement.js';
4
+ export const mapSecurityRequirements = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId, }) => {
5
+ const securityRequirements = spec.security;
6
+ if (!securityRequirements)
7
+ return;
8
+ const document = getObjectById({ uuidObjectHashMap, hashedNodeMap, id: documentId });
9
+ if (!document)
10
+ return;
11
+ // security requirements object = security: [{}, { 'A': [], 'B': [scopes], 'C': [scopes] }]
12
+ // refmap = { '#/components/securitySchemes/A': uuid1, '#/components/securitySchemes/B': uuid2, '#/components/securitySchemes/C': uuid3 }
13
+ // document.security = [uuid4, uuid5]
14
+ // uuidObjectHashMap = { uuid4: hash1, uuid5: hash2 }
15
+ // { hash1: {} }
16
+ // { hash2: { 'A': { $ref: uuid1, scopes: [] }, 'B': { $ref: uuid2, scopes: [scopes] }, 'C': { $ref: uuid3, scopes: [scopes] } } } }
17
+ securityRequirements.forEach((securityRequirement) => {
18
+ // create uuid for each global security requirement
19
+ const uuid = uuidv4();
20
+ mapSecurityRequirement({
21
+ security: securityRequirement,
22
+ refUuidMap,
23
+ uuidObjectHashMap,
24
+ hashedNodeMap,
25
+ uuid,
26
+ });
27
+ // associate security requirement object with document
28
+ document.security.push(uuid);
29
+ });
30
+ };