Skip to content

novr/Kawarimi

Repository files navigation

日本語 | English

Kawarimi(代わり身)

A SwiftPM Build Tool Plugin that generates Kawarimi (ClientTransport mock), KawarimiHandler (APIProtocol default implementation), and KawarimiSpec from OpenAPI at build time.

Types, Client, and Server are generated by the official swift-openapi-generator plugin.

Use both OpenAPIGenerator and KawarimiPlugin on the same target. Compatible with swift-openapi-generator 1.0.0+.

The API target must contain exactly one OpenAPI file named openapi.yaml, openapi.yml, or openapi.json, and exactly one openapi-generator-config.yaml or openapi-generator-config.yml (same rules as OpenAPIGenerator; not multiple of either).

The Kawarimi mock is passed to Client as the transport; generated code does not depend on Client.swift.

Documentation

docs/README.md Index of all guides
CHANGELOG.md Releases and breaking changes (SemVer)
Integration SwiftPM, OpenAPI layout, configs, tests
Henge & runtime Dynamic mock, __kawarimi API, Vapor, kawarimi.json
Mock JSON rules How embedded mock JSON is chosen

KawarimiHandler — witness style (on… closures)

KawarimiHandler.swift generates one on... closure per operation; each APIProtocol method forwards to it (e.g. getGreetingonGetGreeting).

var handler = KawarimiHandler()
handler.onGetGreeting = { input in
    .ok(.init(body: .json(/* your payload */)))
}

Closures are typed @Sendable (Operations.….Input) async throws -> Operations.….Output.

on… properties and forwarding methods use accessModifier from openapi-generator-config.yaml (public / package / internal, default public). If another target imports your API target, use accessModifier: package or public.

Default stub bodies prefer a literal .json(...) expression; when that cannot be generated from the schema, Kawarimi falls back to JSONDecoder on the same synthesized JSON as the Kawarimi transport mock (Mock JSON rules). Configure handlerStubPolicy in kawarimi-generator-config.yaml (Integration).

Example project

DemoPackage (SwiftPM + Vapor DemoServer) and DemoApp (SwiftUI): Example/README.md · Example/README_JA.md (layout, commands, screenshots, security notes).

Requirements (summary)

Swift 6.2+; see docs/integration.md#requirements-and-tooling-notes. Example/ targets macOS 14+; library products also declare iOS 17+.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors