@mintlify/validation 0.1.66 → 0.1.68

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.
@@ -1,8 +1,7 @@
1
1
  import { MintValidationResults } from './common.js';
2
2
  import { navigationSchema } from './schemas/navigation.js';
3
- export function flattenNavigationVersions(nav, versions) {
4
- if (versions === void 0) { versions = []; }
5
- nav.forEach(function (val) {
3
+ export function flattenNavigationVersions(nav, versions = []) {
4
+ nav.forEach((val) => {
6
5
  if (val == null || typeof val === 'string') {
7
6
  return versions;
8
7
  }
@@ -16,24 +15,22 @@ export function flattenNavigationVersions(nav, versions) {
16
15
  });
17
16
  return versions;
18
17
  }
19
- export function validateVersionsInNavigation(navigation, versions) {
20
- if (versions === void 0) { versions = []; }
21
- var results = new MintValidationResults();
18
+ export function validateVersionsInNavigation(navigation, versions = []) {
19
+ const results = new MintValidationResults();
22
20
  if (navigation == null || !navigationSchema.safeParse(navigation).success) {
23
21
  return results;
24
22
  }
25
- var versionsFromNavigation = flattenNavigationVersions(navigation);
26
- versionsFromNavigation.forEach(function (v) {
23
+ const versionsFromNavigation = flattenNavigationVersions(navigation);
24
+ versionsFromNavigation.forEach((v) => {
27
25
  if (versions && !versions.includes(v)) {
28
- results.errors.push("Version ".concat(v, " is not included in the versions array, but is used in the navigation. Please add ").concat(v, " to the versions array."));
26
+ results.errors.push(`Version ${v} is not included in the versions array, but is used in the navigation. Please add ${v} to the versions array.`);
29
27
  }
30
28
  });
31
29
  if (versionsFromNavigation.length === 0 && versions.length > 0) {
32
30
  results.warnings.push('You have versions defined in the config, but no versions are used in the navigation.');
33
31
  }
34
- navigation.forEach(function (nav) {
35
- var _a;
36
- (_a = results.warnings).push.apply(_a, warnVersionNesting(nav, null));
32
+ navigation.forEach((nav) => {
33
+ results.warnings.push(...warnVersionNesting(nav, null));
37
34
  });
38
35
  return results;
39
36
  }
@@ -41,13 +38,13 @@ function warnVersionNesting(navigation, currentVersion) {
41
38
  if (typeof navigation === 'string') {
42
39
  return [];
43
40
  }
44
- var warnings = [];
41
+ const warnings = [];
45
42
  if (navigation.version && currentVersion != null && navigation.version !== currentVersion) {
46
- warnings.push("Please do not set versions on groups nested inside a group that already has a version. The group \"".concat(navigation.group, "\" has version \"").concat(navigation.version, "\" set and it is nested in a group that has the version \"").concat(currentVersion, "\" set."));
43
+ warnings.push(`Please do not set versions on groups nested inside a group that already has a version. The group "${navigation.group}" has version "${navigation.version}" set and it is nested in a group that has the version "${currentVersion}" set.`);
47
44
  }
48
45
  if (navigation.pages) {
49
46
  return warnings.concat(navigation.pages
50
- .map(function (entry) { return warnVersionNesting(entry, currentVersion || navigation.version); })
47
+ .map((entry) => warnVersionNesting(entry, currentVersion || navigation.version))
51
48
  .flat()
52
49
  .filter(Boolean));
53
50
  }
@@ -1,166 +1,110 @@
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
1
  import { convertParameters } from './convertParameters.js';
26
2
  import { convertSchema } from './convertSchema.js';
27
3
  import { convertSecurity } from './convertSecurity.js';
28
4
  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('/', '\\/'); })
5
+ export const generateMessage = (path, messages = []) => {
6
+ const pathString = path
7
+ .map((component) => component.replace('\\', '\\\\').replace('/', '\\/'))
33
8
  .join('/');
34
- return __spreadArray([pathString], messages, true).join('\n');
9
+ return [pathString, ...messages].join('\n');
35
10
  };
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;
11
+ export class InvalidSchemaError extends Error {
12
+ constructor(path, ...messages) {
13
+ super(generateMessage(path, messages));
14
+ this.name = 'InvalidSchemaError';
15
+ Object.setPrototypeOf(this, InvalidSchemaError.prototype);
47
16
  }
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;
17
+ }
18
+ export class ImpossibleSchemaError extends Error {
19
+ constructor(path, ...messages) {
20
+ super(generateMessage(path, messages));
21
+ this.name = 'ImpossibleSchemaError';
22
+ Object.setPrototypeOf(this, ImpossibleSchemaError.prototype);
62
23
  }
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;
24
+ }
25
+ export class ConversionError extends Error {
26
+ constructor(path, ...messages) {
27
+ super(generateMessage(path, messages));
28
+ this.name = 'ConversionError';
29
+ Object.setPrototypeOf(this, ConversionError.prototype);
77
30
  }
78
- return ConversionError;
79
- }(Error));
80
- export { ConversionError };
81
- export var convertBody = function (path, body) {
31
+ }
32
+ export const convertBody = (path, body) => {
82
33
  if (body === undefined) {
83
34
  return {};
84
35
  }
85
- var newEntries = Object.entries(body.content).map(function (_a) {
86
- var contentType = _a[0], mediaObject = _a[1];
36
+ const newEntries = Object.entries(body.content).map(([contentType, mediaObject]) => {
87
37
  return [
88
38
  contentType,
89
- convertSchema(__spreadArray(__spreadArray([], path, true), [contentType, 'schema'], false), mediaObject.schema, body.required),
39
+ convertSchema([...path, contentType, 'schema'], mediaObject.schema, body.required),
90
40
  ];
91
41
  });
92
42
  return Object.fromEntries(newEntries);
93
43
  };
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
- });
44
+ export const convertResponses = (path, responses) => {
45
+ const newEntries = Object.entries(responses).map(([statusCode, response]) => [
46
+ statusCode,
47
+ convertResponse([...path, statusCode], response),
48
+ ]);
102
49
  return Object.fromEntries(newEntries);
103
50
  };
104
- export var convertResponse = function (path, response) {
51
+ export const convertResponse = (path, response) => {
105
52
  if (response.content === undefined) {
106
53
  return {};
107
54
  }
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
- });
55
+ const newEntries = Object.entries(response.content).map(([contentType, mediaType]) => [
56
+ contentType,
57
+ convertSchema([...path, 'content', contentType, 'schema'], mediaType.schema),
58
+ ]);
115
59
  return Object.fromEntries(newEntries);
116
60
  };
117
- export var convertOpenAPIV3_1ToEndpoint = function (spec, path, method) {
61
+ export const convertOpenAPIV3_1ToEndpoint = (spec, path, method) => {
118
62
  var _a, _b, _c, _d, _e;
119
- var paths = spec.paths;
63
+ const paths = spec.paths;
120
64
  if (paths === undefined) {
121
65
  throw new InvalidSchemaError(['#'], 'paths not defined');
122
66
  }
123
- var pathObject = paths[path];
67
+ const pathObject = paths[path];
124
68
  if (pathObject === undefined) {
125
- throw new InvalidSchemaError(['#', 'paths'], "path not defined: ".concat(path));
69
+ throw new InvalidSchemaError(['#', 'paths'], `path not defined: ${path}`);
126
70
  }
127
- var operationObject = pathObject[method];
71
+ const operationObject = pathObject[method];
128
72
  if (operationObject === undefined) {
129
- throw new InvalidSchemaError(['#', 'paths', path], "operation does not exist: ".concat(method));
73
+ throw new InvalidSchemaError(['#', 'paths', path], `operation does not exist: ${method}`);
130
74
  }
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,
75
+ const securityRequirements = (_a = operationObject.security) !== null && _a !== void 0 ? _a : spec.security;
76
+ const securitySchemes = (_b = spec.components) === null || _b === void 0 ? void 0 : _b.securitySchemes;
77
+ const security = convertSecurity({
78
+ securityRequirements,
79
+ securitySchemes,
136
80
  });
137
- var pathParameters = pathObject.parameters;
138
- var operationParameters = operationObject.parameters;
139
- var parameters = convertParameters({
81
+ const pathParameters = pathObject.parameters;
82
+ const operationParameters = operationObject.parameters;
83
+ const parameters = convertParameters({
140
84
  path: ['#', 'paths', path],
141
- method: method,
85
+ method,
142
86
  pathParameters: pathParameters,
143
87
  operationParameters: operationParameters,
144
88
  });
145
- var servers = convertServers({
89
+ const servers = convertServers({
146
90
  servers: (_d = (_c = operationObject.servers) !== null && _c !== void 0 ? _c : pathObject.servers) !== null && _d !== void 0 ? _d : spec.servers,
147
91
  });
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);
92
+ const description = (_e = operationObject.description) !== null && _e !== void 0 ? _e : pathObject === null || pathObject === void 0 ? void 0 : pathObject.description;
93
+ const requestBody = operationObject.requestBody;
94
+ const body = convertBody(['#', 'paths', path, method, 'requestBody'], requestBody);
95
+ const deprecated = !!operationObject.deprecated;
96
+ const response = convertResponses(['#', 'paths', path, method, 'responses'], operationObject.responses);
153
97
  return {
154
- description: description,
155
- path: path,
156
- method: method,
157
- servers: servers,
98
+ description,
99
+ path,
100
+ method,
101
+ servers,
158
102
  request: {
159
- security: security,
160
- parameters: parameters,
161
- body: body,
103
+ security,
104
+ parameters,
105
+ body,
162
106
  },
163
- response: response,
164
- deprecated: deprecated,
107
+ response,
108
+ deprecated,
165
109
  };
166
110
  };
@@ -1,56 +1,45 @@
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
1
  import { InvalidSchemaError } from './convertOpenApi.js';
11
2
  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 = {
3
+ export const convertParameters = ({ path, method, pathParameters, operationParameters, }) => {
4
+ const parameterSections = {
15
5
  path: {},
16
6
  query: {},
17
7
  header: {},
18
8
  cookie: {},
19
9
  };
20
- pathParameters === null || pathParameters === void 0 ? void 0 : pathParameters.forEach(function (parameterObject, i) {
10
+ pathParameters === null || pathParameters === void 0 ? void 0 : pathParameters.forEach((parameterObject, i) => {
21
11
  addParameter({
22
- path: __spreadArray(__spreadArray([], path, true), ['parameters', i.toString()], false),
12
+ path: [...path, 'parameters', i.toString()],
23
13
  parameter: parameterObject,
24
- parameterSections: parameterSections,
14
+ parameterSections,
25
15
  });
26
16
  });
27
- operationParameters === null || operationParameters === void 0 ? void 0 : operationParameters.forEach(function (parameterObject, i) {
17
+ operationParameters === null || operationParameters === void 0 ? void 0 : operationParameters.forEach((parameterObject, i) => {
28
18
  addParameter({
29
- path: __spreadArray(__spreadArray([], path, true), [method, 'parameters', i.toString()], false),
19
+ path: [...path, method, 'parameters', i.toString()],
30
20
  parameter: parameterObject,
31
- parameterSections: parameterSections,
21
+ parameterSections,
32
22
  });
33
23
  });
34
24
  return parameterSections;
35
25
  };
36
- var addParameter = function (_a) {
37
- var path = _a.path, parameter = _a.parameter, parameterSections = _a.parameterSections;
26
+ const addParameter = ({ path, parameter, parameterSections }) => {
38
27
  if (!['path', 'header', 'query', 'cookie'].includes(parameter.in)) {
39
- throw new InvalidSchemaError(path, "invalid parameter location: '".concat(parameter.in, "'"));
28
+ throw new InvalidSchemaError(path, `invalid parameter location: '${parameter.in}'`);
40
29
  }
41
- var location = parameter.in;
30
+ const location = parameter.in;
42
31
  if (location === 'path') {
43
- var newParameter = {
32
+ const newParameter = {
44
33
  required: true,
45
- schema: convertSchema(__spreadArray(__spreadArray([], path, true), ['schema'], false), parameter.schema, true),
34
+ schema: convertSchema([...path, 'schema'], parameter.schema, true),
46
35
  };
47
36
  copyKeyIfDefined('description', parameter, newParameter);
48
37
  copyKeyIfDefined('deprecated', parameter, newParameter);
49
38
  parameterSections.path[parameter.name] = newParameter;
50
39
  }
51
40
  else {
52
- var newParameter = {
53
- schema: convertSchema(__spreadArray(__spreadArray([], path, true), ['schema'], false), parameter.schema, true),
41
+ const newParameter = {
42
+ schema: convertSchema([...path, 'schema'], parameter.schema, true),
54
43
  };
55
44
  copyKeyIfDefined('description', parameter, newParameter);
56
45
  copyKeyIfDefined('deprecated', parameter, newParameter);