@mintlify/validation 0.1.58 → 0.1.60

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 (49) hide show
  1. package/dist/index.d.ts +5 -6
  2. package/dist/index.js +62 -2
  3. package/dist/mint-config/common.js +9 -0
  4. package/dist/mint-config/flattenUnionErrorMessages.js +19 -0
  5. package/dist/mint-config/hexadecimalPattern.js +1 -0
  6. package/dist/mint-config/schemas/analytics.d.ts +0 -104
  7. package/dist/mint-config/schemas/analytics.js +129 -0
  8. package/dist/mint-config/schemas/anchorColors.d.ts +0 -1
  9. package/dist/mint-config/schemas/anchorColors.js +28 -0
  10. package/dist/mint-config/schemas/anchors.d.ts +7 -56
  11. package/dist/mint-config/schemas/anchors.js +69 -0
  12. package/dist/mint-config/schemas/apiReference.d.ts +0 -2
  13. package/dist/mint-config/schemas/apiReference.js +65 -0
  14. package/dist/mint-config/schemas/basics.d.ts +0 -11
  15. package/dist/mint-config/schemas/basics.js +122 -0
  16. package/dist/mint-config/schemas/colors.d.ts +0 -1
  17. package/dist/mint-config/schemas/colors.js +42 -0
  18. package/dist/mint-config/schemas/config.d.ts +18 -19
  19. package/dist/mint-config/schemas/config.js +39 -0
  20. package/dist/mint-config/schemas/favicon.js +9 -0
  21. package/dist/mint-config/schemas/integrations.d.ts +0 -6
  22. package/dist/mint-config/schemas/integrations.js +11 -0
  23. package/dist/mint-config/schemas/navigation.d.ts +15 -2
  24. package/dist/mint-config/schemas/navigation.js +27 -0
  25. package/dist/mint-config/schemas/tabs.d.ts +0 -13
  26. package/dist/mint-config/schemas/tabs.js +28 -0
  27. package/dist/mint-config/schemas/versions.d.ts +0 -13
  28. package/dist/mint-config/schemas/versions.js +13 -0
  29. package/dist/mint-config/validateAnchorsWarnings.d.ts +3 -4
  30. package/dist/mint-config/validateAnchorsWarnings.js +35 -0
  31. package/dist/mint-config/validateVersionsInNavigation.d.ts +4 -5
  32. package/dist/mint-config/validateVersionsInNavigation.js +55 -0
  33. package/dist/openapi/convertOpenApi.d.ts +1 -1
  34. package/dist/openapi/convertOpenApi.js +166 -0
  35. package/dist/openapi/convertParameters.d.ts +1 -1
  36. package/dist/openapi/convertParameters.js +60 -0
  37. package/dist/openapi/convertSchema.d.ts +1 -1
  38. package/dist/openapi/convertSchema.js +475 -0
  39. package/dist/openapi/convertSecurity.d.ts +1 -1
  40. package/dist/openapi/convertSecurity.js +82 -0
  41. package/dist/openapi/convertServers.d.ts +1 -1
  42. package/dist/openapi/convertServers.js +43 -0
  43. package/dist/openapi/types/endpoint.js +13 -0
  44. package/dist/tsconfig.build.tsbuildinfo +1 -0
  45. package/package.json +18 -11
  46. package/dist/index.js.LICENSE.txt +0 -8
  47. package/dist/mint-config/types/enums.d.ts +0 -4
  48. package/dist/mint-config/types/index.d.ts +0 -12
  49. package/dist/mint-config/types/navigation.d.ts +0 -13
