Skip to content

Repository files navigation

Schema to Code

Build Version Downloads

An IntelliJ IDEA plugin that generates type-safe code from JSON data. Paste your JSON and instantly get TypeScript interfaces, type aliases, and more.

Features

  • JSON to TypeScript: Automatically infer types from JSON data
  • Multiple Output Modes: Generate separate interfaces or nested inline types
  • Naming Strategies: Support for camelCase, PascalCase, snake_case, or preserve original names
  • Type Merging: Intelligently merge similar object structures
  • Real-time Preview: See generated code as you type
  • Customizable Options: Configure output format per language

Architecture

The project follows a clean multi-module architecture:

schema-to-code/
├── core/                    # Platform-independent business logic
│   └── src/main/kotlin/
│       └── .../core/
│           ├── config/      # Configuration classes (TargetLanguage, InputFormat, etc.)
│           ├── emit/        # Code emitters (TypeScript, etc.)
│           ├── i18n/        # Internationalization support
│           ├── infer/       # Input parsing (JSON inference)
│           ├── ir/          # Intermediate representation (TypeDef, Field, etc.)
│           ├── language/    # Language descriptors
│           ├── naming/      # Naming strategies (camelCase, PascalCase, etc.)
│           ├── normalize/   # Type normalization and merging
│           ├── options/     # Option definitions
│           ├── resolve/     # Type name resolution
│           ├── result/      # Result types for error handling
│           ├── service/     # Main service (SchemaToCodeService)
│           └── util/        # Utility functions
│
└── plugin/                  # IntelliJ IDEA plugin
    └── src/main/kotlin/
        └── .../plugin/
            ├── language/    # Language registry and IDs
            ├── state/       # Persistent settings
            ├── ui/          # UI components (panels, editors)
            ├── util/        # UI utilities
            └── viewmodel/   # MVVM view models

Processing Pipeline

JSON Input → Parse (Infer) → Normalize → Plan → Emit → TypeScript Output
  1. Infer: Parse JSON and create intermediate representation (IR)
  2. Normalize: Merge structurally equivalent types
  3. Plan: Allocate unique names and collect type declarations
  4. Emit: Generate target language code

Schema to Code converts JSON data into type-safe code instantly.

Features:

  • Generate TypeScript interfaces or type aliases from JSON
  • Multiple naming strategies (camelCase, PascalCase, snake_case)
  • Separate or nested type emission modes
  • Real-time code generation as you type

Installation

  • Using the IDE built-in plugin system:

    Settings/Preferences > Plugins > Marketplace > Search for " schema-to-code" > Install

  • Manually:

    Download the latest release and install it manually using Settings/Preferences > Plugins > ⚙️ > Install plugin from disk...

Usage

  1. Open the Schema to Code tool window (View → Tool Windows → Schema to Code)
  2. Paste your JSON in the left editor
  3. Configure options (language, naming strategy, emission mode)
  4. Copy the generated code from the right editor

Building

./gradlew build

Testing

./gradlew test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

TODO

  • Support TypeScript code generation
  • Support JSON input parsing and inference
  • Support multiple naming strategies (camelCase, PascalCase, snake_case, preserve)
  • Support separate and nested type emission modes
  • Real-time code generation and preview in IntelliJ
  • Customizable options per language
  • Support C# code generation
  • Support Kotlin code generation
  • Support Java code generation
  • Support reading and generating code from OpenAPI schema
  • Support reading and generating code from Swagger schema

Plugin based on the IntelliJ Platform Plugin Template.

About

A JetBrains plugin that convert schema such as JSON to a chosen language model

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages