@mintlify/validation 0.1.494 → 0.1.496

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 (34) hide show
  1. package/dist/mint-config/schemas/v2/properties/navigation/products.js +8 -0
  2. package/dist/openapi/v2/getObjectById.d.ts +6 -0
  3. package/dist/openapi/v2/getObjectById.js +5 -0
  4. package/dist/openapi/v2/mapDocument.d.ts +8 -0
  5. package/dist/openapi/v2/mapDocument.js +11 -0
  6. package/dist/openapi/v2/mapExample.js +1 -1
  7. package/dist/openapi/v2/mapHeader.js +1 -1
  8. package/dist/openapi/v2/mapOperation.d.ts +8 -0
  9. package/dist/openapi/v2/mapOperation.js +73 -0
  10. package/dist/openapi/v2/mapParameter.js +1 -1
  11. package/dist/openapi/v2/mapPath.d.ts +8 -0
  12. package/dist/openapi/v2/mapPath.js +42 -0
  13. package/dist/openapi/v2/mapPathComponents.d.ts +8 -0
  14. package/dist/openapi/v2/mapPathComponents.js +14 -0
  15. package/dist/openapi/v2/mapPaths.d.ts +9 -0
  16. package/dist/openapi/v2/mapPaths.js +21 -0
  17. package/dist/openapi/v2/mapRequestBody.d.ts +2 -2
  18. package/dist/openapi/v2/mapRequestBody.js +2 -1
  19. package/dist/openapi/v2/mapResponse.d.ts +8 -0
  20. package/dist/openapi/v2/mapResponse.js +43 -0
  21. package/dist/openapi/v2/mapResponseComponents.js +2 -38
  22. package/dist/openapi/v2/mapSecurityRequirement.d.ts +8 -0
  23. package/dist/openapi/v2/mapSecurityRequirement.js +19 -0
  24. package/dist/openapi/v2/mapSecurityRequirements.d.ts +9 -0
  25. package/dist/openapi/v2/mapSecurityRequirements.js +30 -0
  26. package/dist/openapi/v2/mapSecuritySchemeComponents.js +1 -1
  27. package/dist/openapi/v2/mapServers.d.ts +8 -0
  28. package/dist/openapi/v2/mapServers.js +18 -0
  29. package/dist/openapi/v2/mapWebhooks.d.ts +9 -0
  30. package/dist/openapi/v2/mapWebhooks.js +21 -0
  31. package/dist/openapi/v2/openApiToSchemaGraph.js +18 -6
  32. package/dist/openapi/v2/types/index.d.ts +64 -12
  33. package/dist/tsconfig.build.tsbuildinfo +1 -1
  34. package/package.json +2 -2
@@ -6,6 +6,7 @@ import { hrefSchema } from '../reusable/href.js';
6
6
  import { iconSchema } from '../reusable/icon.js';
7
7
  import { openApiSchema } from '../reusable/openapi.js';
8
8
  import { anchorsSchema, decoratedAnchorsSchema } from './anchors.js';
9
+ import { decoratedDropdownsSchema, dropdownsSchema } from './dropdown.js';
9
10
  import { globalSchema } from './global.js';
10
11
  import { groupsSchema, decoratedGroupsSchema } from './groups.js';
11
12
  import { languagesSchema, decoratedLanguagesSchema } from './languages.js';
@@ -51,6 +52,12 @@ export const productSchema = z.union([
51
52
  asyncapi: asyncApiSchema.optional(),
52
53
  global: z.lazy(() => globalSchema).optional(),
53
54
  }),