@@ -0,0 +1,166 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
17
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
18
+ if (ar || !(i in from)) {
19
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
20
+ ar[i] = from[i];
21
+ }
22
+ }
23
+ return to.concat(ar || Array.prototype.slice.call(from));
24
+ };
25
+ import { convertParameters } from './convertParameters.js';
26
+ import { convertSchema } from './convertSchema.js';
27
+ import { convertSecurity } from './convertSecurity.js';
28
+ import { convertServers } from './convertServers.js';
29
+ export var generateMessage = function (path, messages) {
30
+ if (messages === void 0) { messages = []; }
31
+ var pathString = path
32
+ .map(function (component) { return component.replace('\\', '\\\\').replace('/', '\\/'); })
33
+ .join('/');
34
+ return __spreadArray([pathString], messages, true).join('\n');
35
+ };
36
+ var InvalidSchemaError = /** @class */ (function (_super) {
37
+ __extends(InvalidSchemaError, _super);
38
+ function InvalidSchemaError(path) {
39
+ var messages = [];
40
+ for (var _i = 1; _i < arguments.length; _i++) {
41
+ messages[_i - 1] = arguments[_i];
42
+ }
43
+ var _this = _super.call(this, generateMessage(path, messages)) || this;
44
+ _this.name = 'InvalidSchemaError';
45
+ Object.setPrototypeOf(_this, InvalidSchemaError.prototype);
46
+ return _this;
47
+ }
48
+ return InvalidSchemaError;
49
+ }(Error));
50
+ export { InvalidSchemaError };
51
+ var ImpossibleSchemaError = /** @class */ (function (_super) {
52
+ __extends(ImpossibleSchemaError, _super);
53
+ function ImpossibleSchemaError(path) {
54
+ var messages = [];
55
+ for (var _i = 1; _i < arguments.length; _i++) {
56
+ messages[_i - 1] = arguments[_i];
57
+ }
58
+ var _this = _super.call(this, generateMessage(path, messages)) || this;
59
+ _this.name = 'ImpossibleSchemaError';
60
+ Object.setPrototypeOf(_this, ImpossibleSchemaError.prototype);
61
+ return _this;
62
+ }
63
+ return ImpossibleSchemaError;
64
+ }(Error));
65
+ export { ImpossibleSchemaError };
66
+ var ConversionError = /** @class */ (function (_super) {
67
+ __extends(ConversionError, _super);
68
+ function ConversionError(path) {
69
+ var messages = [];
70
+ for (var _i = 1; _i < arguments.length; _i++) {
71
+ messages[_i - 1] = arguments[_i];
72
+ }
73
+ var _this = _super.call(this, generateMessage(path, messages)) || this;
74
+ _this.name = 'ConversionError';
75
+ Object.setPrototypeOf(_this, ConversionError.prototype);
76
+ return _this;
77
+ }
78
+ return ConversionError;
79
+ }(Error));
80
+ export { ConversionError };
81
+ export var convertBody = function (path, body) {
82
+ if (body === undefined) {
83
+ return {};
84
+ }
85
+ var newEntries = Object.entries(body.content).map(function (_a) {
86
+ var contentType = _a[0], mediaObject = _a[1];
87
+ return [
88
+ contentType,
89
+ convertSchema(__spreadArray(__spreadArray([], path, true), [contentType, 'schema'], false), mediaObject.schema, body.required),
90
+ ];
91
+ });
92
+ return Object.fromEntries(newEntries);
93
+ };
94
+ export var convertResponses = function (path, responses) {
95
+ var newEntries = Object.entries(responses).map(function (_a) {
96
+ var statusCode = _a[0], response = _a[1];
97
+ return [
98
+ statusCode,
99
+ convertResponse(__spreadArray(__spreadArray([], path, true), [statusCode], false), response),
100
+ ];
101
+ });
102
+ return Object.fromEntries(newEntries);
103
+ };
104
+ export var convertResponse = function (path, response) {
105
+ if (response.content === undefined) {
106
+ return {};
107
+ }
108
+ var newEntries = Object.entries(response.content).map(function (_a) {
109
+ var contentType = _a[0], mediaType = _a[1];
110
+ return [
111
+ contentType,
112
+ convertSchema(__spreadArray(__spreadArray([], path, true), ['content', contentType, 'schema'], false), mediaType.schema),
113
+ ];
114
+ });
115
+ return Object.fromEntries(newEntries);
116
+ };
117
+ export var convertOpenAPIV3_1ToEndpoint = function (spec, path, method) {
118
+ var _a, _b, _c, _d, _e;
119
+ var paths = spec.paths;
120
+ if (paths === undefined) {
121
+ throw new InvalidSchemaError(['#'], 'paths not defined');
122
+ }
123
+ var pathObject = paths[path];
124
+ if (pathObject === undefined) {
125
+ throw new InvalidSchemaError(['#', 'paths'], "path not defined: ".concat(path));
126
+ }
127
+ var operationObject = pathObject[method];
128
+ if (operationObject === undefined) {
129
+ throw new InvalidSchemaError(['#', 'paths', path], "operation does not exist: ".concat(method));
130
+ }
131
+ var securityRequirements = (_a = operationObject.security) !== null && _a !== void 0 ? _a : spec.security;
132
+ var securitySchemes = (_b = spec.components) === null || _b === void 0 ? void 0 : _b.securitySchemes;
133
+ var security = convertSecurity({
134
+ securityRequirements: securityRequirements,
135
+ securitySchemes: securitySchemes,
136
+ });
137
+ var pathParameters = pathObject.parameters;
138
+ var operationParameters = operationObject.parameters;
139
+ var parameters = convertParameters({
140
+ path: ['#', 'paths', path],
141
+ method: method,
142
+ pathParameters: pathParameters,
143
+ operationParameters: operationParameters,
144
+ });
145
+ var servers = convertServers({
146
+ servers: (_d = (_c = operationObject.servers) !== null && _c !== void 0 ? _c : pathObject.servers) !== null && _d !== void 0 ? _d : spec.servers,
147
+ });
148
+ var description = (_e = operationObject.description) !== null && _e !== void 0 ? _e : pathObject === null || pathObject === void 0 ? void 0 : pathObject.description;
149
+ var requestBody = operationObject.requestBody;
150
+ var body = convertBody(['#', 'paths', path, method, 'requestBody'], requestBody);
151
+ var deprecated = !!operationObject.deprecated;
152
+ var response = convertResponses(['#', 'paths', path, method, 'responses'], operationObject.responses);
153
+ return {
154
+ description: description,
155
+ path: path,
156
+ method: method,
157
+ servers: servers,
158
+ request: {
159
+ security: security,
160
+ parameters: parameters,
161
+ body: body,
162
+ },
163
+ response: response,
164
+ deprecated: deprecated,
165
+ };
166
+ };
@@ -1,5 +1,5 @@
1
1
  import { OpenAPIV3_1 } from 'openapi-types';
