mcp-from-openapi 0.0.1
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/LICENSE +201 -0
- package/README.md +666 -0
- package/package.json +51 -0
- package/src/errors.d.ts +38 -0
- package/src/errors.js +62 -0
- package/src/errors.js.map +1 -0
- package/src/generator.d.ts +65 -0
- package/src/generator.js +348 -0
- package/src/generator.js.map +1 -0
- package/src/index.d.ts +8 -0
- package/src/index.js +27 -0
- package/src/index.js.map +1 -0
- package/src/parameter-resolver.d.ts +32 -0
- package/src/parameter-resolver.js +211 -0
- package/src/parameter-resolver.js.map +1 -0
- package/src/response-builder.d.ts +30 -0
- package/src/response-builder.js +147 -0
- package/src/response-builder.js.map +1 -0
- package/src/schema-builder.d.ts +123 -0
- package/src/schema-builder.js +296 -0
- package/src/schema-builder.js.map +1 -0
- package/src/types.d.ts +371 -0
- package/src/types.js +38 -0
- package/src/types.js.map +1 -0
- package/src/validator.d.ts +26 -0
- package/src/validator.js +211 -0
- package/src/validator.js.map +1 -0
package/src/types.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isReferenceObject = isReferenceObject;
|
|
4
|
+
exports.toJSONSchema7 = toJSONSchema7;
|
|
5
|
+
/**
|
|
6
|
+
* Helper to check if an object is a ReferenceObject
|
|
7
|
+
*/
|
|
8
|
+
function isReferenceObject(obj) {
|
|
9
|
+
return obj && typeof obj === 'object' && '$ref' in obj;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Convert OpenAPI schema to JSONSchema7
|
|
13
|
+
* Note: OpenAPI 3.0 uses a subset of JSON Schema Draft 4
|
|
14
|
+
* OpenAPI 3.1 uses JSON Schema Draft 2020-12
|
|
15
|
+
*/
|
|
16
|
+
function toJSONSchema7(schema) {
|
|
17
|
+
if (isReferenceObject(schema)) {
|
|
18
|
+
return { $ref: schema.$ref };
|
|
19
|
+
}
|
|
20
|
+
// Handle OpenAPI 3.0 boolean exclusiveMaximum/exclusiveMinimum
|
|
21
|
+
const result = { ...schema };
|
|
22
|
+
// Convert boolean exclusiveMaximum to number format (JSON Schema Draft 7)
|
|
23
|
+
if ('exclusiveMaximum' in schema && typeof schema.exclusiveMaximum === 'boolean') {
|
|
24
|
+
if (schema.exclusiveMaximum && 'maximum' in schema) {
|
|
25
|
+
result.exclusiveMaximum = schema.maximum;
|
|
26
|
+
delete result.maximum;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Convert boolean exclusiveMinimum to number format (JSON Schema Draft 7)
|
|
30
|
+
if ('exclusiveMinimum' in schema && typeof schema.exclusiveMinimum === 'boolean') {
|
|
31
|
+
if (schema.exclusiveMinimum && 'minimum' in schema) {
|
|
32
|
+
result.exclusiveMinimum = schema.minimum;
|
|
33
|
+
delete result.minimum;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
package/src/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;AAoDA,8CAEC;AAOD,sCAyBC;AArCD;;GAEG;AACH,SAAgB,iBAAiB,CAAC,GAAQ;IACxC,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,MAAsC;IAClE,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAiB,CAAC;IAC9C,CAAC;IAED,+DAA+D;IAC/D,MAAM,MAAM,GAAgB,EAAE,GAAG,MAAM,EAAS,CAAC;IAEjD,0EAA0E;IAC1E,IAAI,kBAAkB,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACjF,IAAI,MAAM,CAAC,gBAAgB,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;YACnD,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,OAAiB,CAAC;YACnD,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,IAAI,kBAAkB,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACjF,IAAI,MAAM,CAAC,gBAAgB,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;YACnD,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,OAAiB,CAAC;YACnD,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\n\n/**\n * OpenAPI specification version 3.0.x or 3.1.x\n */\nexport type OpenAPIVersion = '3.0.0' | '3.0.1' | '3.0.2' | '3.0.3' | '3.1.0';\n\n/**\n * Unified OpenAPI Document type (supports both 3.0 and 3.1)\n */\nexport type OpenAPIDocument = OpenAPIV3.Document | OpenAPIV3_1.Document;\n\n/**\n * HTTP methods supported by OpenAPI\n */\nexport type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'trace';\n\n/**\n * Parameter location types\n */\nexport type ParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'body';\n\n/**\n * Authentication types supported\n */\nexport type AuthType = 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';\n\n// Re-export OpenAPI types for convenience\nexport type OperationObject = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject;\nexport type ParameterObject = OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject;\nexport type RequestBodyObject = OpenAPIV3.RequestBodyObject | OpenAPIV3_1.RequestBodyObject;\nexport type ResponseObject = OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject;\nexport type ResponsesObject = OpenAPIV3.ResponsesObject | OpenAPIV3_1.ResponsesObject;\nexport type MediaTypeObject = OpenAPIV3.MediaTypeObject | OpenAPIV3_1.MediaTypeObject;\nexport type HeaderObject = OpenAPIV3.HeaderObject | OpenAPIV3_1.HeaderObject;\nexport type ExampleObject = OpenAPIV3.ExampleObject | OpenAPIV3_1.ExampleObject;\nexport type PathItemObject = OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject;\nexport type PathsObject = OpenAPIV3.PathsObject | OpenAPIV3_1.PathsObject;\nexport type ServerObject = OpenAPIV3.ServerObject | OpenAPIV3_1.ServerObject;\nexport type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject;\nexport type ReferenceObject = OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;\nexport type TagObject = OpenAPIV3.TagObject | OpenAPIV3_1.TagObject;\nexport type ExternalDocumentationObject = OpenAPIV3.ExternalDocumentationObject | OpenAPIV3_1.ExternalDocumentationObject;\nexport type ServerVariableObject = OpenAPIV3.ServerVariableObject | OpenAPIV3_1.ServerVariableObject;\nexport type EncodingObject = OpenAPIV3.EncodingObject | OpenAPIV3_1.EncodingObject;\nexport type SecurityRequirementObject = OpenAPIV3.SecurityRequirementObject | OpenAPIV3_1.SecurityRequirementObject;\nexport type SchemaObject = OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject;\n\n/**\n * Helper to check if an object is a ReferenceObject\n */\nexport function isReferenceObject(obj: any): obj is ReferenceObject {\n return obj && typeof obj === 'object' && '$ref' in obj;\n}\n\n/**\n * Convert OpenAPI schema to JSONSchema7\n * Note: OpenAPI 3.0 uses a subset of JSON Schema Draft 4\n * OpenAPI 3.1 uses JSON Schema Draft 2020-12\n */\nexport function toJSONSchema7(schema: SchemaObject | ReferenceObject): JSONSchema7 {\n if (isReferenceObject(schema)) {\n return { $ref: schema.$ref } as JSONSchema7;\n }\n\n // Handle OpenAPI 3.0 boolean exclusiveMaximum/exclusiveMinimum\n const result: JSONSchema7 = { ...schema } as any;\n\n // Convert boolean exclusiveMaximum to number format (JSON Schema Draft 7)\n if ('exclusiveMaximum' in schema && typeof schema.exclusiveMaximum === 'boolean') {\n if (schema.exclusiveMaximum && 'maximum' in schema) {\n result.exclusiveMaximum = schema.maximum as number;\n delete result.maximum;\n }\n }\n\n // Convert boolean exclusiveMinimum to number format (JSON Schema Draft 7)\n if ('exclusiveMinimum' in schema && typeof schema.exclusiveMinimum === 'boolean') {\n if (schema.exclusiveMinimum && 'minimum' in schema) {\n result.exclusiveMinimum = schema.minimum as number;\n delete result.minimum;\n }\n }\n\n return result;\n}\n\n/**\n * Main MCP Tool definition generated from OpenAPI\n */\nexport interface McpOpenAPITool {\n /**\n * Unique tool name (from operationId or generated)\n */\n name: string;\n\n /**\n * Tool description (from operation summary/description)\n */\n description: string;\n\n /**\n * Combined input schema including all parameters\n * (path, query, header, cookie, body)\n */\n inputSchema: JSONSchema7;\n\n /**\n * Output schema based on response definitions\n * Can be a union of multiple status codes\n */\n outputSchema?: JSONSchema7;\n\n /**\n * Mapping from input schema properties to actual request parameters\n */\n mapper: ParameterMapper[];\n\n /**\n * Additional metadata about the tool\n */\n metadata: ToolMetadata;\n}\n\n/**\n * Maps input schema properties to their actual request locations\n */\nexport interface ParameterMapper {\n /**\n * Property name in the input schema\n */\n inputKey: string;\n\n /**\n * Where this parameter should be placed in the request\n */\n type: ParameterLocation;\n\n /**\n * Original parameter name (before conflict resolution)\n */\n key: string;\n\n /**\n * Whether this parameter is required\n */\n required?: boolean;\n\n /**\n * Parameter style (for path/query parameters)\n */\n style?: string;\n\n /**\n * Whether to explode arrays/objects\n */\n explode?: boolean;\n\n /**\n * Custom serialization info\n */\n serialization?: SerializationInfo;\n}\n\n/**\n * Serialization information for complex parameters\n */\nexport interface SerializationInfo {\n /**\n * Content type for body parameters\n */\n contentType?: string;\n\n /**\n * Encoding rules\n */\n encoding?: Record<string, EncodingObject>;\n}\n\n/**\n * Additional metadata about the generated tool\n */\nexport interface ToolMetadata {\n /**\n * Original OpenAPI path\n */\n path: string;\n\n /**\n * HTTP method\n */\n method: HTTPMethod;\n\n /**\n * Operation ID from OpenAPI\n */\n operationId?: string;\n\n /**\n * Tags from OpenAPI\n */\n tags?: string[];\n\n /**\n * Whether operation is deprecated\n */\n deprecated?: boolean;\n\n /**\n * Security requirements\n */\n security?: SecurityRequirement[];\n\n /**\n * Server information\n */\n servers?: ServerInfo[];\n\n /**\n * Response status codes included in output schema\n */\n responseStatusCodes?: number[];\n\n /**\n * External documentation\n */\n externalDocs?: ExternalDocumentationObject;\n}\n\n/**\n * Security requirement definition\n */\nexport interface SecurityRequirement {\n /**\n * Security scheme name\n */\n scheme: string;\n\n /**\n * Security type\n */\n type: AuthType;\n\n /**\n * Scopes required (for OAuth2/OpenID Connect)\n */\n scopes?: string[];\n\n /**\n * Parameter name (for API key)\n */\n name?: string;\n\n /**\n * Parameter location (for API key)\n */\n in?: 'query' | 'header' | 'cookie';\n}\n\n/**\n * Server information\n */\nexport interface ServerInfo {\n /**\n * Server URL\n */\n url: string;\n\n /**\n * Server description\n */\n description?: string;\n\n /**\n * Server variables\n */\n variables?: Record<string, ServerVariableObject>;\n}\n\n/**\n * Options for loading OpenAPI specifications\n */\nexport interface LoadOptions {\n /**\n * Whether to dereference $refs in schemas\n * @default true\n */\n dereference?: boolean;\n\n /**\n * Base URL for API requests\n * Overrides servers in OpenAPI spec\n */\n baseUrl?: string;\n\n /**\n * Custom HTTP headers for loading from URL\n */\n headers?: Record<string, string>;\n\n /**\n * Request timeout in milliseconds\n * @default 30000\n */\n timeout?: number;\n\n /**\n * Whether to validate the OpenAPI document\n * @default true\n */\n validate?: boolean;\n\n /**\n * Whether to follow HTTP redirects\n * @default true\n */\n followRedirects?: boolean;\n}\n\n/**\n * Operation object with additional context for filtering\n */\nexport type OperationWithContext = OperationObject & {\n path: string;\n method: string;\n};\n\n/**\n * Options for generating tools\n */\nexport interface GenerateOptions {\n /**\n * Include only these operation IDs\n */\n includeOperations?: string[];\n\n /**\n * Exclude these operation IDs\n */\n excludeOperations?: string[];\n\n /**\n * Custom filter function\n */\n filterFn?: (operation: OperationWithContext) => boolean;\n\n /**\n * Naming strategy for resolving conflicts\n */\n namingStrategy?: NamingStrategy;\n\n /**\n * Preferred response status codes (in order of preference)\n * @default [200, 201, 204, 202, 203, 206]\n */\n preferredStatusCodes?: number[];\n\n /**\n * Whether to include deprecated operations\n * @default false\n */\n includeDeprecated?: boolean;\n\n /**\n * Whether to include all response codes in output schema\n * If false, only preferred status code is used\n * @default true\n */\n includeAllResponses?: boolean;\n\n /**\n * Maximum depth for dereferencing schemas\n * @default 10\n */\n maxSchemaDepth?: number;\n\n /**\n * Whether to include examples in schemas\n * @default false\n */\n includeExamples?: boolean;\n}\n\n/**\n * Naming strategy for resolving parameter conflicts\n */\nexport interface NamingStrategy {\n /**\n * Resolver function for parameter name conflicts\n * @param paramName - Original parameter name\n * @param location - Parameter location\n * @param index - Index of conflicting parameter (0-based)\n * @returns New parameter name\n */\n conflictResolver: (\n paramName: string,\n location: ParameterLocation,\n index: number\n ) => string;\n\n /**\n * Function to generate tool names\n * @param path - OpenAPI path\n * @param method - HTTP method\n * @param operationId - Operation ID if available\n * @returns Tool name\n */\n toolNameGenerator?: (\n path: string,\n method: HTTPMethod,\n operationId?: string\n ) => string;\n}\n\n/**\n * Validation result\n */\nexport interface ValidationResult {\n /**\n * Whether the document is valid\n */\n valid: boolean;\n\n /**\n * Validation errors\n */\n errors?: ValidationErrorDetail[];\n\n /**\n * Validation warnings\n */\n warnings?: ValidationWarning[];\n}\n\n/**\n * Validation error detail\n */\nexport interface ValidationErrorDetail {\n /**\n * Error message\n */\n message: string;\n\n /**\n * Error path (JSON pointer)\n */\n path?: string;\n\n /**\n * Error code\n */\n code?: string;\n}\n\n/**\n * Validation warning\n */\nexport interface ValidationWarning {\n /**\n * Warning message\n */\n message: string;\n\n /**\n * Warning path (JSON pointer)\n */\n path?: string;\n\n /**\n * Warning code\n */\n code?: string;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { OpenAPIDocument, ValidationResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates OpenAPI documents
|
|
4
|
+
*/
|
|
5
|
+
export declare class Validator {
|
|
6
|
+
/**
|
|
7
|
+
* Validate an OpenAPI document
|
|
8
|
+
*/
|
|
9
|
+
validate(document: OpenAPIDocument): Promise<ValidationResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Check if OpenAPI version is valid
|
|
12
|
+
*/
|
|
13
|
+
private isValidOpenAPIVersion;
|
|
14
|
+
/**
|
|
15
|
+
* Validate paths
|
|
16
|
+
*/
|
|
17
|
+
private validatePaths;
|
|
18
|
+
/**
|
|
19
|
+
* Validate an operation
|
|
20
|
+
*/
|
|
21
|
+
private validateOperation;
|
|
22
|
+
/**
|
|
23
|
+
* Validate parameters
|
|
24
|
+
*/
|
|
25
|
+
private validateParameters;
|
|
26
|
+
}
|
package/src/validator.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Validator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validates OpenAPI documents
|
|
6
|
+
*/
|
|
7
|
+
class Validator {
|
|
8
|
+
/**
|
|
9
|
+
* Validate an OpenAPI document
|
|
10
|
+
*/
|
|
11
|
+
async validate(document) {
|
|
12
|
+
const errors = [];
|
|
13
|
+
const warnings = [];
|
|
14
|
+
// Check OpenAPI version
|
|
15
|
+
if (!document.openapi) {
|
|
16
|
+
errors.push({
|
|
17
|
+
message: 'Missing required field: openapi',
|
|
18
|
+
path: '/openapi',
|
|
19
|
+
code: 'MISSING_OPENAPI_VERSION',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else if (!this.isValidOpenAPIVersion(document.openapi)) {
|
|
23
|
+
errors.push({
|
|
24
|
+
message: `Unsupported OpenAPI version: ${document.openapi}. Expected 3.0.x or 3.1.x`,
|
|
25
|
+
path: '/openapi',
|
|
26
|
+
code: 'INVALID_OPENAPI_VERSION',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Check info
|
|
30
|
+
if (!document.info) {
|
|
31
|
+
errors.push({
|
|
32
|
+
message: 'Missing required field: info',
|
|
33
|
+
path: '/info',
|
|
34
|
+
code: 'MISSING_INFO',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (!document.info.title) {
|
|
39
|
+
errors.push({
|
|
40
|
+
message: 'Missing required field: info.title',
|
|
41
|
+
path: '/info/title',
|
|
42
|
+
code: 'MISSING_TITLE',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (!document.info.version) {
|
|
46
|
+
errors.push({
|
|
47
|
+
message: 'Missing required field: info.version',
|
|
48
|
+
path: '/info/version',
|
|
49
|
+
code: 'MISSING_VERSION',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Check paths
|
|
54
|
+
if (!document.paths || Object.keys(document.paths).length === 0) {
|
|
55
|
+
warnings.push({
|
|
56
|
+
message: 'No paths defined in OpenAPI document',
|
|
57
|
+
path: '/paths',
|
|
58
|
+
code: 'NO_PATHS',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.validatePaths(document.paths, errors, warnings);
|
|
63
|
+
}
|
|
64
|
+
// Check servers
|
|
65
|
+
if (!document.servers || document.servers.length === 0) {
|
|
66
|
+
warnings.push({
|
|
67
|
+
message: 'No servers defined. You may need to provide a baseUrl option.',
|
|
68
|
+
path: '/servers',
|
|
69
|
+
code: 'NO_SERVERS',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Check security schemes
|
|
73
|
+
if (document.security && !document.components?.securitySchemes) {
|
|
74
|
+
warnings.push({
|
|
75
|
+
message: 'Security requirements defined but no security schemes found',
|
|
76
|
+
path: '/security',
|
|
77
|
+
code: 'NO_SECURITY_SCHEMES',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
valid: errors.length === 0,
|
|
82
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
83
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if OpenAPI version is valid
|
|
88
|
+
*/
|
|
89
|
+
isValidOpenAPIVersion(version) {
|
|
90
|
+
return /^3\.[01]\.\d+$/.test(version);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Validate paths
|
|
94
|
+
*/
|
|
95
|
+
validatePaths(paths, errors, warnings) {
|
|
96
|
+
for (const [path, pathItem] of Object.entries(paths)) {
|
|
97
|
+
if (!pathItem)
|
|
98
|
+
continue;
|
|
99
|
+
// Check path format
|
|
100
|
+
if (!path.startsWith('/')) {
|
|
101
|
+
errors.push({
|
|
102
|
+
message: `Path must start with '/': ${path}`,
|
|
103
|
+
path: `/paths/${path}`,
|
|
104
|
+
code: 'INVALID_PATH_FORMAT',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// Validate operations
|
|
108
|
+
const methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'];
|
|
109
|
+
let hasOperations = false;
|
|
110
|
+
for (const method of methods) {
|
|
111
|
+
const operation = pathItem[method];
|
|
112
|
+
if (operation) {
|
|
113
|
+
hasOperations = true;
|
|
114
|
+
this.validateOperation(operation, path, method, errors, warnings);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!hasOperations && !pathItem.$ref) {
|
|
118
|
+
warnings.push({
|
|
119
|
+
message: `Path has no operations: ${path}`,
|
|
120
|
+
path: `/paths/${path}`,
|
|
121
|
+
code: 'NO_OPERATIONS',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Validate an operation
|
|
128
|
+
*/
|
|
129
|
+
validateOperation(operation, path, method, errors, warnings) {
|
|
130
|
+
const basePath = `/paths/${path}/${method}`;
|
|
131
|
+
// Check for operationId
|
|
132
|
+
if (!operation.operationId) {
|
|
133
|
+
warnings.push({
|
|
134
|
+
message: `Operation missing operationId: ${method.toUpperCase()} ${path}`,
|
|
135
|
+
path: `${basePath}/operationId`,
|
|
136
|
+
code: 'NO_OPERATION_ID',
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
// Check for responses
|
|
140
|
+
if (!operation.responses || Object.keys(operation.responses).length === 0) {
|
|
141
|
+
errors.push({
|
|
142
|
+
message: `Operation missing responses: ${method.toUpperCase()} ${path}`,
|
|
143
|
+
path: `${basePath}/responses`,
|
|
144
|
+
code: 'NO_RESPONSES',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// Validate parameters
|
|
148
|
+
if (operation.parameters) {
|
|
149
|
+
this.validateParameters(operation.parameters, path, method, errors, warnings);
|
|
150
|
+
}
|
|
151
|
+
// Check for path parameters in path string
|
|
152
|
+
const pathParams = path.match(/\{([^}]+)\}/g)?.map((p) => p.slice(1, -1)) ?? [];
|
|
153
|
+
const definedPathParams = new Set(operation.parameters?.filter((p) => p.in === 'path').map((p) => p.name) ?? []);
|
|
154
|
+
for (const param of pathParams) {
|
|
155
|
+
if (!definedPathParams.has(param)) {
|
|
156
|
+
errors.push({
|
|
157
|
+
message: `Path parameter '${param}' not defined in parameters: ${method.toUpperCase()} ${path}`,
|
|
158
|
+
path: `${basePath}/parameters`,
|
|
159
|
+
code: 'MISSING_PATH_PARAMETER',
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Validate parameters
|
|
166
|
+
*/
|
|
167
|
+
validateParameters(parameters, path, method, errors, warnings) {
|
|
168
|
+
const basePath = `/paths/${path}/${method}/parameters`;
|
|
169
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
170
|
+
const param = parameters[i];
|
|
171
|
+
const paramPath = `${basePath}/${i}`;
|
|
172
|
+
if (!param.name) {
|
|
173
|
+
errors.push({
|
|
174
|
+
message: 'Parameter missing name',
|
|
175
|
+
path: `${paramPath}/name`,
|
|
176
|
+
code: 'MISSING_PARAMETER_NAME',
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (!param.in) {
|
|
180
|
+
errors.push({
|
|
181
|
+
message: 'Parameter missing "in" field',
|
|
182
|
+
path: `${paramPath}/in`,
|
|
183
|
+
code: 'MISSING_PARAMETER_IN',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else if (!['path', 'query', 'header', 'cookie'].includes(param.in)) {
|
|
187
|
+
errors.push({
|
|
188
|
+
message: `Invalid parameter location: ${param.in}`,
|
|
189
|
+
path: `${paramPath}/in`,
|
|
190
|
+
code: 'INVALID_PARAMETER_IN',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (param.in === 'path' && !param.required) {
|
|
194
|
+
errors.push({
|
|
195
|
+
message: `Path parameter '${param.name}' must be required`,
|
|
196
|
+
path: `${paramPath}/required`,
|
|
197
|
+
code: 'PATH_PARAMETER_NOT_REQUIRED',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (!param.schema && !param.content) {
|
|
201
|
+
errors.push({
|
|
202
|
+
message: `Parameter '${param.name}' missing schema or content`,
|
|
203
|
+
path: `${paramPath}`,
|
|
204
|
+
code: 'MISSING_PARAMETER_SCHEMA',
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.Validator = Validator;
|
|
211
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AG,SAAS,KAAK;oBACvB,IAAI,EAAE,sBAAsB;iBAC7B,CAAC,CAAC;YACL,CAAC;iBAAM,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;gBACrE,MAAM,CAAC,IAAI,CAAC;oBACV,OAAO,EAAE,+BAA+B,KAAK,CAAC,EAAE,EAAE;oBAClD,IAAI,EAAE,GAAG,SAAS,KAAK;oBACvB,IAAI,EAAE,sBAAsB;iBAC7B,CAAC,CAAC;YACL,CAAC;YAED,IAAI,KAAK,CAAC,EAAE,KAAK,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAC3C,MAAM,CAAC,IAAI,CAAC;oBACV,OAAO,EAAE,mBAAmB,KAAK,CAAC,IAAI,oBAAoB;oBAC1D,IAAI,EAAE,GAAG,SAAS,WAAW;oBAC7B,IAAI,EAAE,6BAA6B;iBACpC,CAAC,CAAC;YACL,CAAC;YAED,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACpC,MAAM,CAAC,IAAI,CAAC;oBACV,OAAO,EAAE,cAAc,KAAK,CAAC,IAAI,6BAA6B;oBAC9D,IAAI,EAAE,GAAG,SAAS,EAAE;oBACpB,IAAI,EAAE,0BAA0B;iBACjC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA/OD,8BA+OC","sourcesContent":["import type { OpenAPIDocument, ValidationResult, ValidationErrorDetail, ValidationWarning } from './types';\nimport { ValidationError } from './errors';\n\n/**\n * Validates OpenAPI documents\n */\nexport class Validator {\n /**\n * Validate an OpenAPI document\n */\n async validate(document: OpenAPIDocument): Promise<ValidationResult> {\n const errors: ValidationErrorDetail[] = [];\n const warnings: ValidationWarning[] = [];\n\n // Check OpenAPI version\n if (!document.openapi) {\n errors.push({\n message: 'Missing required field: openapi',\n path: '/openapi',\n code: 'MISSING_OPENAPI_VERSION',\n });\n } else if (!this.isValidOpenAPIVersion(document.openapi)) {\n errors.push({\n message: `Unsupported OpenAPI version: ${document.openapi}. Expected 3.0.x or 3.1.x`,\n path: '/openapi',\n code: 'INVALID_OPENAPI_VERSION',\n });\n }\n\n // Check info\n if (!document.info) {\n errors.push({\n message: 'Missing required field: info',\n path: '/info',\n code: 'MISSING_INFO',\n });\n } else {\n if (!document.info.title) {\n errors.push({\n message: 'Missing required field: info.title',\n path: '/info/title',\n code: 'MISSING_TITLE',\n });\n }\n if (!document.info.version) {\n errors.push({\n message: 'Missing required field: info.version',\n path: '/info/version',\n code: 'MISSING_VERSION',\n });\n }\n }\n\n // Check paths\n if (!document.paths || Object.keys(document.paths).length === 0) {\n warnings.push({\n message: 'No paths defined in OpenAPI document',\n path: '/paths',\n code: 'NO_PATHS',\n });\n } else {\n this.validatePaths(document.paths, errors, warnings);\n }\n\n // Check servers\n if (!document.servers || document.servers.length === 0) {\n warnings.push({\n message: 'No servers defined. You may need to provide a baseUrl option.',\n path: '/servers',\n code: 'NO_SERVERS',\n });\n }\n\n // Check security schemes\n if (document.security && !document.components?.securitySchemes) {\n warnings.push({\n message: 'Security requirements defined but no security schemes found',\n path: '/security',\n code: 'NO_SECURITY_SCHEMES',\n });\n }\n\n return {\n valid: errors.length === 0,\n errors: errors.length > 0 ? errors : undefined,\n warnings: warnings.length > 0 ? warnings : undefined,\n };\n }\n\n /**\n * Check if OpenAPI version is valid\n */\n private isValidOpenAPIVersion(version: string): boolean {\n return /^3\\.[01]\\.\\d+$/.test(version);\n }\n\n /**\n * Validate paths\n */\n private validatePaths(\n paths: Record<string, any>,\n errors: ValidationErrorDetail[],\n warnings: ValidationWarning[],\n ): void {\n for (const [path, pathItem] of Object.entries(paths)) {\n if (!pathItem) continue;\n\n // Check path format\n if (!path.startsWith('/')) {\n errors.push({\n message: `Path must start with '/': ${path}`,\n path: `/paths/${path}`,\n code: 'INVALID_PATH_FORMAT',\n });\n }\n\n // Validate operations\n const methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace'];\n let hasOperations = false;\n\n for (const method of methods) {\n const operation = pathItem[method];\n if (operation) {\n hasOperations = true;\n this.validateOperation(operation, path, method, errors, warnings);\n }\n }\n\n if (!hasOperations && !pathItem.$ref) {\n warnings.push({\n message: `Path has no operations: ${path}`,\n path: `/paths/${path}`,\n code: 'NO_OPERATIONS',\n });\n }\n }\n }\n\n /**\n * Validate an operation\n */\n private validateOperation(\n operation: any,\n path: string,\n method: string,\n errors: ValidationErrorDetail[],\n warnings: ValidationWarning[],\n ): void {\n const basePath = `/paths/${path}/${method}`;\n\n // Check for operationId\n if (!operation.operationId) {\n warnings.push({\n message: `Operation missing operationId: ${method.toUpperCase()} ${path}`,\n path: `${basePath}/operationId`,\n code: 'NO_OPERATION_ID',\n });\n }\n\n // Check for responses\n if (!operation.responses || Object.keys(operation.responses).length === 0) {\n errors.push({\n message: `Operation missing responses: ${method.toUpperCase()} ${path}`,\n path: `${basePath}/responses`,\n code: 'NO_RESPONSES',\n });\n }\n\n // Validate parameters\n if (operation.parameters) {\n this.validateParameters(operation.parameters, path, method, errors, warnings);\n }\n\n // Check for path parameters in path string\n const pathParams = path.match(/\\{([^}]+)\\}/g)?.map((p) => p.slice(1, -1)) ?? [];\n const definedPathParams = new Set(\n operation.parameters?.filter((p: any) => p.in === 'path').map((p: any) => p.name) ?? [],\n );\n\n for (const param of pathParams) {\n if (!definedPathParams.has(param)) {\n errors.push({\n message: `Path parameter '${param}' not defined in parameters: ${method.toUpperCase()} ${path}`,\n path: `${basePath}/parameters`,\n code: 'MISSING_PATH_PARAMETER',\n });\n }\n }\n }\n\n /**\n * Validate parameters\n */\n private validateParameters(\n parameters: any[],\n path: string,\n method: string,\n errors: ValidationErrorDetail[],\n warnings: ValidationWarning[],\n ): void {\n const basePath = `/paths/${path}/${method}/parameters`;\n\n for (let i = 0; i < parameters.length; i++) {\n const param = parameters[i];\n const paramPath = `${basePath}/${i}`;\n\n if (!param.name) {\n errors.push({\n message: 'Parameter missing name',\n path: `${paramPath}/name`,\n code: 'MISSING_PARAMETER_NAME',\n });\n }\n\n if (!param.in) {\n errors.push({\n message: 'Parameter missing \"in\" field',\n path: `${paramPath}/in`,\n code: 'MISSING_PARAMETER_IN',\n });\n } else if (!['path', 'query', 'header', 'cookie'].includes(param.in)) {\n errors.push({\n message: `Invalid parameter location: ${param.in}`,\n path: `${paramPath}/in`,\n code: 'INVALID_PARAMETER_IN',\n });\n }\n\n if (param.in === 'path' && !param.required) {\n errors.push({\n message: `Path parameter '${param.name}' must be required`,\n path: `${paramPath}/required`,\n code: 'PATH_PARAMETER_NOT_REQUIRED',\n });\n }\n\n if (!param.schema && !param.content) {\n errors.push({\n message: `Parameter '${param.name}' missing schema or content`,\n path: `${paramPath}`,\n code: 'MISSING_PARAMETER_SCHEMA',\n });\n }\n }\n }\n}\n"]}
|