@mintlify/validation 0.1.98 → 0.1.99
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.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/openapi/OpenApiToEndpointConverter.d.ts +13 -0
- package/dist/openapi/OpenApiToEndpointConverter.js +96 -0
- package/dist/openapi/ParametersConverter.d.ts +13 -0
- package/dist/openapi/ParametersConverter.js +46 -0
- package/dist/openapi/SchemaConverter.d.ts +40 -0
- package/dist/openapi/SchemaConverter.js +467 -0
- package/dist/openapi/SecurityConverter.d.ts +10 -0
- package/dist/openapi/SecurityConverter.js +80 -0
- package/dist/openapi/ServersConverter.d.ts +9 -0
- package/dist/openapi/ServersConverter.js +47 -0
- package/dist/openapi/errors.d.ts +10 -0
- package/dist/openapi/errors.js +27 -0
- package/dist/openapi/utils.d.ts +2 -0
- package/dist/openapi/utils.js +12 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/openapi/convertOpenApi.d.ts +0 -16
- package/dist/openapi/convertOpenApi.js +0 -118
- package/dist/openapi/convertParameters.d.ts +0 -9
- package/dist/openapi/convertParameters.js +0 -37
- package/dist/openapi/convertSchema.d.ts +0 -11
- package/dist/openapi/convertSchema.js +0 -462
- package/dist/openapi/convertSecurity.d.ts +0 -14
- package/dist/openapi/convertSecurity.js +0 -74
- package/dist/openapi/convertServers.d.ts +0 -8
- package/dist/openapi/convertServers.js +0 -39
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { ConfigType } from '@mintlify/models';
|
|
|
2
2
|
import { MintValidationResults } from './mint-config/common.js';
|
|
3
3
|
export declare function validateMintConfig(config: ConfigType): MintValidationResults;
|
|
4
4
|
export * from './openapi/types/endpoint.js';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
5
|
+
export { OpenApiToEndpointConverter } from './openapi/OpenApiToEndpointConverter.js';
|
|
6
|
+
export { SchemaConverter } from './openapi/SchemaConverter.js';
|
|
7
7
|
export { generateExampleFromSchema } from './openapi/generateExampleFromSchema.js';
|
|
8
8
|
export declare const mintConfigSchema: any;
|
|
9
9
|
export { sort } from './sort.js';
|
package/dist/index.js
CHANGED
|
@@ -44,8 +44,8 @@ export function validateMintConfig(config) {
|
|
|
44
44
|
return results;
|
|
45
45
|
}
|
|
46
46
|
export * from './openapi/types/endpoint.js';
|
|
47
|
-
export {
|
|
48
|
-
export {
|
|
47
|
+
export { OpenApiToEndpointConverter } from './openapi/OpenApiToEndpointConverter.js';
|
|
48
|
+
export { SchemaConverter } from './openapi/SchemaConverter.js';
|
|
49
49
|
export { generateExampleFromSchema } from './openapi/generateExampleFromSchema.js';
|
|
50
50
|
export const mintConfigSchema = (() => {
|
|
51
51
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import type { Endpoint, HttpMethod } from './types/endpoint.js';
|
|
3
|
+
export declare class OpenApiToEndpointConverter {
|
|
4
|
+
readonly document: OpenAPIV3_1.Document;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly method: HttpMethod;
|
|
7
|
+
private constructor();
|
|
8
|
+
private convert;
|
|
9
|
+
private convertContent;
|
|
10
|
+
private convertExamples;
|
|
11
|
+
private convertResponses;
|
|
12
|
+
static convert(spec: OpenAPIV3_1.Document, path: string, method: HttpMethod): Endpoint | undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ParametersConverter } from './ParametersConverter.js';
|
|
2
|
+
import { SchemaConverter } from './SchemaConverter.js';
|
|
3
|
+
import { SecurityConverter } from './SecurityConverter.js';
|
|
4
|
+
import { ServersConverter } from './ServersConverter.js';
|
|
5
|
+
import { InvalidSchemaError } from './errors.js';
|
|
6
|
+
import { generateExampleFromSchema } from './generateExampleFromSchema.js';
|
|
7
|
+
export class OpenApiToEndpointConverter {
|
|
8
|
+
constructor(document, path, method) {
|
|
9
|
+
this.document = document;
|
|
10
|
+
this.path = path;
|
|
11
|
+
this.method = method;
|
|
12
|
+
}
|
|
13
|
+
convert() {
|
|
14
|
+
var _a, _b, _c, _d, _e;
|
|
15
|
+
const paths = this.document.paths;
|
|
16
|
+
if (paths === undefined) {
|
|
17
|
+
throw new InvalidSchemaError(['#'], 'paths not defined');
|
|
18
|
+
}
|
|
19
|
+
const pathObject = paths[this.path];
|
|
20
|
+
if (pathObject === undefined) {
|
|
21
|
+
throw new InvalidSchemaError(['#', 'paths'], `path not defined: ${this.path}`);
|
|
22
|
+
}
|
|
23
|
+
const operationObject = pathObject[this.method];
|
|
24
|
+
if (operationObject === undefined) {
|
|
25
|
+
throw new InvalidSchemaError(['#', 'paths', this.path], `operation does not exist: ${this.method}`);
|
|
26
|
+
}
|
|
27
|
+
const securityRequirements = (_a = operationObject.security) !== null && _a !== void 0 ? _a : this.document.security;
|
|
28
|
+
const securitySchemes = (_b = this.document.components) === null || _b === void 0 ? void 0 : _b.securitySchemes;
|
|
29
|
+
const security = SecurityConverter.convert(securityRequirements, securitySchemes);
|
|
30
|
+
const pathParameters = pathObject.parameters;
|
|
31
|
+
const operationParameters = operationObject.parameters;
|
|
32
|
+
const parameters = ParametersConverter.convert(this.method, pathParameters, operationParameters, ['#', 'paths', this.path]);
|
|
33
|
+
const servers = ServersConverter.convert((_d = (_c = operationObject.servers) !== null && _c !== void 0 ? _c : pathObject.servers) !== null && _d !== void 0 ? _d : this.document.servers);
|
|
34
|
+
const description = (_e = operationObject.description) !== null && _e !== void 0 ? _e : pathObject.description;
|
|
35
|
+
const requestBody = operationObject.requestBody;
|
|
36
|
+
const body = this.convertContent(['#', 'paths', this.path, this.method, 'requestBody', 'content'], requestBody === null || requestBody === void 0 ? void 0 : requestBody.content, requestBody === null || requestBody === void 0 ? void 0 : requestBody.required);
|
|
37
|
+
const deprecated = !!operationObject.deprecated;
|
|
38
|
+
const response = this.convertResponses(['#', 'paths', this.path, this.method, 'responses'], operationObject.responses);
|
|
39
|
+
return {
|
|
40
|
+
description,
|
|
41
|
+
path: this.path,
|
|
42
|
+
method: this.method,
|
|
43
|
+
servers,
|
|
44
|
+
request: {
|
|
45
|
+
security,
|
|
46
|
+
parameters,
|
|
47
|
+
body,
|
|
48
|
+
},
|
|
49
|
+
response,
|
|
50
|
+
deprecated,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
convertContent(debugPath, content, required) {
|
|
54
|
+
if (content === undefined) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
const newEntries = Object.entries(content).map(([contentType, mediaObject]) => {
|
|
58
|
+
const schemaArray = SchemaConverter.convert({
|
|
59
|
+
schema: mediaObject.schema,
|
|
60
|
+
path: [...debugPath, contentType, 'schema'],
|
|
61
|
+
required,
|
|
62
|
+
});
|
|
63
|
+
const examples = this.convertExamples(mediaObject.examples, mediaObject.example, schemaArray);
|
|
64
|
+
return [contentType, { schemaArray, examples }];
|
|
65
|
+
});
|
|
66
|
+
return Object.fromEntries(newEntries);
|
|
67
|
+
}
|
|
68
|
+
convertExamples(examples, example, schemaArray) {
|
|
69
|
+
if (examples && Object.values(examples).some(({ value }) => value !== undefined)) {
|
|
70
|
+
return Object.fromEntries(Object.entries(examples)
|
|
71
|
+
.filter(([_, { value }]) => value !== undefined)
|
|
72
|
+
.map(([key, example]) => [
|
|
73
|
+
key,
|
|
74
|
+
{
|
|
75
|
+
summary: example.summary,
|
|
76
|
+
description: example.description,
|
|
77
|
+
value: example.value,
|
|
78
|
+
},
|
|
79
|
+
]));
|
|
80
|
+
}
|
|
81
|
+
if (example !== undefined) {
|
|
82
|
+
return { example: { value: example } };
|
|
83
|
+
}
|
|
84
|
+
return { example: { value: generateExampleFromSchema(schemaArray[0]) } };
|
|
85
|
+
}
|
|
86
|
+
convertResponses(debugPath, responses) {
|
|
87
|
+
const newEntries = Object.entries(responses).map(([statusCode, response]) => [
|
|
88
|
+
statusCode,
|
|
89
|
+
this.convertContent([...debugPath, statusCode, 'content'], response.content),
|
|
90
|
+
]);
|
|
91
|
+
return Object.fromEntries(newEntries);
|
|
92
|
+
}
|
|
93
|
+
static convert(spec, path, method) {
|
|
94
|
+
return new OpenApiToEndpointConverter(spec, path, method).convert();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { ParameterSections } from './types/endpoint.js';
|
|
3
|
+
export declare class ParametersConverter {
|
|
4
|
+
readonly method: string;
|
|
5
|
+
readonly pathParameters: OpenAPIV3_1.ParameterObject[] | undefined;
|
|
6
|
+
readonly operationParameters: OpenAPIV3_1.ParameterObject[] | undefined;
|
|
7
|
+
readonly path: string[];
|
|
8
|
+
private parameterSections;
|
|
9
|
+
private constructor();
|
|
10
|
+
private convert;
|
|
11
|
+
private addParameter;
|
|
12
|
+
static convert(method: string, pathParameters: OpenAPIV3_1.ParameterObject[] | undefined, operationParameters: OpenAPIV3_1.ParameterObject[] | undefined, path: string[]): ParameterSections;
|
|
13
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SchemaConverter } from './SchemaConverter.js';
|
|
2
|
+
import { InvalidSchemaError } from './errors.js';
|
|
3
|
+
import { copyKeyIfDefined } from './utils.js';
|
|
4
|
+
export class ParametersConverter {
|
|
5
|
+
constructor(method, pathParameters, operationParameters, path) {
|
|
6
|
+
this.method = method;
|
|
7
|
+
this.pathParameters = pathParameters;
|
|
8
|
+
this.operationParameters = operationParameters;
|
|
9
|
+
this.path = path;
|
|
10
|
+
this.parameterSections = {
|
|
11
|
+
path: {},
|
|
12
|
+
query: {},
|
|
13
|
+
header: {},
|
|
14
|
+
cookie: {},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
convert() {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
(_a = this.pathParameters) === null || _a === void 0 ? void 0 : _a.forEach((parameterObject, i) => {
|
|
20
|
+
this.addParameter([...this.path, 'parameters', i.toString()], parameterObject);
|
|
21
|
+
});
|
|
22
|
+
(_b = this.operationParameters) === null || _b === void 0 ? void 0 : _b.forEach((parameterObject, i) => {
|
|
23
|
+
this.addParameter([...this.path, this.method, 'parameters', i.toString()], parameterObject);
|
|
24
|
+
});
|
|
25
|
+
return this.parameterSections;
|
|
26
|
+
}
|
|
27
|
+
addParameter(path, parameter) {
|
|
28
|
+
if (!['path', 'header', 'query', 'cookie'].includes(parameter.in)) {
|
|
29
|
+
throw new InvalidSchemaError(path, `invalid parameter location: '${parameter.in}'`);
|
|
30
|
+
}
|
|
31
|
+
const location = parameter.in;
|
|
32
|
+
// parameter.schema may be undefined (if the schema is instead defined in parameter.content), but this is likely super rare
|
|
33
|
+
const parameterSchema = parameter.schema;
|
|
34
|
+
copyKeyIfDefined('description', parameter, parameterSchema);
|
|
35
|
+
copyKeyIfDefined('deprecated', parameter, parameterSchema);
|
|
36
|
+
const newParameter = SchemaConverter.convert({
|
|
37
|
+
schema: parameter.schema,
|
|
38
|
+
path: [...path, 'schema'],
|
|
39
|
+
required: location === 'path' ? true : parameter.required,
|
|
40
|
+
});
|
|
41
|
+
this.parameterSections[location][parameter.name] = { schema: newParameter };
|
|
42
|
+
}
|
|
43
|
+
static convert(method, pathParameters, operationParameters, path) {
|
|
44
|
+
return new ParametersConverter(method, pathParameters, operationParameters, path).convert();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
import { DataSchemaArray } from './types/endpoint.js';
|
|
3
|
+
export declare class SchemaConverter {
|
|
4
|
+
readonly schema: OpenAPIV3_1.SchemaObject | undefined;
|
|
5
|
+
readonly required?: boolean | undefined;
|
|
6
|
+
readonly path: string[];
|
|
7
|
+
readonly location?: "request" | "response" | undefined;
|
|
8
|
+
private constructor();
|
|
9
|
+
private convert;
|
|
10
|
+
/**
|
|
11
|
+
* This function should be used to reduce strictly `oneOf` and `anyOf` compositions.
|
|
12
|
+
*
|
|
13
|
+
* @param schemaArray `schema.allOf` or `schema.oneOf`
|
|
14
|
+
* @returns a schema array equivalent to the `schemaArray` argument, but in reduced form
|
|
15
|
+
*/
|
|
16
|
+
private evaluateOptionsCompositions;
|
|
17
|
+
private evaluateCompositionsRecursive;
|
|
18
|
+
private generateTopLevelSchemaArray;
|
|
19
|
+
/**
|
|
20
|
+
* Given two arrays representing schema options, return an array representing schema options that satisfy one element in both arrays.
|
|
21
|
+
*
|
|
22
|
+
* It is helpful to think of each array as a union of all the schemas in the array. This function can then be thought of as taking
|
|
23
|
+
* the intersection of the two union types.
|
|
24
|
+
*
|
|
25
|
+
* @param a first array of schema options
|
|
26
|
+
* @param b second array of schema options
|
|
27
|
+
* @returns array of schemas that satisfy both arrays
|
|
28
|
+
*/
|
|
29
|
+
private multiplySchemaArrays;
|
|
30
|
+
private combineReducedSchemas;
|
|
31
|
+
private combineTopLevelSchemas;
|
|
32
|
+
private convertSchemaRecursive;
|
|
33
|
+
private convertProperties;
|
|
34
|
+
static convert({ schema, required, path, location, }: {
|
|
35
|
+
schema: OpenAPIV3_1.SchemaObject | undefined;
|
|
36
|
+
required?: boolean;
|
|
37
|
+
path?: string[];
|
|
38
|
+
location?: 'request' | 'response';
|
|
39
|
+
}): DataSchemaArray;
|
|
40
|
+
}
|