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
Roadmap.md Project goals (future direction); backlog on GitHub Issues, releases in CHANGELOG
CHANGELOG.md Releases and breaking changes (SemVer)
Integration SwiftPM, OpenAPI layout, configs, tests, Skills, KawarimiValidate
User Skills Agent SSOT for mock/scenario JSON — avoids drift from runtime contracts
Henge & runtime Dynamic mock, __kawarimi API, Vapor, scenario runtime
Mock JSON rules How embedded mock JSON is chosen

SwiftPM products

Product Why you need it
Kawarimi CLI for OpenAPI codegen (same entry as the plugin)
KawarimiValidate Fail CI before merge when scenario JSON would only warn at runtime — macOS: brew install novr/taps/kawarimi-validate
KawarimiCore Shared models, KawarimiConfigStore, KawarimiAPIClient, scenario resolver
KawarimiServer Server-side dynamic mocks without coupling to Henge UI
KawarimiClient Scenario header state on generated OpenAPI clients
KawarimiHenge SwiftUI admin UI (macOS)

Details: Integration, Henge.

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

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages