Skip to main content
Glama

Carbon Voice

by PhononX
zod-schema-transformer.ts2.23 kB
// import { OpenAPIV3 } from 'openapi-types'; // import { z } from 'zod'; // function generateZodSchema(schema: OpenAPIV3.SchemaObject): z.ZodType<any> { // if (!schema) { // return z.any(); // } // switch (schema.type) { // case 'string': // return schema.enum // ? z.enum(schema.enum as [string, ...string[]]) // : z.string(); // case 'number': // case 'integer': // return z.number(); // case 'boolean': // return z.boolean(); // case 'array': // return z.array(generateZodSchema(schema.items as OpenAPIV3.SchemaObject)); // case 'object': // if (schema.properties) { // const shape: { [key: string]: z.ZodType<any> } = {}; // for (const [key, prop] of Object.entries(schema.properties)) { // const isRequired = schema.required?.includes(key); // shape[key] = isRequired // ? generateZodSchema(prop as OpenAPIV3.SchemaObject) // : generateZodSchema(prop as OpenAPIV3.SchemaObject).optional(); // } // return z.object(shape); // } // return z.record(z.any()); // default: // return z.any(); // } // } // export const transformer = async (args: any) => { // if (!args || !args.schema) { // throw new Error( // 'Transformer received undefined or missing schema! Args: ' + // JSON.stringify(args), // ); // } // const schemas: { [key: string]: z.ZodType<any> } = {}; // // Process all schemas in the OpenAPI document // if (args.schema.components?.schemas) { // for (const [name, schema] of Object.entries( // args.schema.components.schemas, // )) { // schemas[name] = generateZodSchema(schema as OpenAPIV3.SchemaObject); // } // } // // Generate the output file content // const output = `import { z } from 'zod'; // // Generated Zod schemas // ${Object.entries(schemas) // .map(([name, schema]) => `export const ${name}Schema = ${schema.toString()};`) // .join('\n')} // // Type exports // ${Object.entries(schemas) // .map(([name]) => `export type ${name} = z.infer<typeof ${name}Schema>;`) // .join('\n')} // `; // return output; // }; // export default transformer;

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PhononX/cv-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server