55
+ baseProductSchema.extend({
56
+ dropdowns: z.lazy(() => dropdownsSchema),
57
+ openapi: openApiSchema.optional(),
58
+ asyncapi: asyncApiSchema.optional(),
59
+ global: z.lazy(() => globalSchema).optional(),
60
+ }),
54
61
  baseProductSchema.extend({
55
62
  groups: z.lazy(() => groupsSchema),
56
63
  openapi: openApiSchema.optional(),
@@ -75,6 +82,7 @@ export const decoratedProductSchema = baseProductSchema.and(z.union([
75
82
  z.lazy(() => z.object({ versions: decoratedVersionsSchema, global: globalSchema.optional() })),
76
83
  z.lazy(() => z.object({ tabs: decoratedTabsSchema, global: globalSchema.optional() })),
77
84
  z.lazy(() => z.object({ anchors: decoratedAnchorsSchema, global: globalSchema.optional() })),
85
+ z.lazy(() => z.object({ dropdowns: decoratedDropdownsSchema, global: globalSchema.optional() })),
78
86
  z.lazy(() => z.object({ groups: decoratedGroupsSchema, global: globalSchema.optional() })),
79
87
  z.lazy(() => z.object({ pages: decoratedPagesSchema, global: globalSchema.optional() })),
80
88
  ]));
@@ -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;
@@ -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 { 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
+ };
@@ -13,7 +13,7 @@ export const mapParameter = ({ parameter, refUuidMap, uuidObjectHashMap, hashedN
13
13
  return;
14
14
  }
15
15
  // if ref, replace with uuid
16
- if ('$ref' in parameter) {
16
+ if ('$ref' in parameter && parameter.$ref) {
17
17
  const refId = parameter.$ref;
18
18
  const refUuid = refUuidMap[refId] || uuidv4();
19
19
  parameter.$ref = refUuid;
@@ -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
+ };
@@ -1,6 +1,6 @@
1
- import { HashedNodeMap, RequestBodyOrRef, RefUuidMap, UUID, UUIDObjectHashMap } from './types/index.js';
1
+ import { HashedNodeMap, RequestBodyOrRefObject, RefUuidMap, UUID, UUIDObjectHashMap } from './types/index.js';
2
2
  export declare const mapRequestBody: ({ requestBody, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }: {
3
- requestBody: RequestBodyOrRef;
3
+ requestBody: RequestBodyOrRefObject;
4
4
  refUuidMap: RefUuidMap;
5
5
  uuidObjectHashMap: UUIDObjectHashMap;
6
6
  hashedNodeMap: HashedNodeMap;
@@ -13,7 +13,7 @@ export const mapRequestBody = ({ requestBody, refUuidMap, uuidObjectHashMap, has
13
13
  return;
14
14
  }
15
15
  // if ref, replace with uuid
16
- if ('$ref' in requestBody) {
16
+ if ('$ref' in requestBody && requestBody.$ref) {
17
17
  const refId = requestBody.$ref;
18
18
  const refUuid = refUuidMap[refId] || uuidv4();
19
19
  requestBody.$ref = refUuid;
@@ -23,6 +23,7 @@ export const mapRequestBody = ({ requestBody, refUuidMap, uuidObjectHashMap, has
23
23
  Object.entries(requestBody.content).forEach(([contentType, content]) => {
24
24
  const uuid = uuidv4();
25
25
  mapMedia({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
27
  requestBody.content[contentType] = uuid;
27
28
  });
28
29
  }
@@ -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
+ };
@@ -10,7 +10,7 @@ export const mapSecuritySchemeComponents = ({ spec, refUuidMap, uuidObjectHashMa
10
10
  const uuid = refUuidMap[refId] || uuidv4();
11
11
  const objectHash = hash(securityScheme);
12
12
  uuidObjectHashMap[uuid] = objectHash;
13
- if ('$ref' in securityScheme) {
13
+ if ('$ref' in securityScheme && securityScheme.$ref) {
14
14
  const refId = securityScheme.$ref;
15
15
  const refUuid = refUuidMap[refId] || uuidv4();
16
16
  securityScheme.$ref = refUuid;
@@ -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 mapServers: ({ spec, uuidObjectHashMap, hashedNodeMap, documentId, }: {
4
+ spec: OpenAPIV3.Document | OpenAPIV3_1.Document;
5
+ uuidObjectHashMap: UUIDObjectHashMap;
6
+ hashedNodeMap: HashedNodeMap;
7
+ documentId: UUID;
8
+ }) => void;
@@ -0,0 +1,18 @@
1
+ import hash from 'object-hash';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { getObjectById } from './getObjectById.js';
4
+ export const mapServers = ({ spec, uuidObjectHashMap, hashedNodeMap, documentId, }) => {
5
+ const servers = spec.servers;
6
+ if (!servers)
7
+ return;
8
+ const document = getObjectById({ uuidObjectHashMap, hashedNodeMap, id: documentId });
9
+ if (!document)
10
+ return;
11
+ servers.forEach((server) => {
12
+ const uuid = uuidv4();
13
+ const objectHash = hash(server);
14
+ uuidObjectHashMap[uuid] = objectHash;
15
+ hashedNodeMap[objectHash] = server;
16
+ document.servers.push(uuid);
17
+ });
18
+ };
@@ -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 mapWebhooks: ({ 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 mapWebhooks = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId, }) => {
5
+ if (!('webhooks' in spec))
6
+ return;
7
+ const webhooks = spec.webhooks;
8
+ if (!webhooks)
9
+ return;
10
+ const document = getObjectById({ uuidObjectHashMap, hashedNodeMap, id: documentId });
11
+ if (!document)
12
+ return;
13
+ Object.entries(webhooks).forEach(([webhookPath, webhook]) => {
14
+ if (!webhook)
15
+ return;
16
+ const uuid = uuidv4();
17
+ refUuidMap[webhookPath] = uuid;
18
+ mapPath({ pathItem: webhook, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
19
+ document.webhooks.push(uuid);
20
+ });
21
+ };
@@ -1,17 +1,21 @@
1
+ import { v4 as uuidv4 } from 'uuid';
1
2
  import { buildRefUuidMap } from './buildRefUuidMap.js';
3
+ import { mapDocument } from './mapDocument.js';
2
4
  import { mapExampleComponents } from './mapExampleComponents.js';
3
5
  import { mapHeaderComponents } from './mapHeaderComponents.js';
4
6
  import { mapParameterComponents } from './mapParameterComponents.js';
7
+ import { mapPathComponents } from './mapPathComponents.js';
8
+ import { mapPaths } from './mapPaths.js';
5
9
  import { mapRequestBodyComponents } from './mapRequestBodyComponents.js';
6
10
  import { mapResponseComponents } from './mapResponseComponents.js';
7
11
  import { mapSchemaComponents } from './mapSchemaComponents.js';
12
+ import { mapSecurityRequirements } from './mapSecurityRequirements.js';
8
13
  import { mapSecuritySchemeComponents } from './mapSecuritySchemeComponents.js';
14
+ import { mapServers } from './mapServers.js';
15
+ import { mapWebhooks } from './mapWebhooks.js';
9
16
  export const openApiToSchemaGraph = ({ spec, filename, originalFileLocation, }) => {
10
17
  // build map of component refs -> uuids
11
- // eslint-disable-next-line unused-imports/no-unused-vars
12
18
  const refUuidMap = buildRefUuidMap(spec);
13
- // eslint-disable-next-line unused-imports/no-unused-vars
14
- const nodes = [];
15
19
  // build map of uuids -> object hashes
16
20
  const uuidObjectHashMap = {};
17
21
  // object hashes -> full objects
@@ -38,12 +42,20 @@ export const openApiToSchemaGraph = ({ spec, filename, originalFileLocation, })
38
42
  mapSecuritySchemeComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
39
43
  // document.components.links -> TODO (unsupported)
40
44
  // document.components.callbacks -> TODO (unsupported)
41
- // document.components.pathItems -> TODO (unsupported)
45
+ // document.components.pathItems -> Path, possibly Parameter, Operation, RequestBody, Response, SecurityRequirement, Server
46
+ mapPathComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
47
+ // document -> Document
48
+ const documentId = uuidv4();
49
+ mapDocument({ spec, uuidObjectHashMap, hashedNodeMap, uuid: documentId });
42
50
  // document.servers -> Server
51
+ mapServers({ spec, uuidObjectHashMap, hashedNodeMap, documentId });
52
+ // document.security -> SecurityRequirement
53
+ mapSecurityRequirements({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId });
54
+ // add paths and webhooks to ref-uuid map for fast lookup per page in client
43
55
  // document.paths -> Path, possibly Parameter, Operation, RequestBody, Response, SecurityRequirement, Server
56
+ mapPaths({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId });
44
57
  // document.webhooks -> Path, possibly Parameter, Operation, RequestBody, Response, SecurityRequirement, Server
45
- // document.security -> SecurityRequirement
46
- // document -> Document
58
+ mapWebhooks({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId });
47
59
  return {
48
60
  filename,
49
61
  originalFileLocation,