@mintlify/validation 0.1.67 → 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.
- package/dist/index.js +17 -23
- package/dist/mint-config/common.js +3 -5
- package/dist/mint-config/flattenUnionErrorMessages.js +3 -12
- package/dist/mint-config/hexadecimalPattern.js +1 -1
- package/dist/mint-config/schemas/analytics.js +15 -15
- package/dist/mint-config/schemas/anchorColors.js +2 -2
- package/dist/mint-config/schemas/anchors.js +5 -5
- package/dist/mint-config/schemas/apiReference.js +4 -4
- package/dist/mint-config/schemas/basics.js +46 -48
- package/dist/mint-config/schemas/colors.js +1 -1
- package/dist/mint-config/schemas/config.js +1 -1
- package/dist/mint-config/schemas/favicon.js +2 -2
- package/dist/mint-config/schemas/integrations.js +3 -3
- package/dist/mint-config/schemas/navigation.js +7 -9
- package/dist/mint-config/schemas/tabs.js +3 -3
- package/dist/mint-config/schemas/versions.js +2 -2
- package/dist/mint-config/validateAnchorsWarnings.js +4 -4
- package/dist/mint-config/validateVersionsInNavigation.js +12 -15
- package/dist/openapi/convertOpenApi.js +65 -121
- package/dist/openapi/convertParameters.js +15 -26
- package/dist/openapi/convertSchema.js +89 -118
- package/dist/openapi/convertSecurity.js +19 -21
- package/dist/openapi/convertServers.js +7 -11
- package/dist/openapi/types/endpoint.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
26
|
-
versionsFromNavigation.forEach(
|
|
23
|
+
const versionsFromNavigation = flattenNavigationVersions(navigation);
|
|
24
|
+
versionsFromNavigation.forEach((v) => {
|
|
27
25
|
if (versions && !versions.includes(v)) {
|
|
28
|
-
results.errors.push(
|
|
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(
|
|
35
|
-
|
|
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
|
-
|
|
41
|
+
const warnings = [];
|
|
45
42
|
if (navigation.version && currentVersion != null && navigation.version !== currentVersion) {
|
|
46
|
-
warnings.push(
|
|
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(
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
9
|
+
return [pathString, ...messages].join('\n');
|
|
35
10
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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(
|
|
39
|
+
convertSchema([...path, contentType, 'schema'], mediaObject.schema, body.required),
|
|
90
40
|
];
|
|
91
41
|
});
|
|
92
42
|
return Object.fromEntries(newEntries);
|
|
93
43
|
};
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
51
|
+
export const convertResponse = (path, response) => {
|
|
105
52
|
if (response.content === undefined) {
|
|
106
53
|
return {};
|
|
107
54
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
|
61
|
+
export const convertOpenAPIV3_1ToEndpoint = (spec, path, method) => {
|
|
118
62
|
var _a, _b, _c, _d, _e;
|
|
119
|
-
|
|
63
|
+
const paths = spec.paths;
|
|
120
64
|
if (paths === undefined) {
|
|
121
65
|
throw new InvalidSchemaError(['#'], 'paths not defined');
|
|
122
66
|
}
|
|
123
|
-
|
|
67
|
+
const pathObject = paths[path];
|
|
124
68
|
if (pathObject === undefined) {
|
|
125
|
-
throw new InvalidSchemaError(['#', 'paths'],
|
|
69
|
+
throw new InvalidSchemaError(['#', 'paths'], `path not defined: ${path}`);
|
|
126
70
|
}
|
|
127
|
-
|
|
71
|
+
const operationObject = pathObject[method];
|
|
128
72
|
if (operationObject === undefined) {
|
|
129
|
-
throw new InvalidSchemaError(['#', 'paths', path],
|
|
73
|
+
throw new InvalidSchemaError(['#', 'paths', path], `operation does not exist: ${method}`);
|
|
130
74
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
securityRequirements
|
|
135
|
-
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
81
|
+
const pathParameters = pathObject.parameters;
|
|
82
|
+
const operationParameters = operationObject.parameters;
|
|
83
|
+
const parameters = convertParameters({
|
|
140
84
|
path: ['#', 'paths', path],
|
|
141
|
-
method
|
|
85
|
+
method,
|
|
142
86
|
pathParameters: pathParameters,
|
|
143
87
|
operationParameters: operationParameters,
|
|
144
88
|
});
|
|
145
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
155
|
-
path
|
|
156
|
-
method
|
|
157
|
-
servers
|
|
98
|
+
description,
|
|
99
|
+
path,
|
|
100
|
+
method,
|
|
101
|
+
servers,
|
|
158
102
|
request: {
|
|
159
|
-
security
|
|
160
|
-
parameters
|
|
161
|
-
body
|
|
103
|
+
security,
|
|
104
|
+
parameters,
|
|
105
|
+
body,
|
|
162
106
|
},
|
|
163
|
-
response
|
|
164
|
-
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
|
|
13
|
-
|
|
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(
|
|
10
|
+
pathParameters === null || pathParameters === void 0 ? void 0 : pathParameters.forEach((parameterObject, i) => {
|
|
21
11
|
addParameter({
|
|
22
|
-
path:
|
|
12
|
+
path: [...path, 'parameters', i.toString()],
|
|
23
13
|
parameter: parameterObject,
|
|
24
|
-
parameterSections
|
|
14
|
+
parameterSections,
|
|
25
15
|
});
|
|
26
16
|
});
|
|
27
|
-
operationParameters === null || operationParameters === void 0 ? void 0 : operationParameters.forEach(
|
|
17
|
+
operationParameters === null || operationParameters === void 0 ? void 0 : operationParameters.forEach((parameterObject, i) => {
|
|
28
18
|
addParameter({
|
|
29
|
-
path:
|
|
19
|
+
path: [...path, method, 'parameters', i.toString()],
|
|
30
20
|
parameter: parameterObject,
|
|
31
|
-
parameterSections
|
|
21
|
+
parameterSections,
|
|
32
22
|
});
|
|
33
23
|
});
|
|
34
24
|
return parameterSections;
|
|
35
25
|
};
|
|
36
|
-
|
|
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,
|
|
28
|
+
throw new InvalidSchemaError(path, `invalid parameter location: '${parameter.in}'`);
|
|
40
29
|
}
|
|
41
|
-
|
|
30
|
+
const location = parameter.in;
|
|
42
31
|
if (location === 'path') {
|
|
43
|
-
|
|
32
|
+
const newParameter = {
|
|
44
33
|
required: true,
|
|
45
|
-
schema: convertSchema(
|
|
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
|
-
|
|
53
|
-
schema: convertSchema(
|
|
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);
|