TypeMUX

One Schema, Three Protocols

TypeMUX is a powerful Interface Definition Language (IDL) that generates GraphQL schemas, Protocol Buffers, and OpenAPI specifications from a single source of truth.

Why TypeMUX?

Maintaining separate schema definitions for GraphQL, Protocol Buffers, and OpenAPI is tedious and error-prone. TypeMUX solves this by letting you write one .typemux schema file and automatically generating all three formats, ensuring consistency across your API specifications.

/// User entity with authentication roles
type User {
  id: string @required
  email: string @required
  username: string @required
  role: UserRole @default("USER")
  createdAt: timestamp @required
}

enum UserRole {
  ADMIN
  USER
  GUEST
}

service UserService {
  rpc GetUser(GetUserRequest) returns (User)
    @http(GET)
    @path("/api/v1/users/{id}")
    @graphql(query)
}

From this single schema, TypeMUX generates:

Key Features

Installation

From Source

git clone https://github.com/rasmartins/typemux.git
cd typemux
go build -o typemux

Using Go Install

go install github.com/rasmartins/typemux@latest

Basic Usage

# Generate all formats
typemux -input schema.typemux -output ./generated

# Generate specific format
typemux -input schema.typemux -format graphql -output ./generated

# With external annotations
typemux -input schema.typemux -annotations annotations.yaml -output ./generated

Example Output

Given a TypeMUX schema, you get:

GraphQL (schema.graphql):

type User {
  id: String!
  email: String!
  username: String!
  role: UserRole
  createdAt: String!
}

enum UserRole {
  ADMIN
  USER
  GUEST
}

type Query {
  GetUser(input: GetUserRequestInput!): User
}

Protocol Buffers (schema.proto):

syntax = "proto3";

message User {
  string id = 1;
  string email = 2;
  string username = 3;
  UserRole role = 4;
  google.protobuf.Timestamp createdAt = 5;
}

enum UserRole {
  ADMIN = 0;
  USER = 1;
  GUEST = 2;
}

service UserService {
  rpc GetUser(GetUserRequest) returns (User);
}

OpenAPI (openapi.yaml):

paths:
  /api/v1/users/{id}:
    get:
      operationId: GetUser
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'

components:
  schemas:
    User:
      type: object
      required: [id, email, username, createdAt]
      properties:
        id:
          type: string
        email:
          type: string
        username:
          type: string
        role:
          $ref: '#/components/schemas/UserRole'
        createdAt:
          type: string
          format: date-time

Use Cases

Contributing

Contributions are welcome! Please see our Contributing Guide for details.

License

[License information to be added]

Support