quickmodel / SchemaToModelService
Class: SchemaToModelService
Converts a formal schema (produced by getSchema) back into a QuickModel TypeScript class definition.
This is the inverse of QModel.getSchema():
getSchema(format)exports model structure → schemaSchemaToModelService.fromSchema(format, schema)imports schema → model class
Example
// Round-trip: model → JSON Schema → model class
const jsonSchema = User.getSchema('json');
const code = SchemaToModelService.fromSchema('json', jsonSchema, 'User');
// From a TypeScript interface string
const tsInterface = User.getSchema('typescript');
const code2 = SchemaToModelService.fromSchema('typescript', tsInterface, 'User');See
- QModel.fromSchema — static method on QModel
QFromSchemaTool— MCP tool
Constructors
Constructor
new SchemaToModelService():
SchemaToModelService
Returns
SchemaToModelService
Methods
fromSchema()
staticfromSchema<T>(format,schema,className?):string
Converts a schema (produced by getSchema) back into a QuickModel class.
Supported formats:
'json'— JSON Schema Draft-07 object (Record<string, unknown>)'openapi'— OpenAPI 3.0 component schema or full document (Record<string, unknown>)'ajv'— AJV JSON Schema object, same structure as'json''typescript'— TypeScript interface source string'graphql'— GraphQL SDLtypeblock string'prisma'— Prismamodelblock string'valibot'— Valibotv.object({…})source string'yup'— Yupyup.object({…})source string'typebox'— TypeBoxType.Object({…})source string'effect-schema'— EffectSchema.Struct({…})source string'drizzle'— DrizzlepgTable(…)source string'mongo'— Mongoose/Mongo schema object (Record<string, unknown>)'zod'— LiveZodObject<any>instance (produced bygetSchema('zod'))
Type Parameters
T
T extends IFromSchemaFormat
Parameters
format
T
Schema format (must match a supported IFromSchemaFormat value)
schema
IFromSchemaInput<T>
The schema to convert (type depends on format)
className?
string
Optional class name override. Falls back to schema name or 'GeneratedModel'.
Returns
string
TypeScript source code string for a class extending QModel.
Throws
For 'openapi': when className is not found in components.schemas.
Throws
For 'typescript': when no interface declaration is found in the source.
Throws
For 'graphql': when no type block is found in the source.
Throws
For 'prisma': when no model block is found in the source.
Throws
For 'valibot': when no v.object block is found in the source.
Throws
For 'yup': when no yup.object block is found in the source.
Throws
For 'typebox': when no Type.Object block is found in the source.
Throws
For 'effect-schema': when no Schema.Struct block is found in the source.
Throws
For 'drizzle': when no pgTable block is found in the source.