Skip to content

Feature: Add getFieldDefinition() and getTableDefinition() to SchemaManager #7

@wagnert

Description

@wagnert

Summary

Add convenience methods to SchemaManager for accessing field and table definitions directly, without navigating the nested schema structure.

Motivation

Currently, to access field metadata (like allowedValues for Enum fields), consumers must navigate the nested schema:

const schema = schemaManager.getSchema();
const statusField = schema.connections['default'].tables['service_portfolio'].fields['status'];
const allowedValues = statusField.allowedValues;

This is verbose and error-prone. A convenience method would simplify this common use case.

Proposed API

// Get field definition
const statusField = schemaManager.getFieldDefinition('default', 'service_portfolio', 'status');
// → { type: 'Enum', allowedValues: ['Vorgeschlagen', 'In Prüfung', ...], required: false, default: 'Vorgeschlagen' }

// Get table definition
const tableDefinition = schemaManager.getTableDefinition('default', 'service_portfolio');
// → { tableName: 'service_portfolio', keyField: 'service_portfolio_id', fields: {...} }

// Get allowed values for Enum field (shortcut)
const statusValues = schemaManager.getAllowedValues('default', 'service_portfolio', 'status');
// → ['Vorgeschlagen', 'In Prüfung', 'Akzeptiert', 'Abgelehnt', 'Deprecated']

Use Cases

  1. Zod Schema Generation: Generate Zod enums from schema allowedValues
  2. OpenAPI Spec Generation: Generate enum constraints for API documentation
  3. UI Dropdowns: Populate select options from schema
  4. Validation: Check if a value is valid for an Enum field
  5. Type Generation: Generate TypeScript types from schema

Acceptance Criteria

  • Add getFieldDefinition(connectionName, tableName, fieldName): FieldDefinition | undefined
  • Add getTableDefinition(connectionName, tableName): TableDefinition | undefined
  • Add getAllowedValues(connectionName, tableName, fieldName): string[] | undefined
  • Throw descriptive errors for non-existent connections/tables/fields (or return undefined?)
  • Add unit tests
  • Update documentation

Related

  • Used by: service-portfolio-mcp project
  • Eliminates need for hardcoded enum values across multiple files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions