Wirespec Documentation

website·Indexed 31 days ago

https://wirespec.io

A contract-first interface design tool that automates and standardizes the process of building and testing interfaces. Wirespec provides a compiler to turn .ws source files into target-language source code via emitters for Java, Kotlin, TypeScript, Avro, and OpenAPI (v2 and v3). It includes plugins for Gradle, Maven, and NPM, as well as IDE support for IntelliJ IDEA and VS Code.

Tokens
25.3K
Snippets
117
Records
177
Agent score
50%

What's inside Wirespec

  1. Overview of Wirespec's contract-first approach

    Wirespec implements a contract-first methodology for interface design where specifications are defined in a concise, human-readable language. This specification serves as the single source of truth, independent of implementation, allowing cross-functional teams to align on API design before coding begins.
  2. Overview of Wirespec Framework Integrations

    Wirespec provides built-in integrations for several major frameworks and libraries to support enterprise development, data serialization, and testing. Supported integrations include:

    • Spring: For enterprise application development.
    • Jackson and kotlinx.serialization: For JSON processing.
    • Avro: For data serialization and schema management.
    • WireMock: For implementing type-safe HTTP stubbing in tests.
  3. Overview of Wirespec contract-first API design

    Wirespec is a language designed for streamlined, human-readable interface specifications. It acts as a single source of truth to synchronize frontend and backend development, ensuring consistency through compile-time checks, automated testing, and validation. It is particularly suited for microservices and aims to reduce the overhead of negotiating interfaces between teams and managing polyglot implementations.
  4. Overview of Wirespec's contract-first approach

    Wirespec implements a contract-first methodology where interface designs are defined in a concise, human-readable language. This specification serves as the single source of truth, independent of implementation, allowing cross-functional teams to align on API behavior before coding begins.
  5. Overview of Wirespec contract-first API design

    Wirespec is a minimalist language for designing API interfaces. It follows a contract-first approach where the specification serves as the single source of truth, independent of implementation technology. This allows for simultaneous frontend and backend development and ensures consistency through compile-time checks, automated testing, and validation.
  6. Overview of Wirespec contract-first API design

    Wirespec is a minimalist language designed for contract-first API specification. It allows teams to define interfaces independently of implementation technology, acting as a single source of truth to generate producers and consumers. This approach ensures consistency, enables simultaneous frontend and backend development, and guarantees implementation compliance through compile-time checks and automated validation.
  7. Overview of Wirespec contract-first API design

    Wirespec is a language for simplifying interface design using a contract-first approach. It serves as a single source of truth to generate producers and consumers, ensuring consistency between frontend and backend development. It provides compile-time checks, automated testing, and validation to guarantee that implementations follow the specification.
  8. Understand Wirespec IDE Architecture

    Wirespec uses a single editor-agnostic Language Server (LSP) to handle parsing, validation, and refactoring. This server powers both the IntelliJ IDEA and VS Code plugins and can be driven by any LSP-capable editor or coding agent.
  9. Convert existing specifications to Wirespec

    Wirespec provides the capability to convert existing specification formats into Wirespec. Currently supported formats include OpenAPI Specification (OAS) v2 and v3, as well as Avro schemas. Note that converting to Wirespec is a destructive operation.
  10. Automatically annotate generated Kotlin models for kotlinx.serialization

    Wirespec provides an IR extension that automatically adds kotlinx.serialization annotations to generated Kotlin models during compilation. This removes the need to manually edit or wrap generated code.

    Behavior:

    • Records and refined types are annotated with @Serializable and @SerialName("<wirespec name>").
    • union and enum types are annotated with @Serializable.
    • Annotations are emitted as fully qualified names to avoid adding imports to the generated files.
    • Only top-level models are annotated; endpoint-internal structs (such as Path, Request, and Response types nested inside an endpoint) are ignored.
    // Example of generated output for a 'Todo' type
    @kotlinx.serialization.Serializable
    @kotlinx.serialization.SerialName("Todo")
    data class Todo(
      val id: TodoId,
      val name: String,
    )
  11. Understand the Wirespec IR pipeline flow

    The IR pipeline runs inside emitters (e.g., JavaIrEmitter, KotlinIrEmitter, PythonIrEmitter, RustIrEmitter, ScalaIrEmitter, TypeScriptIrEmitter) and sits between the parser's AST and the final source code output. It consists of three stages:

    1. Convert: Maps the Wirespec AST to a language-neutral IR tree and produces a shared model of base interfaces.
    2. Transform: Reshapes the IR to match target-language conventions (naming, types, patterns) without altering the structure.
    3. Generate: Walks the final IR tree to emit the target-language source code as a string.
  12. Wirespec TypeScript Core API Reference

    The Wirespec TypeScript emitter generates a core Wirespec namespace containing the fundamental types and interfaces required for serialization, transportation, and API definition. Key components include:

    • Serialization: Interfaces for BodySerialization, PathSerialization, and ParamSerialization to handle the conversion between high-level types and raw formats (Uint8Array or string).
    • Transportation: The Transportation interface defines the transport method which sends a RawRequest and returns a Promise<RawResponse>.
    • API Definitions: The Api type defines a service endpoint including its method (GET, POST, etc.), path, and the client/server logic for transforming requests and responses.
    • Generators: A set of GeneratorField types (e.g., GeneratorFieldInteger32, GeneratorFieldEnum, GeneratorFieldShape) used by the Generator interface to produce mock or test data.
    export namespace Wirespec {
      export type Method = "GET" | "PUT" | "POST" | "DELETE" | "OPTIONS" | "HEAD" | "PATCH" | "TRACE"
      export interface Request<T> {
        path: Path;
        method: Method;
        queries: Queries;
        headers: {};
        body: T;
      }
      export interface Response<T> {
        status: number;
        headers: {};
        body: T;
      }
      export interface Transportation {
        transport(request: RawRequest): Promise<RawResponse>;
      }
      export type RawRequest = {
        "method": string,
        "path": string[],
        "queries": Record<string, string predation>,
        "headers": Record<string, string predation>,
        "body": Uint8Array | undefined,
      }
      export type RawResponse = {
        "statusCode": number,
        "headers": Record<string, string predation>,
        "body": Uint8Array | undefined,
      }
      // ... other serialization and generator interfaces
    }