2
- import { ParameterSections } from './types/endpoint';
2
+ import { ParameterSections } from './types/endpoint.js';
3
3
  export type ConvertParametersParams = {
4
4
  path: string[];
5
5
  method: string;
@@ -0,0 +1,60 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { InvalidSchemaError } from './convertOpenApi.js';
11
+ import { convertSchema, copyKeyIfDefined } from './convertSchema.js';
12
+ export var convertParameters = function (_a) {
13
+ var path = _a.path, method = _a.method, pathParameters = _a.pathParameters, operationParameters = _a.operationParameters;
14
+ var parameterSections = {
15
+ path: {},
16
+ query: {},
17
+ header: {},
18
+ cookie: {},
19
+ };
20
+ pathParameters === null || pathParameters === void 0 ? void 0 : pathParameters.forEach(function (parameterObject, i) {
21
+ addParameter({
22
+ path: __spreadArray(__spreadArray([], path, true), ['parameters', i.toString()], false),
23
+ parameter: parameterObject,
24
+ parameterSections: parameterSections,
25
+ });
26
+ });
27
+ operationParameters === null || operationParameters === void 0 ? void 0 : operationParameters.forEach(function (parameterObject, i) {
28
+ addParameter({
29
+ path: __spreadArray(__spreadArray([], path, true), [method, 'parameters', i.toString()], false),
30
+ parameter: parameterObject,
31
+ parameterSections: parameterSections,
32
+ });
33
+ });
34
+ return parameterSections;
35
+ };
36
+ var addParameter = function (_a) {
37
+ var path = _a.path, parameter = _a.parameter, parameterSections = _a.parameterSections;
38
+ if (!['path', 'header', 'query', 'cookie'].includes(parameter.in)) {
39
+ throw new InvalidSchemaError(path, "invalid parameter location: '".concat(parameter.in, "'"));
40
+ }
41
+ var location = parameter.in;
42
+ if (location === 'path') {
43
+ var newParameter = {
44
+ required: true,
45
+ schema: convertSchema(__spreadArray(__spreadArray([], path, true), ['schema'], false), parameter.schema, true),
46
+ };
47
+ copyKeyIfDefined('description', parameter, newParameter);
48
+ copyKeyIfDefined('deprecated', parameter, newParameter);
49
+ parameterSections.path[parameter.name] = newParameter;
50
+ }
51
+ else {
52
+ var newParameter = {
53
+ schema: convertSchema(__spreadArray(__spreadArray([], path, true), ['schema'], false), parameter.schema, true),
54
+ };
55
+ copyKeyIfDefined('description', parameter, newParameter);
56
+ copyKeyIfDefined('deprecated', parameter, newParameter);
57
+ copyKeyIfDefined('required', parameter, newParameter);
58
+ parameterSections[location][parameter.name] = newParameter;
59
+ }
60
+ };
@@ -1,5 +1,5 @@
1
1
  import { OpenAPIV3_1 } from 'openapi-types';
2
- import { DataSchemaArray } from './types/endpoint';
2
+ import { DataSchemaArray } from './types/endpoint.js';
3
3
  export declare const convertSchema: (path: string[], schema: OpenAPIV3_1.SchemaObject | undefined, required?: boolean) => DataSchemaArray;
4
4
  export declare const combineTopLevelSchemas: (path: string[], schema1: OpenAPIV3_1.SchemaObject, schema2: OpenAPIV3_1.SchemaObject) => OpenAPIV3_1.SchemaObject;
5
5
  export declare const addKeyIfDefined: <D, K extends keyof D>(key: K, value: D[K], destination: D) => void;