or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

API Schema Migrator

Build a utility that migrates API schema definitions between different versions, handling type modifications and backward compatibility.

Overview

Create a schema migration system that transforms API schema objects between versions while maintaining type safety. The system should handle property modifications, additions, and removals.

Requirements

Schema Version Support

Your system should support migrating schema definitions that evolve over time. Schemas may have properties that need to be:

  • Removed in newer versions
  • Added with new types
  • Modified to have different types or constraints

Type-Safe Migration

The migration utility must provide compile-time type safety, ensuring that:

  • Removed properties are not accessible in migrated schemas
  • New properties have correct types
  • Modified properties reflect their updated types

Migration Functions

Implement the following functions:

  1. A function migrateToV2 that accepts a V1 schema object and returns a V2 schema object
  2. A function migrateToV3 that accepts a V2 schema object and returns a V3 schema object

Schema Version Specifications

Version 1 Schema has:

  • name: string
  • type: string
  • required: boolean
  • deprecated: boolean

Version 2 Schema removes deprecated and adds:

  • nullable: boolean
  • description: string

Version 3 Schema removes nullable and adds:

  • allowNull: boolean (replaces nullable)
  • metadata: object with source (string) and version (number) properties

Implementation

@generates

API

/**
 * Migrates a V1 schema to V2
 */
export function migrateToV2(schema: SchemaV1): SchemaV2;

/**
 * Migrates a V2 schema to V3
 */
export function migrateToV3(schema: SchemaV2): SchemaV3;

Test Cases

  • Given a V1 schema {name: "user", type: "object", required: true, deprecated: false}, migrateToV2 returns a V2 schema without the deprecated property and with nullable: false and description: "" @test

  • Given a V2 schema {name: "user", type: "object", nullable: true, description: "User schema"}, migrateToV3 returns a V3 schema without nullable property, with allowNull: true and metadata: {source: "migration", version: 3} @test

  • The migrated V2 schema should not allow accessing the deprecated property (compile-time check) @test

  • The migrated V3 schema should not allow accessing the nullable property (compile-time check) @test

Dependencies { .dependencies }

openapi-types { .dependency }

Provides TypeScript type utilities for API schema definitions and migrations.