Wirespec Documentation
website·Indexed 31 days ago
https://wirespec.ioA 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.
What's inside Wirespec
- 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.
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.
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.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.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.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.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.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.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.Automatically annotate generated Kotlin models for kotlinx.serialization
Wirespec provides an IR extension that automatically adds
kotlinx.serializationannotations 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
@Serializableand@SerialName("<wirespec name>"). unionandenumtypes 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, andResponsetypes 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, )- Records and refined types are annotated with
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:- Convert: Maps the Wirespec AST to a language-neutral IR tree and produces a shared model of base interfaces.
- Transform: Reshapes the IR to match target-language conventions (naming, types, patterns) without altering the structure.
- Generate: Walks the final IR tree to emit the target-language source code as a string.
Wirespec TypeScript Core API Reference
The Wirespec TypeScript emitter generates a core
Wirespecnamespace containing the fundamental types and interfaces required for serialization, transportation, and API definition. Key components include:- Serialization: Interfaces for
BodySerialization,PathSerialization, andParamSerializationto handle the conversion between high-level types and raw formats (Uint8Array or string). - Transportation: The
Transportationinterface defines thetransportmethod which sends aRawRequestand returns aPromise<RawResponse>. - API Definitions: The
Apitype defines a service endpoint including itsmethod(GET, POST, etc.),path, and theclient/serverlogic for transforming requests and responses. - Generators: A set of
GeneratorFieldtypes (e.g.,GeneratorFieldInteger32,GeneratorFieldEnum,GeneratorFieldShape) used by theGeneratorinterface 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 }- Serialization: Interfaces for