@demokit-ai/schema 0.0.1 → 0.0.2

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.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/relationships.ts","../src/parser.ts"],"names":["api"],"mappings":";;;;;AA2cO,SAAS,YAAY,KAAA,EAAoC;AAC9D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAAoB,IAAA,KAAS,QAAA;AAEzC;AAMO,SAAS,eAAe,GAAA,EAAqB;AAClD,EAAA,MAAM,KAAA,GAAQ,GAAA,CAAI,KAAA,CAAM,GAAG,CAAA;AAC3B,EAAA,OAAO,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA,IAAK,GAAA;AACpC;;;ACpcA,IAAM,iBAAA,GAAoB;AAAA;AAAA,EAExB,EAAE,OAAA,EAAS,UAAA,EAAY,WAAA,EAAa,IAAA,EAAK;AAAA,EACzC,EAAE,OAAA,EAAS,WAAA,EAAa,WAAA,EAAa,IAAA,EAAK;AAAA,EAC1C,EAAE,OAAA,EAAS,UAAA,EAAY,WAAA,EAAa,IAAA,EAAK;AAAA;AAAA,EAGzC,EAAE,OAAA,EAAS,YAAA,EAAc,WAAA,EAAa,MAAA,EAAO;AAAA,EAC7C,EAAE,OAAA,EAAS,YAAA,EAAc,WAAA,EAAa,MAAA,EAAO;AAAA,EAC7C,EAAE,OAAA,EAAS,aAAA,EAAe,WAAA,EAAa,MAAA;AACzC,CAAA;AAMA,SAAS,kBAAkB,MAAA,EAAwB;AACjD,EAAA,OAAO,MAAA,CAAO,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,MAAA,CAAO,MAAM,CAAC,CAAA;AACxD;AAKO,SAAS,4BAAA,CACd,UACA,eAAA,EAC2B;AAC3B,EAAA,MAAM,YAAY,QAAA,CAAS,IAAA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UAAU,MAAA,EAAQ;AAC9B,UAAA,WAAA,CAAY,OAAA,CAAQ,WAAW,CAAA,GAAI;AAAA,YACjC,IAAA,EAAO,UAAU,MAAA,CAA2B;AAAA,WAC9C;AAAA,QACF,CAAA,MAAO;AACL,UAAA,WAAA,CAAY,OAAA,CAAQ,WAAW,CAAA,GAAI,kBAAA;AAAA,YACjC,WAAW,UAAU,CAAA,CAAA;AAAA,YACrB,SAAA,CAAU;AAAA,WACZ;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,WAAA;AACT;AAKA,SAAS,sBACP,IAAA,EACW;AACX,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,OAAO,KAAK,CAAC,CAAA;AACtC,EAAA,OAAO,IAAA;AACT;AAKA,SAAS,yBACP,IAAA,EACc;AACd,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,OAAO,KAAK,CAAC,CAAA;AACtC,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["/**\n * Core types for DemoKit schema representation\n *\n * These types represent a parsed API schema with relationship detection,\n * independent of the source format (OpenAPI, GraphQL, etc.)\n */\n\n/**\n * The main schema representation for DemoKit\n * Contains all information needed for fixture generation\n */\nexport interface DemokitSchema {\n /**\n * Metadata about the API\n */\n info: SchemaInfo\n\n /**\n * All API endpoints discovered from the spec\n */\n endpoints: Endpoint[]\n\n /**\n * All data models (schemas) from the spec\n */\n models: Record<string, DataModel>\n\n /**\n * Detected relationships between models\n */\n relationships: Relationship[]\n}\n\n/**\n * API metadata\n */\nexport interface SchemaInfo {\n /**\n * API title from the spec\n */\n title: string\n\n /**\n * API version\n */\n version: string\n\n /**\n * Optional description\n */\n description?: string\n\n /**\n * Base URL for the API (if specified)\n */\n baseUrl?: string\n}\n\n/**\n * An API endpoint\n */\nexport interface Endpoint {\n /**\n * HTTP method (GET, POST, PUT, PATCH, DELETE)\n */\n method: HttpMethod\n\n /**\n * URL path with parameter placeholders\n * @example \"/users/{id}\" or \"/orders/{orderId}/items\"\n */\n path: string\n\n /**\n * Operation ID from OpenAPI (if available)\n */\n operationId?: string\n\n /**\n * Human-readable summary\n */\n summary?: string\n\n /**\n * Detailed description\n */\n description?: string\n\n /**\n * Path parameters\n */\n pathParams: ParameterDef[]\n\n /**\n * Query parameters\n */\n queryParams: ParameterDef[]\n\n /**\n * Request body schema (for POST/PUT/PATCH)\n */\n requestBody?: RequestBody\n\n /**\n * Response schemas by status code\n */\n responses: Record<string, ResponseDef>\n\n /**\n * Tags for grouping endpoints\n */\n tags: string[]\n}\n\n/**\n * HTTP methods supported\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'\n\n/**\n * A request or response body definition\n */\nexport interface RequestBody {\n /**\n * Content type (usually application/json)\n */\n contentType: string\n\n /**\n * Reference to the model name, or inline schema\n */\n schema: SchemaRef | DataModel\n\n /**\n * Whether the body is required\n */\n required: boolean\n\n /**\n * Description of the body\n */\n description?: string\n}\n\n/**\n * A response definition\n */\nexport interface ResponseDef {\n /**\n * HTTP status code\n */\n statusCode: string\n\n /**\n * Description of the response\n */\n description?: string\n\n /**\n * Content type to schema mapping\n */\n content?: Record<string, SchemaRef | DataModel>\n}\n\n/**\n * A parameter definition (path or query)\n */\nexport interface ParameterDef {\n /**\n * Parameter name\n */\n name: string\n\n /**\n * Where the parameter is located\n */\n in: 'path' | 'query' | 'header' | 'cookie'\n\n /**\n * Whether the parameter is required\n */\n required: boolean\n\n /**\n * Parameter type\n */\n type: PropertyType\n\n /**\n * Optional format hint\n */\n format?: string\n\n /**\n * Description\n */\n description?: string\n\n /**\n * Example value\n */\n example?: unknown\n}\n\n/**\n * Reference to another schema/model\n */\nexport interface SchemaRef {\n /**\n * The referenced model name\n */\n $ref: string\n}\n\n/**\n * A data model representing an object schema\n */\nexport interface DataModel {\n /**\n * Model name (from the schema component name)\n */\n name: string\n\n /**\n * The type of this model\n */\n type: ModelType\n\n /**\n * Description from the spec\n */\n description?: string\n\n /**\n * Properties for object types\n */\n properties?: Record<string, PropertyDef>\n\n /**\n * Required property names\n */\n required?: string[]\n\n /**\n * For array types, the item schema\n */\n items?: SchemaRef | DataModel\n\n /**\n * Enum values for enum types\n */\n enum?: unknown[]\n\n /**\n * Example value from the spec\n */\n example?: unknown\n\n /**\n * Additional properties schema (for dictionaries)\n */\n additionalProperties?: boolean | SchemaRef | DataModel\n}\n\n/**\n * Model types\n */\nexport type ModelType = 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null'\n\n/**\n * A property definition within a model\n */\nexport interface PropertyDef {\n /**\n * Property name\n */\n name: string\n\n /**\n * Property type\n */\n type: PropertyType\n\n /**\n * Format hint (uuid, email, date-time, etc.)\n */\n format?: string\n\n /**\n * Description\n */\n description?: string\n\n /**\n * Whether this property is required\n */\n required?: boolean\n\n /**\n * Whether this property is nullable\n */\n nullable?: boolean\n\n /**\n * Enum values for string enums\n */\n enum?: unknown[]\n\n /**\n * For array types, the item schema\n */\n items?: SchemaRef | DataModel\n\n /**\n * Reference to another model (for $ref properties)\n */\n $ref?: string\n\n /**\n * Example value\n */\n example?: unknown\n\n /**\n * Default value\n */\n default?: unknown\n\n /**\n * Minimum value (for numbers)\n */\n minimum?: number\n\n /**\n * Maximum value (for numbers)\n */\n maximum?: number\n\n /**\n * Min length (for strings)\n */\n minLength?: number\n\n /**\n * Max length (for strings)\n */\n maxLength?: number\n\n /**\n * Pattern (regex for strings)\n */\n pattern?: string\n\n /**\n * Detected relationship to another model\n * Set by relationship detection, not directly from spec\n */\n relationshipTo?: RelationshipTarget\n\n /**\n * Custom extension for explicit relationship hints\n * @example \"x-demokit-relationship\": { \"model\": \"User\", \"field\": \"id\" }\n */\n 'x-demokit-relationship'?: RelationshipTarget\n}\n\n/**\n * Property types\n */\nexport type PropertyType =\n | 'string'\n | 'number'\n | 'integer'\n | 'boolean'\n | 'array'\n | 'object'\n | 'null'\n\n/**\n * A detected relationship between two models\n */\nexport interface Relationship {\n /**\n * The source side of the relationship\n */\n from: RelationshipSide\n\n /**\n * The target side of the relationship\n */\n to: RelationshipSide\n\n /**\n * Type of relationship\n */\n type: RelationshipType\n\n /**\n * Whether the relationship is required (not nullable)\n */\n required: boolean\n\n /**\n * How this relationship was detected\n */\n detectedBy: RelationshipDetectionMethod\n}\n\n/**\n * One side of a relationship\n */\nexport interface RelationshipSide {\n /**\n * Model name\n */\n model: string\n\n /**\n * Field name\n */\n field: string\n}\n\n/**\n * Target for a relationship from a property\n */\nexport interface RelationshipTarget {\n /**\n * Target model name\n */\n model: string\n\n /**\n * Target field (usually \"id\")\n */\n field: string\n}\n\n/**\n * Types of relationships between models\n */\nexport type RelationshipType =\n | 'one-to-one'\n | 'one-to-many'\n | 'many-to-one'\n | 'many-to-many'\n\n/**\n * How a relationship was detected\n */\nexport type RelationshipDetectionMethod =\n | 'explicit-ref' // OpenAPI $ref\n | 'naming-convention' // userId -> User.id pattern\n | 'x-demokit-extension' // x-demokit-relationship extension\n | 'inferred' // AI or heuristic inference\n\n/**\n * Helper type to check if something is a schema reference\n */\nexport function isSchemaRef(value: unknown): value is SchemaRef {\n return (\n typeof value === 'object' &&\n value !== null &&\n '$ref' in value &&\n typeof (value as SchemaRef).$ref === 'string'\n )\n}\n\n/**\n * Extract the model name from a $ref string\n * @example \"#/components/schemas/User\" -> \"User\"\n */\nexport function extractRefName(ref: string): string {\n const parts = ref.split('/')\n return parts[parts.length - 1] ?? ref\n}\n","/**\n * Relationship detection for DemoKit schemas\n *\n * Detects relationships between models using:\n * 1. Explicit $ref references in OpenAPI\n * 2. Naming conventions (userId -> User.id)\n * 3. x-demokit-relationship extension\n */\n\nimport type {\n DataModel,\n PropertyDef,\n Relationship,\n RelationshipTarget,\n RelationshipDetectionMethod,\n RelationshipType,\n} from './types'\nimport { isSchemaRef, extractRefName } from './types'\n\n/**\n * Common ID field naming patterns\n * Maps suffix patterns to implied relationships\n */\nconst ID_FIELD_PATTERNS = [\n // Standard patterns: userId -> User, customerId -> Customer\n { pattern: /^(.+)Id$/, targetField: 'id' },\n { pattern: /^(.+)_id$/, targetField: 'id' },\n { pattern: /^(.+)ID$/, targetField: 'id' },\n\n // UUID patterns: userUuid -> User, customerUUID -> Customer\n { pattern: /^(.+)Uuid$/, targetField: 'uuid' },\n { pattern: /^(.+)UUID$/, targetField: 'uuid' },\n { pattern: /^(.+)_uuid$/, targetField: 'uuid' },\n]\n\n/**\n * Convert a field name prefix to a model name\n * @example \"user\" -> \"User\", \"orderItem\" -> \"OrderItem\"\n */\nfunction prefixToModelName(prefix: string): string {\n return prefix.charAt(0).toUpperCase() + prefix.slice(1)\n}\n\n/**\n * Check if a property looks like a foreign key based on naming conventions\n */\nexport function detectRelationshipFromNaming(\n property: PropertyDef,\n availableModels: Set<string>\n): RelationshipTarget | null {\n const fieldName = property.name\n\n for (const { pattern, targetField } of ID_FIELD_PATTERNS) {\n const match = fieldName.match(pattern)\n if (match && match[1]) {\n const prefix = match[1]\n const modelName = prefixToModelName(prefix)\n\n // Check if this model exists in the schema\n if (availableModels.has(modelName)) {\n return { model: modelName, field: targetField }\n }\n\n // Also check for plural forms\n const pluralModel = modelName + 's'\n if (availableModels.has(pluralModel)) {\n return { model: pluralModel, field: targetField }\n }\n }\n }\n\n return null\n}\n\n/**\n * Check if a property has an explicit x-demokit-relationship extension\n */\nexport function detectRelationshipFromExtension(\n property: PropertyDef\n): RelationshipTarget | null {\n const extension = property['x-demokit-relationship']\n if (extension && typeof extension === 'object') {\n return {\n model: extension.model,\n field: extension.field || 'id',\n }\n }\n return null\n}\n\n/**\n * Check if a property is a $ref to another model\n */\nexport function detectRelationshipFromRef(\n property: PropertyDef,\n availableModels: Set<string>\n): RelationshipTarget | null {\n if (property.$ref) {\n const modelName = extractRefName(property.$ref)\n if (availableModels.has(modelName)) {\n return { model: modelName, field: 'id' }\n }\n }\n\n // Check if items is a $ref (for arrays of references)\n if (property.items && isSchemaRef(property.items)) {\n const modelName = extractRefName(property.items.$ref)\n if (availableModels.has(modelName)) {\n return { model: modelName, field: 'id' }\n }\n }\n\n return null\n}\n\n/**\n * Detect the relationship type based on property and target\n */\nfunction determineRelationshipType(\n property: PropertyDef,\n _fromModel: DataModel\n): RelationshipType {\n // If the property is an array, it's one-to-many or many-to-many\n if (property.type === 'array') {\n // For simplicity, treat array references as one-to-many\n // (the \"one\" side has the array of references)\n return 'one-to-many'\n }\n\n // Single reference is many-to-one (many records can reference one target)\n return 'many-to-one'\n}\n\n/**\n * Detect all relationships in a set of models\n */\nexport function detectRelationships(\n models: Record<string, DataModel>\n): Relationship[] {\n const relationships: Relationship[] = []\n const availableModels = new Set(Object.keys(models))\n\n for (const [modelName, model] of Object.entries(models)) {\n if (!model.properties) continue\n\n for (const [propName, property] of Object.entries(model.properties)) {\n let target: RelationshipTarget | null = null\n let detectionMethod: RelationshipDetectionMethod = 'inferred'\n\n // Priority 1: Explicit x-demokit-relationship extension\n target = detectRelationshipFromExtension(property)\n if (target) {\n detectionMethod = 'x-demokit-extension'\n }\n\n // Priority 2: $ref references\n if (!target) {\n target = detectRelationshipFromRef(property, availableModels)\n if (target) {\n detectionMethod = 'explicit-ref'\n }\n }\n\n // Priority 3: Naming conventions\n if (!target) {\n target = detectRelationshipFromNaming(property, availableModels)\n if (target) {\n detectionMethod = 'naming-convention'\n }\n }\n\n if (target) {\n // Don't create self-referential relationships for simple IDs\n if (target.model === modelName && target.field === 'id' && propName === 'id') {\n continue\n }\n\n // Add the detected relationship info to the property\n property.relationshipTo = target\n\n relationships.push({\n from: { model: modelName, field: propName },\n to: target,\n type: determineRelationshipType(property, model),\n required: property.required ?? false,\n detectedBy: detectionMethod,\n })\n }\n }\n }\n\n return relationships\n}\n\n/**\n * Find all relationships for a specific model\n */\nexport function getRelationshipsForModel(\n modelName: string,\n relationships: Relationship[]\n): {\n outgoing: Relationship[]\n incoming: Relationship[]\n} {\n return {\n outgoing: relationships.filter(r => r.from.model === modelName),\n incoming: relationships.filter(r => r.to.model === modelName),\n }\n}\n\n/**\n * Check if a model is referenced by other models\n */\nexport function isModelReferenced(\n modelName: string,\n relationships: Relationship[]\n): boolean {\n return relationships.some(r => r.to.model === modelName)\n}\n\n/**\n * Get the dependency order for models based on relationships\n * Returns models in order such that dependencies come before dependents\n */\nexport function getModelDependencyOrder(\n models: Record<string, DataModel>,\n relationships: Relationship[]\n): string[] {\n const modelNames = Object.keys(models)\n const visited = new Set<string>()\n const order: string[] = []\n\n function visit(name: string, path: Set<string> = new Set()) {\n if (visited.has(name)) return\n if (path.has(name)) {\n // Circular dependency - skip to break the cycle\n return\n }\n\n path.add(name)\n\n // Visit all models that this model depends on first\n const deps = relationships\n .filter(r => r.from.model === name)\n .map(r => r.to.model)\n .filter(dep => modelNames.includes(dep))\n\n for (const dep of deps) {\n visit(dep, new Set(path))\n }\n\n if (!visited.has(name)) {\n visited.add(name)\n order.push(name)\n }\n }\n\n for (const name of modelNames) {\n visit(name)\n }\n\n return order\n}\n","/**\n * OpenAPI 3.x parser for DemoKit\n *\n * Parses OpenAPI specs into DemoKit's internal schema representation\n * with automatic relationship detection.\n */\n\nimport SwaggerParser from '@apidevtools/swagger-parser'\nimport type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\nimport type {\n DemokitSchema,\n SchemaInfo,\n Endpoint,\n DataModel,\n PropertyDef,\n HttpMethod,\n ParameterDef,\n RequestBody,\n ResponseDef,\n PropertyType,\n ModelType,\n} from './types'\n// extractRefName is used in relationships.ts, re-exported from index.ts\nimport { detectRelationships } from './relationships'\n\ntype OpenAPIDocument = OpenAPIV3.Document | OpenAPIV3_1.Document\ntype SchemaObject = OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject\ntype ReferenceObject = OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject\ntype ParameterObject = OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject\ntype RequestBodyObject = OpenAPIV3.RequestBodyObject | OpenAPIV3_1.RequestBodyObject\ntype ResponseObject = OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject\ntype MediaTypeObject = OpenAPIV3.MediaTypeObject | OpenAPIV3_1.MediaTypeObject\n\n/**\n * Options for parsing OpenAPI specs\n */\nexport interface ParseOptions {\n /**\n * Whether to dereference all $ref pointers\n * @default true\n */\n dereference?: boolean\n\n /**\n * Whether to detect relationships automatically\n * @default true\n */\n detectRelationships?: boolean\n\n /**\n * Whether to include response schemas in models\n * @default true\n */\n includeResponses?: boolean\n}\n\n/**\n * Parse an OpenAPI spec from a file path or URL\n */\nexport async function parseOpenAPIFromPath(\n pathOrUrl: string,\n options: ParseOptions = {}\n): Promise<DemokitSchema> {\n const { dereference = true } = options\n\n let api: OpenAPI.Document\n\n if (dereference) {\n api = await SwaggerParser.dereference(pathOrUrl)\n } else {\n api = await SwaggerParser.parse(pathOrUrl)\n }\n\n return parseOpenAPIDocument(api as OpenAPIDocument, options)\n}\n\n/**\n * Parse an OpenAPI spec from a string (JSON or YAML)\n */\nexport async function parseOpenAPIFromString(\n spec: string,\n options: ParseOptions = {}\n): Promise<DemokitSchema> {\n const { dereference = true } = options\n\n // Parse the string as JSON or YAML\n let parsed: unknown\n try {\n parsed = JSON.parse(spec)\n } catch {\n // If JSON parse fails, try YAML via SwaggerParser\n const api = await SwaggerParser.parse(spec as unknown as string)\n if (dereference) {\n return parseOpenAPIDocument(\n (await SwaggerParser.dereference(api)) as OpenAPIDocument,\n options\n )\n }\n return parseOpenAPIDocument(api as OpenAPIDocument, options)\n }\n\n let api: OpenAPI.Document\n if (dereference) {\n api = await SwaggerParser.dereference(parsed as OpenAPI.Document)\n } else {\n api = await SwaggerParser.validate(parsed as OpenAPI.Document)\n }\n\n return parseOpenAPIDocument(api as OpenAPIDocument, options)\n}\n\n/**\n * Parse an OpenAPI spec from an already-parsed object\n */\nexport async function parseOpenAPIFromObject(\n spec: Record<string, unknown>,\n options: ParseOptions = {}\n): Promise<DemokitSchema> {\n const { dereference = true } = options\n\n let api: OpenAPI.Document\n if (dereference) {\n api = await SwaggerParser.dereference(spec as OpenAPI.Document)\n } else {\n api = await SwaggerParser.validate(spec as OpenAPI.Document)\n }\n\n return parseOpenAPIDocument(api as OpenAPIDocument, options)\n}\n\n/**\n * Parse an OpenAPI document into DemokitSchema\n */\nfunction parseOpenAPIDocument(\n doc: OpenAPIDocument,\n options: ParseOptions = {}\n): DemokitSchema {\n const { detectRelationships: shouldDetect = true } = options\n\n // Parse info\n const info = parseInfo(doc)\n\n // Parse models from components/schemas\n const models = parseModels(doc)\n\n // Parse endpoints from paths\n const endpoints = parseEndpoints(doc)\n\n // Detect relationships\n const relationships = shouldDetect ? detectRelationships(models) : []\n\n return {\n info,\n endpoints,\n models,\n relationships,\n }\n}\n\n/**\n * Parse API info from the document\n */\nfunction parseInfo(doc: OpenAPIDocument): SchemaInfo {\n const info: SchemaInfo = {\n title: doc.info?.title ?? 'Untitled API',\n version: doc.info?.version ?? '1.0.0',\n description: doc.info?.description,\n }\n\n // Try to extract base URL from servers\n if (doc.servers && doc.servers.length > 0 && doc.servers[0]) {\n info.baseUrl = doc.servers[0].url\n }\n\n return info\n}\n\n/**\n * Parse all models from components/schemas\n */\nfunction parseModels(doc: OpenAPIDocument): Record<string, DataModel> {\n const models: Record<string, DataModel> = {}\n\n const schemas = doc.components?.schemas\n if (!schemas) {\n return models\n }\n\n for (const [name, schema] of Object.entries(schemas)) {\n // Skip reference objects (shouldn't happen after dereference)\n if ('$ref' in schema) {\n continue\n }\n\n models[name] = parseSchemaToModel(name, schema as SchemaObject)\n }\n\n return models\n}\n\n/**\n * Parse a schema object into a DataModel\n */\nfunction parseSchemaToModel(name: string, schema: SchemaObject): DataModel {\n const model: DataModel = {\n name,\n type: schemaTypeToModelType(schema.type),\n description: schema.description,\n }\n\n // Parse properties for object types\n if (schema.type === 'object' || schema.properties) {\n model.type = 'object'\n model.properties = {}\n model.required = schema.required || []\n\n if (schema.properties) {\n for (const [propName, propSchema] of Object.entries(schema.properties)) {\n model.properties[propName] = parseProperty(\n propName,\n propSchema as SchemaObject | ReferenceObject,\n model.required.includes(propName)\n )\n }\n }\n\n if (schema.additionalProperties !== undefined) {\n if (typeof schema.additionalProperties === 'boolean') {\n model.additionalProperties = schema.additionalProperties\n } else if ('$ref' in schema.additionalProperties) {\n model.additionalProperties = {\n $ref: (schema.additionalProperties as ReferenceObject).$ref,\n }\n } else {\n model.additionalProperties = parseSchemaToModel(\n `${name}AdditionalProps`,\n schema.additionalProperties as SchemaObject\n )\n }\n }\n }\n\n // Parse array items\n if (schema.type === 'array' && schema.items) {\n model.type = 'array'\n if ('$ref' in schema.items) {\n model.items = { $ref: (schema.items as ReferenceObject).$ref }\n } else {\n model.items = parseSchemaToModel(`${name}Item`, schema.items as SchemaObject)\n }\n }\n\n // Parse enum values\n if (schema.enum) {\n model.enum = schema.enum\n }\n\n // Parse example\n if (schema.example !== undefined) {\n model.example = schema.example\n }\n\n return model\n}\n\n/**\n * Parse a property schema into a PropertyDef\n */\nfunction parseProperty(\n name: string,\n schema: SchemaObject | ReferenceObject,\n required: boolean\n): PropertyDef {\n // Handle $ref\n if ('$ref' in schema) {\n return {\n name,\n type: 'object',\n required,\n $ref: schema.$ref,\n }\n }\n\n const prop: PropertyDef = {\n name,\n type: schemaTypeToPropertyType(schema.type),\n required,\n nullable: (schema as Record<string, unknown>).nullable as boolean | undefined,\n description: schema.description,\n format: schema.format,\n enum: schema.enum,\n example: schema.example,\n default: schema.default,\n minimum: schema.minimum,\n maximum: schema.maximum,\n minLength: schema.minLength,\n maxLength: schema.maxLength,\n pattern: schema.pattern,\n }\n\n // Parse array items\n if (schema.type === 'array' && schema.items) {\n prop.type = 'array'\n if ('$ref' in schema.items) {\n prop.items = { $ref: (schema.items as ReferenceObject).$ref }\n } else {\n prop.items = parseSchemaToModel(`${name}Item`, schema.items as SchemaObject)\n }\n }\n\n // Check for x-demokit-relationship extension\n const xRelationship = (schema as Record<string, unknown>)['x-demokit-relationship']\n if (xRelationship && typeof xRelationship === 'object') {\n prop['x-demokit-relationship'] = xRelationship as { model: string; field: string }\n }\n\n return prop\n}\n\n/**\n * Parse all endpoints from paths\n */\nfunction parseEndpoints(doc: OpenAPIDocument): Endpoint[] {\n const endpoints: Endpoint[] = []\n\n if (!doc.paths) {\n return endpoints\n }\n\n const methods: HttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']\n\n for (const [path, pathItem] of Object.entries(doc.paths)) {\n if (!pathItem) continue\n\n for (const method of methods) {\n const operation = pathItem[method.toLowerCase() as keyof typeof pathItem] as\n | OpenAPIV3.OperationObject\n | OpenAPIV3_1.OperationObject\n | undefined\n\n if (!operation) continue\n\n endpoints.push(parseEndpoint(method, path, operation, pathItem))\n }\n }\n\n return endpoints\n}\n\n/**\n * Parse a single endpoint\n */\nfunction parseEndpoint(\n method: HttpMethod,\n path: string,\n operation: OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject,\n pathItem: OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject\n): Endpoint {\n // Combine path-level and operation-level parameters\n const allParams = [...(pathItem.parameters || []), ...(operation.parameters || [])]\n\n const pathParams: ParameterDef[] = []\n const queryParams: ParameterDef[] = []\n\n for (const param of allParams) {\n if ('$ref' in param) continue // Skip refs\n const paramObj = param as ParameterObject\n const parsed = parseParameter(paramObj)\n\n if (parsed.in === 'path') {\n pathParams.push(parsed)\n } else if (parsed.in === 'query') {\n queryParams.push(parsed)\n }\n }\n\n // Parse request body\n let requestBody: RequestBody | undefined\n if (operation.requestBody && !('$ref' in operation.requestBody)) {\n requestBody = parseRequestBody(operation.requestBody as RequestBodyObject)\n }\n\n // Parse responses\n const responses: Record<string, ResponseDef> = {}\n if (operation.responses) {\n for (const [statusCode, response] of Object.entries(operation.responses)) {\n if ('$ref' in response) continue\n responses[statusCode] = parseResponse(statusCode, response as ResponseObject)\n }\n }\n\n return {\n method,\n path,\n operationId: operation.operationId,\n summary: operation.summary,\n description: operation.description,\n pathParams,\n queryParams,\n requestBody,\n responses,\n tags: operation.tags || [],\n }\n}\n\n/**\n * Parse a parameter object\n */\nfunction parseParameter(param: ParameterObject): ParameterDef {\n const schema = param.schema as SchemaObject | undefined\n\n return {\n name: param.name,\n in: param.in as 'path' | 'query' | 'header' | 'cookie',\n required: param.required ?? false,\n type: schema ? schemaTypeToPropertyType(schema.type) : 'string',\n format: schema?.format,\n description: param.description,\n example: param.example ?? schema?.example,\n }\n}\n\n/**\n * Parse a request body object\n */\nfunction parseRequestBody(body: RequestBodyObject): RequestBody {\n const contentType = Object.keys(body.content || {})[0] || 'application/json'\n const mediaType = body.content?.[contentType] as MediaTypeObject | undefined\n\n let schema: RequestBody['schema'] = { name: 'Unknown', type: 'object' }\n\n if (mediaType?.schema) {\n if ('$ref' in mediaType.schema) {\n schema = { $ref: (mediaType.schema as ReferenceObject).$ref }\n } else {\n schema = parseSchemaToModel('RequestBody', mediaType.schema as SchemaObject)\n }\n }\n\n return {\n contentType,\n schema,\n required: body.required ?? false,\n description: body.description,\n }\n}\n\n/**\n * Parse a response object\n */\nfunction parseResponse(statusCode: string, response: ResponseObject): ResponseDef {\n const responseDef: ResponseDef = {\n statusCode,\n description: response.description,\n }\n\n if (response.content) {\n responseDef.content = {}\n\n for (const [contentType, mediaType] of Object.entries(response.content)) {\n if (mediaType.schema) {\n if ('$ref' in mediaType.schema) {\n responseDef.content[contentType] = {\n $ref: (mediaType.schema as ReferenceObject).$ref,\n }\n } else {\n responseDef.content[contentType] = parseSchemaToModel(\n `Response${statusCode}`,\n mediaType.schema as SchemaObject\n )\n }\n }\n }\n }\n\n return responseDef\n}\n\n/**\n * Convert OpenAPI schema type to ModelType\n */\nfunction schemaTypeToModelType(\n type: string | string[] | undefined\n): ModelType {\n if (!type) return 'object'\n if (Array.isArray(type)) return type[0] as ModelType\n return type as ModelType\n}\n\n/**\n * Convert OpenAPI schema type to PropertyType\n */\nfunction schemaTypeToPropertyType(\n type: string | string[] | undefined\n): PropertyType {\n if (!type) return 'object'\n if (Array.isArray(type)) return type[0] as PropertyType\n return type as PropertyType\n}\n"]}
1
+ {"version":3,"sources":["../src/types.ts","../src/relationships.ts","../src/parser.ts"],"names":[],"mappings":";;;;;AA2cO,SAAS,YAAY,KAAA,EAAoC;AAC9D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAAoB,IAAA,KAAS,QAAA;AAEzC;AAMO,SAAS,eAAe,GAAA,EAAqB;AAClD,EAAA,MAAM,KAAA,GAAQ,GAAA,CAAI,KAAA,CAAM,GAAG,CAAA;AAC3B,EAAA,OAAO,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA,IAAK,GAAA;AACpC;;;ACpcA,IAAM,iBAAA,GAAoB;AAAA;AAAA,EAExB,EAAE,OAAA,EAAS,UAAA,EAAY,WAAA,EAAa,IAAA,EAAK;AAAA,EACzC,EAAE,OAAA,EAAS,WAAA,EAAa,WAAA,EAAa,IAAA,EAAK;AAAA,EAC1C,EAAE,OAAA,EAAS,UAAA,EAAY,WAAA,EAAa,IAAA,EAAK;AAAA;AAAA,EAGzC,EAAE,OAAA,EAAS,YAAA,EAAc,WAAA,EAAa,MAAA,EAAO;AAAA,EAC7C,EAAE,OAAA,EAAS,YAAA,EAAc,WAAA,EAAa,MAAA,EAAO;AAAA,EAC7C,EAAE,OAAA,EAAS,aAAA,EAAe,WAAA,EAAa,MAAA;AACzC,CAAA;AAMA,SAAS,kBAAkB,MAAA,EAAwB;AACjD,EAAA,OAAO,MAAA,CAAO,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,MAAA,CAAO,MAAM,CAAC,CAAA;AACxD;AAKO,SAAS,4BAAA,CACd,UACA,eAAA,EAC2B;AAC3B,EAAA,MAAM,YAAY,Q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A,WACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,WAAA;AACT;AAKA,SAAS,sBACP,IAAA,EACW;AACX,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,OAAO,KAAK,CAAC,CAAA;AACtC,EAAA,OAAO,IAAA;AACT;AAKA,SAAS,yBACP,IAAA,EACc;AACd,EAAA,IAAI,CAAC,MAAM,OAAO,QAAA;AAClB,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,OAAO,KAAK,CAAC,CAAA;AACtC,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["/**\n * Core types for DemoKit schema representation\n *\n * These types represent a parsed API schema with relationship detection,\n * independent of the source format (OpenAPI, GraphQL, etc.)\n */\n\n/**\n * The main schema representation for DemoKit\n * Contains all information needed for fixture generation\n */\nexport interface DemokitSchema {\n /**\n * Metadata about the API\n */\n info: SchemaInfo\n\n /**\n * All API endpoints discovered from the spec\n */\n endpoints: Endpoint[]\n\n /**\n * All data models (schemas) from the spec\n */\n models: Record<string, DataModel>\n\n /**\n * Detected relationships between models\n */\n relationships: Relationship[]\n}\n\n/**\n * API metadata\n */\nexport interface SchemaInfo {\n /**\n * API title from the spec\n */\n title: string\n\n /**\n * API version\n */\n version: string\n\n /**\n * Optional description\n */\n description?: string\n\n /**\n * Base URL for the API (if specified)\n */\n baseUrl?: string\n}\n\n/**\n * An API endpoint\n */\nexport interface Endpoint {\n /**\n * HTTP method (GET, POST, PUT, PATCH, DELETE)\n */\n method: HttpMethod\n\n /**\n * URL path with parameter placeholders\n * @example \"/users/{id}\" or \"/orders/{orderId}/items\"\n */\n path: string\n\n /**\n * Operation ID from OpenAPI (if available)\n */\n operationId?: string\n\n /**\n * Human-readable summary\n */\n summary?: string\n\n /**\n * Detailed description\n */\n description?: string\n\n /**\n * Path parameters\n */\n pathParams: ParameterDef[]\n\n /**\n * Query parameters\n */\n queryParams: ParameterDef[]\n\n /**\n * Request body schema (for POST/PUT/PATCH)\n */\n requestBody?: RequestBody\n\n /**\n * Response schemas by status code\n */\n responses: Record<string, ResponseDef>\n\n /**\n * Tags for grouping endpoints\n */\n tags: string[]\n}\n\n/**\n * HTTP methods supported\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'\n\n/**\n * A request or response body definition\n */\nexport interface RequestBody {\n /**\n * Content type (usually application/json)\n */\n contentType: string\n\n /**\n * Reference to the model name, or inline schema\n */\n schema: SchemaRef | DataModel\n\n /**\n * Whether the body is required\n */\n required: boolean\n\n /**\n * Description of the body\n */\n description?: string\n}\n\n/**\n * A response definition\n */\nexport interface ResponseDef {\n /**\n * HTTP status code\n */\n statusCode: string\n\n /**\n * Description of the response\n */\n description?: string\n\n /**\n * Content type to schema mapping\n */\n content?: Record<string, SchemaRef | DataModel>\n}\n\n/**\n * A parameter definition (path or query)\n */\nexport interface ParameterDef {\n /**\n * Parameter name\n */\n name: string\n\n /**\n * Where the parameter is located\n */\n in: 'path' | 'query' | 'header' | 'cookie'\n\n /**\n * Whether the parameter is required\n */\n required: boolean\n\n /**\n * Parameter type\n */\n type: PropertyType\n\n /**\n * Optional format hint\n */\n format?: string\n\n /**\n * Description\n */\n description?: string\n\n /**\n * Example value\n */\n example?: unknown\n}\n\n/**\n * Reference to another schema/model\n */\nexport interface SchemaRef {\n /**\n * The referenced model name\n */\n $ref: string\n}\n\n/**\n * A data model representing an object schema\n */\nexport interface DataModel {\n /**\n * Model name (from the schema component name)\n */\n name: string\n\n /**\n * The type of this model\n */\n type: ModelType\n\n /**\n * Description from the spec\n */\n description?: string\n\n /**\n * Properties for object types\n */\n properties?: Record<string, PropertyDef>\n\n /**\n * Required property names\n */\n required?: string[]\n\n /**\n * For array types, the item schema\n */\n items?: SchemaRef | DataModel\n\n /**\n * Enum values for enum types\n */\n enum?: unknown[]\n\n /**\n * Example value from the spec\n */\n example?: unknown\n\n /**\n * Additional properties schema (for dictionaries)\n */\n additionalProperties?: boolean | SchemaRef | DataModel\n}\n\n/**\n * Model types\n */\nexport type ModelType = 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null'\n\n/**\n * A property definition within a model\n */\nexport interface PropertyDef {\n /**\n * Property name\n */\n name: string\n\n /**\n * Property type\n */\n type: PropertyType\n\n /**\n * Format hint (uuid, email, date-time, etc.)\n */\n format?: string\n\n /**\n * Description\n */\n description?: string\n\n /**\n * Whether this property is required\n */\n required?: boolean\n\n /**\n * Whether this property is nullable\n */\n nullable?: boolean\n\n /**\n * Enum values for string enums\n */\n enum?: unknown[]\n\n /**\n * For array types, the item schema\n */\n items?: SchemaRef | DataModel\n\n /**\n * Reference to another model (for $ref properties)\n */\n $ref?: string\n\n /**\n * Example value\n */\n example?: unknown\n\n /**\n * Default value\n */\n default?: unknown\n\n /**\n * Minimum value (for numbers)\n */\n minimum?: number\n\n /**\n * Maximum value (for numbers)\n */\n maximum?: number\n\n /**\n * Min length (for strings)\n */\n minLength?: number\n\n /**\n * Max length (for strings)\n */\n maxLength?: number\n\n /**\n * Pattern (regex for strings)\n */\n pattern?: string\n\n /**\n * Detected relationship to another model\n * Set by relationship detection, not directly from spec\n */\n relationshipTo?: RelationshipTarget\n\n /**\n * Custom extension for explicit relationship hints\n * @example \"x-demokit-relationship\": { \"model\": \"User\", \"field\": \"id\" }\n */\n 'x-demokit-relationship'?: RelationshipTarget\n}\n\n/**\n * Property types\n */\nexport type PropertyType =\n | 'string'\n | 'number'\n | 'integer'\n | 'boolean'\n | 'array'\n | 'object'\n | 'null'\n\n/**\n * A detected relationship between two models\n */\nexport interface Relationship {\n /**\n * The source side of the relationship\n */\n from: RelationshipSide\n\n /**\n * The target side of the relationship\n */\n to: RelationshipSide\n\n /**\n * Type of relationship\n */\n type: RelationshipType\n\n /**\n * Whether the relationship is required (not nullable)\n */\n required: boolean\n\n /**\n * How this relationship was detected\n */\n detectedBy: RelationshipDetectionMethod\n}\n\n/**\n * One side of a relationship\n */\nexport interface RelationshipSide {\n /**\n * Model name\n */\n model: string\n\n /**\n * Field name\n */\n field: string\n}\n\n/**\n * Target for a relationship from a property\n */\nexport interface RelationshipTarget {\n /**\n * Target model name\n */\n model: string\n\n /**\n * Target field (usually \"id\")\n */\n field: string\n}\n\n/**\n * Types of relationships between models\n */\nexport type RelationshipType =\n | 'one-to-one'\n | 'one-to-many'\n | 'many-to-one'\n | 'many-to-many'\n\n/**\n * How a relationship was detected\n */\nexport type RelationshipDetectionMethod =\n | 'explicit-ref' // OpenAPI $ref\n | 'naming-convention' // userId -> User.id pattern\n | 'x-demokit-extension' // x-demokit-relationship extension\n | 'inferred' // AI or heuristic inference\n\n/**\n * Helper type to check if something is a schema reference\n */\nexport function isSchemaRef(value: unknown): value is SchemaRef {\n return (\n typeof value === 'object' &&\n value !== null &&\n '$ref' in value &&\n typeof (value as SchemaRef).$ref === 'string'\n )\n}\n\n/**\n * Extract the model name from a $ref string\n * @example \"#/components/schemas/User\" -> \"User\"\n */\nexport function extractRefName(ref: string): string {\n const parts = ref.split('/')\n return parts[parts.length - 1] ?? ref\n}\n","/**\n * Relationship detection for DemoKit schemas\n *\n * Detects relationships between models using:\n * 1. Explicit $ref references in OpenAPI\n * 2. Naming conventions (userId -> User.id)\n * 3. x-demokit-relationship extension\n */\n\nimport type {\n DataModel,\n PropertyDef,\n Relationship,\n RelationshipTarget,\n RelationshipDetectionMethod,\n RelationshipType,\n} from './types'\nimport { isSchemaRef, extractRefName } from './types'\n\n/**\n * Common ID field naming patterns\n * Maps suffix patterns to implied relationships\n */\nconst ID_FIELD_PATTERNS = [\n // Standard patterns: userId -> User, customerId -> Customer\n { pattern: /^(.+)Id$/, targetField: 'id' },\n { pattern: /^(.+)_id$/, targetField: 'id' },\n { pattern: /^(.+)ID$/, targetField: 'id' },\n\n // UUID patterns: userUuid -> User, customerUUID -> Customer\n { pattern: /^(.+)Uuid$/, targetField: 'uuid' },\n { pattern: /^(.+)UUID$/, targetField: 'uuid' },\n { pattern: /^(.+)_uuid$/, targetField: 'uuid' },\n]\n\n/**\n * Convert a field name prefix to a model name\n * @example \"user\" -> \"User\", \"orderItem\" -> \"OrderItem\"\n */\nfunction prefixToModelName(prefix: string): string {\n return prefix.charAt(0).toUpperCase() + prefix.slice(1)\n}\n\n/**\n * Check if a property looks like a foreign key based on naming conventions\n */\nexport function detectRelationshipFromNaming(\n property: PropertyDef,\n availableModels: Set<string>\n): RelationshipTarget | null {\n const fieldName = property.name\n\n for (const { pattern, targetField } of ID_FIELD_PATTERNS) {\n const match = fieldName.match(pattern)\n if (match && match[1]) {\n const prefix = match[1]\n const modelName = prefixToModelName(prefix)\n\n // Check if this model exists in the schema\n if (availableModels.has(modelName)) {\n return { model: modelName, field: targetField }\n }\n\n // Also check for plural forms\n const pluralModel = modelName + 's'\n if (availableModels.has(pluralModel)) {\n return { model: pluralModel, field: targetField }\n }\n }\n }\n\n return null\n}\n\n/**\n * Check if a property has an explicit x-demokit-relationship extension\n */\nexport function detectRelationshipFromExtension(\n property: PropertyDef\n): RelationshipTarget | null {\n const extension = property['x-demokit-relationship']\n if (extension && typeof extension === 'object') {\n return {\n model: extension.model,\n field: extension.field || 'id',\n }\n }\n return null\n}\n\n/**\n * Check if a property is a $ref to another model\n */\nexport function detectRelationshipFromRef(\n property: PropertyDef,\n availableModels: Set<string>\n): RelationshipTarget | null {\n if (property.$ref) {\n const modelName = extractRefName(property.$ref)\n if (availableModels.has(modelName)) {\n return { model: modelName, field: 'id' }\n }\n }\n\n // Check if items is a $ref (for arrays of references)\n if (property.items && isSchemaRef(property.items)) {\n const modelName = extractRefName(property.items.$ref)\n if (availableModels.has(modelName)) {\n return { model: modelName, field: 'id' }\n }\n }\n\n return null\n}\n\n/**\n * Detect the relationship type based on property and target\n */\nfunction determineRelationshipType(\n property: PropertyDef,\n _fromModel: DataModel\n): RelationshipType {\n // If the property is an array, it's one-to-many or many-to-many\n if (property.type === 'array') {\n // For simplicity, treat array references as one-to-many\n // (the \"one\" side has the array of references)\n return 'one-to-many'\n }\n\n // Single reference is many-to-one (many records can reference one target)\n return 'many-to-one'\n}\n\n/**\n * Detect all relationships in a set of models\n */\nexport function detectRelationships(\n models: Record<string, DataModel>\n): Relationship[] {\n const relationships: Relationship[] = []\n const availableModels = new Set(Object.keys(models))\n\n for (const [modelName, model] of Object.entries(models)) {\n if (!model.properties) continue\n\n for (const [propName, property] of Object.entries(model.properties)) {\n let target: RelationshipTarget | null = null\n let detectionMethod: RelationshipDetectionMethod = 'inferred'\n\n // Priority 1: Explicit x-demokit-relationship extension\n target = detectRelationshipFromExtension(property)\n if (target) {\n detectionMethod = 'x-demokit-extension'\n }\n\n // Priority 2: $ref references\n if (!target) {\n target = detectRelationshipFromRef(property, availableModels)\n if (target) {\n detectionMethod = 'explicit-ref'\n }\n }\n\n // Priority 3: Naming conventions\n if (!target) {\n target = detectRelationshipFromNaming(property, availableModels)\n if (target) {\n detectionMethod = 'naming-convention'\n }\n }\n\n if (target) {\n // Don't create self-referential relationships for simple IDs\n if (target.model === modelName && target.field === 'id' && propName === 'id') {\n continue\n }\n\n // Add the detected relationship info to the property\n property.relationshipTo = target\n\n relationships.push({\n from: { model: modelName, field: propName },\n to: target,\n type: determineRelationshipType(property, model),\n required: property.required ?? false,\n detectedBy: detectionMethod,\n })\n }\n }\n }\n\n return relationships\n}\n\n/**\n * Find all relationships for a specific model\n */\nexport function getRelationshipsForModel(\n modelName: string,\n relationships: Relationship[]\n): {\n outgoing: Relationship[]\n incoming: Relationship[]\n} {\n return {\n outgoing: relationships.filter(r => r.from.model === modelName),\n incoming: relationships.filter(r => r.to.model === modelName),\n }\n}\n\n/**\n * Check if a model is referenced by other models\n */\nexport function isModelReferenced(\n modelName: string,\n relationships: Relationship[]\n): boolean {\n return relationships.some(r => r.to.model === modelName)\n}\n\n/**\n * Get the dependency order for models based on relationships\n * Returns models in order such that dependencies come before dependents\n */\nexport function getModelDependencyOrder(\n models: Record<string, DataModel>,\n relationships: Relationship[]\n): string[] {\n const modelNames = Object.keys(models)\n const visited = new Set<string>()\n const order: string[] = []\n\n function visit(name: string, path: Set<string> = new Set()) {\n if (visited.has(name)) return\n if (path.has(name)) {\n // Circular dependency - skip to break the cycle\n return\n }\n\n path.add(name)\n\n // Visit all models that this model depends on first\n const deps = relationships\n .filter(r => r.from.model === name)\n .map(r => r.to.model)\n .filter(dep => modelNames.includes(dep))\n\n for (const dep of deps) {\n visit(dep, new Set(path))\n }\n\n if (!visited.has(name)) {\n visited.add(name)\n order.push(name)\n }\n }\n\n for (const name of modelNames) {\n visit(name)\n }\n\n return order\n}\n","/**\n * OpenAPI 3.x parser for DemoKit\n *\n * Parses OpenAPI specs into DemoKit's internal schema representation\n * with automatic relationship detection.\n *\n * Uses @scalar/openapi-parser - a modern, webpack-compatible parser.\n */\n\nimport { dereference, validate } from '@scalar/openapi-parser'\nimport type { OpenAPI, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type {\n DemokitSchema,\n SchemaInfo,\n Endpoint,\n DataModel,\n PropertyDef,\n HttpMethod,\n ParameterDef,\n RequestBody,\n ResponseDef,\n PropertyType,\n ModelType,\n} from './types'\nimport { detectRelationships } from './relationships'\n\n// Type aliases for OpenAPI 3.x structures\ntype OpenAPIDocument = OpenAPI.Document\ntype SchemaObject = OpenAPIV3_1.SchemaObject\ntype ReferenceObject = OpenAPIV3_1.ReferenceObject\ntype ParameterObject = OpenAPIV3_1.ParameterObject\ntype RequestBodyObject = OpenAPIV3_1.RequestBodyObject\ntype ResponseObject = OpenAPIV3_1.ResponseObject\ntype MediaTypeObject = OpenAPIV3_1.MediaTypeObject\n\n/**\n * Options for parsing OpenAPI specs\n */\nexport interface ParseOptions {\n /**\n * Whether to dereference all $ref pointers\n * @default true\n */\n dereference?: boolean\n\n /**\n * Whether to detect relationships automatically\n * @default true\n */\n detectRelationships?: boolean\n\n /**\n * Whether to include response schemas in models\n * @default true\n */\n includeResponses?: boolean\n}\n\n/**\n * Parse an OpenAPI spec from a file path or URL\n */\nexport async function parseOpenAPIFromPath(\n pathOrUrl: string,\n options: ParseOptions = {}\n): Promise<DemokitSchema> {\n // Fetch the content\n const response = await fetch(pathOrUrl)\n if (!response.ok) {\n throw new Error(`Failed to fetch OpenAPI spec from ${pathOrUrl}: ${response.statusText}`)\n }\n\n const content = await response.text()\n return parseOpenAPIFromString(content, options)\n}\n\n/**\n * Parse an OpenAPI spec from a string (JSON or YAML)\n */\nexport async function parseOpenAPIFromString(\n spec: string,\n options: ParseOptions = {}\n): Promise<DemokitSchema> {\n const { dereference: shouldDereference = true } = options\n\n // First validate the spec\n const validationResult = await validate(spec)\n if (!validationResult.valid) {\n const errorMessages = validationResult.errors?.map(e => e.message).join(', ') || 'Unknown validation error'\n throw new Error(`Invalid OpenAPI specification: ${errorMessages}`)\n }\n\n // Get the dereferenced schema if requested\n let schema: OpenAPIDocument\n if (shouldDereference) {\n const derefResult = await dereference(spec)\n if (derefResult.errors && derefResult.errors.length > 0) {\n const errorMessages = derefResult.errors.map(e => e.message).join(', ')\n throw new Error(`Failed to dereference OpenAPI spec: ${errorMessages}`)\n }\n schema = derefResult.schema as OpenAPIDocument\n } else {\n // Parse without dereferencing - just use the validated result\n schema = validationResult.specification as OpenAPIDocument\n }\n\n return parseOpenAPIDocument(schema, options)\n}\n\n/**\n * Parse an OpenAPI spec from an already-parsed object\n */\nexport async function parseOpenAPIFromObject(\n spec: Record<string, unknown>,\n options: ParseOptions = {}\n): Promise<DemokitSchema> {\n const { dereference: shouldDereference = true } = options\n\n // Validate the object\n const validationResult = await validate(spec)\n if (!validationResult.valid) {\n const errorMessages = validationResult.errors?.map(e => e.message).join(', ') || 'Unknown validation error'\n throw new Error(`Invalid OpenAPI specification: ${errorMessages}`)\n }\n\n // Get the dereferenced schema if requested\n let schema: OpenAPIDocument\n if (shouldDereference) {\n const derefResult = await dereference(spec)\n if (derefResult.errors && derefResult.errors.length > 0) {\n const errorMessages = derefResult.errors.map(e => e.message).join(', ')\n throw new Error(`Failed to dereference OpenAPI spec: ${errorMessages}`)\n }\n schema = derefResult.schema as OpenAPIDocument\n } else {\n schema = validationResult.specification as OpenAPIDocument\n }\n\n return parseOpenAPIDocument(schema, options)\n}\n\n/**\n * Parse an OpenAPI document into DemokitSchema\n */\nfunction parseOpenAPIDocument(\n doc: OpenAPIDocument,\n options: ParseOptions = {}\n): DemokitSchema {\n const { detectRelationships: shouldDetect = true } = options\n\n // Parse info\n const info = parseInfo(doc)\n\n // Parse models from components/schemas\n const models = parseModels(doc)\n\n // Parse endpoints from paths\n const endpoints = parseEndpoints(doc)\n\n // Detect relationships\n const relationships = shouldDetect ? detectRelationships(models) : []\n\n return {\n info,\n endpoints,\n models,\n relationships,\n }\n}\n\n/**\n * Parse API info from the document\n */\nfunction parseInfo(doc: OpenAPIDocument): SchemaInfo {\n const docInfo = (doc as any).info || {}\n const info: SchemaInfo = {\n title: docInfo.title ?? 'Untitled API',\n version: docInfo.version ?? '1.0.0',\n description: docInfo.description,\n }\n\n // Try to extract base URL from servers\n const servers = (doc as any).servers\n if (servers && servers.length > 0 && servers[0]) {\n info.baseUrl = servers[0].url\n }\n\n return info\n}\n\n/**\n * Parse all models from components/schemas\n */\nfunction parseModels(doc: OpenAPIDocument): Record<string, DataModel> {\n const models: Record<string, DataModel> = {}\n\n const components = (doc as any).components\n const schemas = components?.schemas\n if (!schemas) {\n return models\n }\n\n for (const [name, schema] of Object.entries(schemas)) {\n // Skip reference objects (shouldn't happen after dereference)\n if (schema && typeof schema === 'object' && '$ref' in schema) {\n continue\n }\n\n models[name] = parseSchemaToModel(name, schema as SchemaObject)\n }\n\n return models\n}\n\n/**\n * Parse a schema object into a DataModel\n */\nfunction parseSchemaToModel(name: string, schema: SchemaObject): DataModel {\n if (!schema || typeof schema !== 'object') {\n return { name, type: 'object' }\n }\n\n const s = schema as Record<string, unknown>\n const model: DataModel = {\n name,\n type: schemaTypeToModelType(s.type as string | string[] | undefined),\n description: s.description as string | undefined,\n }\n\n // Parse properties for object types\n if (s.type === 'object' || s.properties) {\n model.type = 'object'\n model.properties = {}\n model.required = (s.required as string[]) || []\n\n if (s.properties && typeof s.properties === 'object') {\n for (const [propName, propSchema] of Object.entries(s.properties)) {\n model.properties[propName] = parseProperty(\n propName,\n propSchema as SchemaObject | ReferenceObject,\n model.required.includes(propName)\n )\n }\n }\n\n if (s.additionalProperties !== undefined) {\n if (typeof s.additionalProperties === 'boolean') {\n model.additionalProperties = s.additionalProperties\n } else if (s.additionalProperties && typeof s.additionalProperties === 'object') {\n if ('$ref' in s.additionalProperties) {\n model.additionalProperties = {\n $ref: (s.additionalProperties as ReferenceObject).$ref,\n }\n } else {\n model.additionalProperties = parseSchemaToModel(\n `${name}AdditionalProps`,\n s.additionalProperties as SchemaObject\n )\n }\n }\n }\n }\n\n // Parse array items\n if (s.type === 'array' && s.items) {\n model.type = 'array'\n if (typeof s.items === 'object' && '$ref' in s.items) {\n model.items = { $ref: (s.items as ReferenceObject).$ref }\n } else {\n model.items = parseSchemaToModel(`${name}Item`, s.items as SchemaObject)\n }\n }\n\n // Parse enum values\n if (s.enum) {\n model.enum = s.enum as unknown[]\n }\n\n // Parse example\n if (s.example !== undefined) {\n model.example = s.example\n }\n\n return model\n}\n\n/**\n * Parse a property schema into a PropertyDef\n */\nfunction parseProperty(\n name: string,\n schema: SchemaObject | ReferenceObject,\n required: boolean\n): PropertyDef {\n // Handle $ref\n if (schema && typeof schema === 'object' && '$ref' in schema) {\n return {\n name,\n type: 'object',\n required,\n $ref: schema.$ref,\n }\n }\n\n const s = schema as Record<string, unknown>\n\n const prop: PropertyDef = {\n name,\n type: schemaTypeToPropertyType(s.type as string | string[] | undefined),\n required,\n nullable: s.nullable as boolean | undefined,\n description: s.description as string | undefined,\n format: s.format as string | undefined,\n enum: s.enum as unknown[] | undefined,\n example: s.example,\n default: s.default,\n minimum: s.minimum as number | undefined,\n maximum: s.maximum as number | undefined,\n minLength: s.minLength as number | undefined,\n maxLength: s.maxLength as number | undefined,\n pattern: s.pattern as string | undefined,\n }\n\n // Parse array items\n if (s.type === 'array' && s.items) {\n prop.type = 'array'\n if (typeof s.items === 'object' && '$ref' in s.items) {\n prop.items = { $ref: (s.items as ReferenceObject).$ref }\n } else {\n prop.items = parseSchemaToModel(`${name}Item`, s.items as SchemaObject)\n }\n }\n\n // Check for x-demokit-relationship extension\n const xRelationship = s['x-demokit-relationship']\n if (xRelationship && typeof xRelationship === 'object') {\n prop['x-demokit-relationship'] = xRelationship as { model: string; field: string }\n }\n\n return prop\n}\n\n/**\n * Parse all endpoints from paths\n */\nfunction parseEndpoints(doc: OpenAPIDocument): Endpoint[] {\n const endpoints: Endpoint[] = []\n\n const paths = (doc as any).paths\n if (!paths) {\n return endpoints\n }\n\n const methods: HttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']\n\n for (const [path, pathItem] of Object.entries(paths)) {\n if (!pathItem || typeof pathItem !== 'object') continue\n\n for (const method of methods) {\n const operation = (pathItem as Record<string, unknown>)[method.toLowerCase()]\n\n if (!operation || typeof operation !== 'object') continue\n\n endpoints.push(parseEndpoint(method, path, operation as Record<string, unknown>, pathItem as Record<string, unknown>))\n }\n }\n\n return endpoints\n}\n\n/**\n * Parse a single endpoint\n */\nfunction parseEndpoint(\n method: HttpMethod,\n path: string,\n operation: Record<string, unknown>,\n pathItem: Record<string, unknown>\n): Endpoint {\n // Combine path-level and operation-level parameters\n const pathParams: ParameterDef[] = []\n const queryParams: ParameterDef[] = []\n\n const allParams = [\n ...((pathItem.parameters as unknown[]) || []),\n ...((operation.parameters as unknown[]) || []),\n ]\n\n for (const param of allParams) {\n if (!param || typeof param !== 'object') continue\n if ('$ref' in param) continue // Skip refs\n\n const parsed = parseParameter(param as ParameterObject)\n\n if (parsed.in === 'path') {\n pathParams.push(parsed)\n } else if (parsed.in === 'query') {\n queryParams.push(parsed)\n }\n }\n\n // Parse request body\n let requestBody: RequestBody | undefined\n const opRequestBody = operation.requestBody\n if (opRequestBody && typeof opRequestBody === 'object' && !('$ref' in opRequestBody)) {\n requestBody = parseRequestBody(opRequestBody as RequestBodyObject)\n }\n\n // Parse responses\n const responses: Record<string, ResponseDef> = {}\n const opResponses = operation.responses\n if (opResponses && typeof opResponses === 'object') {\n for (const [statusCode, response] of Object.entries(opResponses)) {\n if (!response || typeof response !== 'object') continue\n if ('$ref' in response) continue\n responses[statusCode] = parseResponse(statusCode, response as ResponseObject)\n }\n }\n\n return {\n method,\n path,\n operationId: operation.operationId as string | undefined,\n summary: operation.summary as string | undefined,\n description: operation.description as string | undefined,\n pathParams,\n queryParams,\n requestBody,\n responses,\n tags: (operation.tags as string[]) || [],\n }\n}\n\n/**\n * Parse a parameter object\n */\nfunction parseParameter(param: ParameterObject): ParameterDef {\n const p = param as Record<string, unknown>\n const schema = p.schema as Record<string, unknown> | undefined\n\n return {\n name: p.name as string,\n in: p.in as 'path' | 'query' | 'header' | 'cookie',\n required: (p.required as boolean) ?? false,\n type: schema ? schemaTypeToPropertyType(schema.type as string | string[] | undefined) : 'string',\n format: schema?.format as string | undefined,\n description: p.description as string | undefined,\n example: p.example ?? schema?.example,\n }\n}\n\n/**\n * Parse a request body object\n */\nfunction parseRequestBody(body: RequestBodyObject): RequestBody {\n const b = body as Record<string, unknown>\n const content = b.content as Record<string, unknown> | undefined\n const contentType = Object.keys(content || {})[0] || 'application/json'\n const mediaType = content?.[contentType] as MediaTypeObject | undefined\n\n let schema: RequestBody['schema'] = { name: 'Unknown', type: 'object' }\n\n if (mediaType) {\n const m = mediaType as Record<string, unknown>\n const mediaSchema = m.schema\n if (mediaSchema && typeof mediaSchema === 'object') {\n if ('$ref' in mediaSchema) {\n schema = { $ref: (mediaSchema as ReferenceObject).$ref }\n } else {\n schema = parseSchemaToModel('RequestBody', mediaSchema as SchemaObject)\n }\n }\n }\n\n return {\n contentType,\n schema,\n required: (b.required as boolean) ?? false,\n description: b.description as string | undefined,\n }\n}\n\n/**\n * Parse a response object\n */\nfunction parseResponse(statusCode: string, response: ResponseObject): ResponseDef {\n const r = response as Record<string, unknown>\n const responseDef: ResponseDef = {\n statusCode,\n description: r.description as string | undefined,\n }\n\n const content = r.content as Record<string, unknown> | undefined\n if (content) {\n responseDef.content = {}\n\n for (const [contentType, mediaType] of Object.entries(content)) {\n if (!mediaType || typeof mediaType !== 'object') continue\n\n const m = mediaType as Record<string, unknown>\n const schema = m.schema\n if (schema && typeof schema === 'object') {\n if ('$ref' in schema) {\n responseDef.content[contentType] = {\n $ref: (schema as ReferenceObject).$ref,\n }\n } else {\n responseDef.content[contentType] = parseSchemaToModel(\n `Response${statusCode}`,\n schema as SchemaObject\n )\n }\n }\n }\n }\n\n return responseDef\n}\n\n/**\n * Convert OpenAPI schema type to ModelType\n */\nfunction schemaTypeToModelType(\n type: string | string[] | undefined\n): ModelType {\n if (!type) return 'object'\n if (Array.isArray(type)) return type[0] as ModelType\n return type as ModelType\n}\n\n/**\n * Convert OpenAPI schema type to PropertyType\n */\nfunction schemaTypeToPropertyType(\n type: string | string[] | undefined\n): PropertyType {\n if (!type) return 'object'\n if (Array.isArray(type)) return type[0] as PropertyType\n return type as PropertyType\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@demokit-ai/schema",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "OpenAPI schema parsing with relationship detection for DemoKit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,8 +28,8 @@
28
28
  "typecheck": "tsc --noEmit"
29
29
  },
30
30
  "dependencies": {
31
- "@apidevtools/swagger-parser": "^10.1.0",
32
- "openapi-types": "^12.1.3"
31
+ "@scalar/openapi-parser": "^0.10.0",
32
+ "@scalar/openapi-types": "^0.2.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsup": "^8.3.5",