@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,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 && securityScheme.$ref) {
14
+ const refId = securityScheme.$ref;
15
+ const refUuid = refUuidMap[refId] || uuidv4();
16
+ securityScheme.$ref = refUuid;
17
+ }
18
+ hashedNodeMap[objectHash] = securityScheme;
19
+ });
20
+ };
@@ -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,12 +1,21 @@
1
+ import { v4 as uuidv4 } from 'uuid';
1
2
  import { buildRefUuidMap } from './buildRefUuidMap.js';
3
+ import { mapDocument } from './mapDocument.js';
4
+ import { mapExampleComponents } from './mapExampleComponents.js';
5
+ import { mapHeaderComponents } from './mapHeaderComponents.js';
6
+ import { mapParameterComponents } from './mapParameterComponents.js';
7
+ import { mapPathComponents } from './mapPathComponents.js';
8
+ import { mapPaths } from './mapPaths.js';
9
+ import { mapRequestBodyComponents } from './mapRequestBodyComponents.js';
2
10
  import { mapResponseComponents } from './mapResponseComponents.js';
3
11
  import { mapSchemaComponents } from './mapSchemaComponents.js';
12
+ import { mapSecurityRequirements } from './mapSecurityRequirements.js';
13
+ import { mapSecuritySchemeComponents } from './mapSecuritySchemeComponents.js';
14
+ import { mapServers } from './mapServers.js';
15
+ import { mapWebhooks } from './mapWebhooks.js';
4
16
  export const openApiToSchemaGraph = ({ spec, filename, originalFileLocation, }) => {
5
17
  // build map of component refs -> uuids
6
- // eslint-disable-next-line unused-imports/no-unused-vars
7
18
  const refUuidMap = buildRefUuidMap(spec);
8
- // eslint-disable-next-line unused-imports/no-unused-vars
9
- const nodes = [];
10
19
  // build map of uuids -> object hashes
11
20
  const uuidObjectHashMap = {};
12
21
  // object hashes -> full objects
@@ -22,18 +31,31 @@ export const openApiToSchemaGraph = ({ spec, filename, originalFileLocation, })
22
31
  // document.components.responses -> Response, possibly Header, Schema, Example, Media, Encoding
23
32
  mapResponseComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
24
33
  // document.components.parameters -> Parameter, possibly Schema, Example, Media, Encoding
34
+ mapParameterComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
25
35
  // document.components.examples -> Example
36
+ mapExampleComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
26
37
  // document.components.requestBodies -> RequestBody, possibly Media, Schema, Example, Encoding
38
+ mapRequestBodyComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
27
39
  // document.components.headers -> Header, possibly Schema, Example, Media, Encoding
40
+ mapHeaderComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
28
41
  // document.components.securitySchemes -> SecurityScheme
42
+ mapSecuritySchemeComponents({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap });
29
43
  // document.components.links -> TODO (unsupported)
30
44
  // document.components.callbacks -> TODO (unsupported)
31
- // 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 });
32
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
33
55
  // document.paths -> Path, possibly Parameter, Operation, RequestBody, Response, SecurityRequirement, Server
56
+ mapPaths({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId });
34
57
  // document.webhooks -> Path, possibly Parameter, Operation, RequestBody, Response, SecurityRequirement, Server
35
- // document.security -> SecurityRequirement
36
- // document -> Document
58
+ mapWebhooks({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, documentId });
37
59
  return {
38
60
  filename,
39
61
  originalFileLocation,
@@ -5,7 +5,7 @@ export type HashId = string;
5
5
  export type RefUuidMap = Record<string, UUID>;
6
6
  export type UUIDObjectHashMap = Record<UUID, HashId>;
7
7
  export type HashedNodeMap = Record<HashId, GraphNode>;
8
- export type GraphNode = SchemaOrRef | ResponseOrRef | HeaderOrRef | ParameterOrRef | Media | ExampleOrRef | RequestBodyOrRef | SecurityScheme | Server | Path | Operation | SecurityRequirement | Document;
8
+ export type GraphNode = SchemaOrRef | ResponseOrRef | HeaderOrRef | ParameterOrRef | Media | ExampleOrRef | RequestBodyOrRef | SecuritySchemeOrRef | Server | PathOrRef | Operation | SecurityRequirement | Document;
9
9
  export type SchemaObject = OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject;
10
10
  export type RefObject = OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;
11
11
  export type SchemaOrRefObject = SchemaObject | RefObject;
@@ -19,10 +19,21 @@ export type SchemaOrRef = (SchemaOrRefObject & {
19
19
  anyOf?: UUID[];
20
20
  oneOf?: UUID[];
21
21
  not?: UUID;
22
+ } & {
23
+ $ref?: never;
22
24
  }) | (RefObject & {
23
25
  $ref: UUID;
26
+ } & {
27
+ items?: never;
28
+ properties?: never;
29
+ additionalProperties?: never;
30
+ allOf?: never;
31
+ anyOf?: never;
32
+ oneOf?: never;
33
+ not?: never;
24
34
  }) | HashId;
25
35
  export type ResponseObject = OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject;
36
+ export type ResponseOrRefObject = ResponseObject | RefObject;
26
37
  export type ResponseOrRef = (ResponseObject & {
27
38
  headers?: {
28
39
  [header: string]: UUID;
@@ -33,8 +44,14 @@ export type ResponseOrRef = (ResponseObject & {
33
44
  links?: {
34
45
  [link: string]: UUID;
35
46
  };
47
+ } & {
48
+ $ref?: never;
36
49
  }) | (RefObject & {
37
50
  $ref: UUID;
51
+ } & {
52
+ headers?: never;
53
+ content?: never;
54
+ links?: never;
38
55
  });
39
56
  export type HeaderObject = OpenAPIV3.HeaderObject | OpenAPIV3_1.HeaderObject;
40
57
  export type HeaderOrRefObject = HeaderObject | RefObject;
@@ -46,8 +63,14 @@ export type HeaderOrRef = (HeaderObject & {
46
63
  content?: {
47
64
  [contentType: string]: UUID;
48
65
  };
66
+ } & {
67
+ $ref?: never;
49
68
  }) | (RefObject & {
50
69
  $ref: UUID;
70
+ } & {
71
+ schema?: never;
72
+ examples?: never;
73
+ content?: never;
51
74
  });
52
75
  export type ParameterObject = OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject;
53
76
  export type ParameterOrRefObject = ParameterObject | RefObject;
@@ -59,8 +82,14 @@ export type ParameterOrRef = (ParameterObject & {
59
82
  content?: {
60
83
  [contentType: string]: UUID;
61
84
  };
85
+ } & {
86
+ $ref?: never;
62
87
  }) | (RefObject & {
63
88
  $ref: UUID;
89
+ } & {
90
+ schema?: never;
91
+ examples?: never;
92
+ content?: never;
64
93
  });
65
94
  export type MediaObject = OpenAPIV3.MediaTypeObject | OpenAPIV3_1.MediaTypeObject;
66
95
  export type Media = MediaObject & {
@@ -74,8 +103,12 @@ export type Media = MediaObject & {
74
103
  };
75
104
  export type ExampleObject = OpenAPIV3.ExampleObject | OpenAPIV3_1.ExampleObject;
76
105
  export type ExampleOrRefObject = ExampleObject | RefObject;
77
- export type ExampleOrRef = ExampleObject | (RefObject & {
106
+ export type ExampleOrRef = (ExampleObject & {
107
+ $ref?: never;
108
+ }) | (RefObject & {
78
109
  $ref: UUID;
110
+ } & {
111
+ value?: never;
79
112
  });
80
113
  export type RequestBodyObject = OpenAPIV3.RequestBodyObject | OpenAPIV3_1.RequestBodyObject;
81
114
  export type RequestBodyOrRefObject = RequestBodyObject | RefObject;
@@ -83,20 +116,37 @@ export type RequestBodyOrRef = (RequestBodyObject & {
83
116
  content?: {
84
117
  [contentType: string]: UUID;
85
118
  };
119
+ } & {
120
+ $ref?: never;
86
121
  }) | (RefObject & {
87
122
  $ref: UUID;
123
+ } & {
124
+ content?: never;
88
125
  });
89
126
  export type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject;
90
- export type SecurityScheme = SecuritySchemeObject;
127
+ export type SecuritySchemeOrRefObject = SecuritySchemeObject | RefObject;
128
+ export type SecuritySchemeOrRef = (SecuritySchemeObject & {
129
+ $ref?: never;
130
+ }) | (RefObject & {
131
+ $ref: UUID;
132
+ });
91
133
  export type ServerObject = OpenAPIV3.ServerObject | OpenAPIV3_1.ServerObject;
92
134
  export type Server = ServerObject;
93
135
  export type PathObject = OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject;
94
- export type Path = PathObject & {
95
- pattern: string;
136
+ export type PathObjectOrRef = PathObject | RefObject;
137
+ export type PathOrRef = (PathObject & {
96
138
  parameters?: UUID[];
97
139
  } & {
98
140
  [method in OpenAPIV3.HttpMethods]: UUID;
99
- };
141
+ } & {
142
+ $ref?: never;
143
+ }) | (RefObject & {
144
+ $ref: UUID;
145
+ } & {
146
+ parameters?: never;
147
+ } & {
148
+ [method in OpenAPIV3.HttpMethods]: never;
149
+ });
100
150
  export type OperationObject = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject;
101
151
  export type OperationExtensions = {
102
152
  'x-mint'?: XMint;
@@ -119,11 +169,16 @@ export type Operation = OperationObject & {
119
169
  servers?: UUID[];
120
170
  } & OperationExtensions;
121
171
  export type SecurityRequirementObject = OpenAPIV3.SecurityRequirementObject | OpenAPIV3_1.SecurityRequirementObject;
122
- export type SecurityRequirement = SecurityRequirementObject;
172
+ export type SecurityRequirement = {
173
+ [name: string]: {
174
+ $ref?: UUID;
175
+ scopes?: string[];
176
+ };
177
+ };
123
178
  export type DocumentObject = OpenAPIV3.Document | OpenAPIV3_1.Document;
124
- export type Document = DocumentObject & {
125
- servers?: UUID[];
126
- paths?: UUID[];
127
- webhooks?: UUID[];
128
- security?: UUID[];
179
+ export type Document = Omit<DocumentObject, 'servers' | 'paths' | 'webhooks' | 'security'> & {
180
+ servers: UUID[];
181
+ paths: UUID[];
182
+ webhooks: UUID[];
183
+ security: UUID[];
129
184
  };