@stackone/ai
Version:
Tools for agents to perform actions on your SaaS
103 lines (102 loc) • 3.7 kB
TypeScript
import { ParameterLocation, ToolDefinition } from "../types.js";
import { JSONSchema7 } from "json-schema";
import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
//#region src/openapi/parser.d.ts
// Define a type for OpenAPI document
type OpenAPIDocument = OpenAPIV3.Document | OpenAPIV3_1.Document;
// Define a type for schema objects
type SchemaObject = OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject;
/**
* Parser for OpenAPI specifications
*/
declare class OpenAPIParser {
_spec: OpenAPIDocument;
_baseUrl: string;
private _removedParams;
/**
* Create a new OpenAPIParser
* @param spec The OpenAPI specification object
* @param customBaseUrl Optional custom base URL to use for all operations
* @param removedParams Optional array of parameter names to remove from all tools
*/
constructor(spec: OpenAPIDocument, customBaseUrl?: string, removedParams?: string[]);
/**
* Helper method to check if a parameter should be removed
*/
private isRemovedParam;
/**
* Helper method to check if a schema is deprecated
*/
private isDeprecated;
/**
* Helper method to check if a value is a non-null object
*/
private isObject;
/**
* Determine the base URL from the servers array in the OpenAPI spec
* @returns The base URL to use for all operations
*/
private determineBaseUrl;
/**
* Create a parser from a JSON string
* @param specString OpenAPI specification as a JSON string
* @param customBaseUrl Optional custom base URL to use for all tools
* @param removedParams Optional array of parameter names to remove from all tools
* @returns A new OpenAPIParser instance
*/
static fromString(specString: string, customBaseUrl?: string, removedParams?: string[]): OpenAPIParser;
/**
* Resolve a JSON schema reference in the OpenAPI spec
*/
resolveSchemaRef(ref: string, visited?: Set<string>): JSONSchema7;
/**
* Resolve all references in a schema, preserving structure
* This also filters out deprecated properties and properties in removedParams
*/
resolveSchema(schema: SchemaObject | unknown, visited?: Set<string>): JSONSchema7;
/**
* Parse content schema for a specific content type
*/
parseContentSchema(contentType: string, content: Record<string, OpenAPIV3.MediaTypeObject>): [JSONSchema7 | null, string | null];
/**
* Resolve a request body reference
*/
resolveRequestBodyRef(ref: string): OpenAPIV3.RequestBodyObject | null;
/**
* Parse request body from an operation
*/
parseRequestBody(operation: OpenAPIV3.OperationObject): [JSONSchema7 | null, string | null];
/**
* Helper method to check if an item should be skipped (removed or deprecated)
*/
private shouldSkipItem;
/**
* Get the parameter location from a property schema
* @param propSchema The schema of the property
* @returns The parameter location (HEADER, QUERY, PATH, or BODY)
*/
getParameterLocation(propSchema: OpenAPIV3.ParameterObject | Record<string, unknown>): ParameterLocation;
/**
* Filter out removed parameters from both properties and required arrays
*/
private filterRemovedParams;
/**
* Parse OpenAPI spec into tool definitions
*/
parseTools(): Record<string, ToolDefinition>;
/**
* Extract operations from a path item
*/
extractOperations(pathItem: OpenAPIV3.PathItemObject): [string, OpenAPIV3.OperationObject][];
/**
* Resolve a parameter reference
*/
resolveParameter(param: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject): OpenAPIV3.ParameterObject | null;
/**
* Get the base URL
*/
get baseUrl(): string;
}
//#endregion
export { OpenAPIParser };
//# sourceMappingURL=parser.d.ts.map