swift-asyncapi

0.1.0

A Swift library for generating AsyncAPI documents.
ajevans99/swift-asyncapi

What's New

v0.1.0

2025-06-02T02:59:47Z

Swift AsyncAPI Generator

CI

A Swift library for generating AsyncAPI documents.

Usage

Basic Example

import AsyncAPIGenerator
import JSONSchemaBuilder

// Define your message types
@Schemable
struct LightMeasured {
    @NumberOptions(.minimum(0))
    let lumens: Int
    let sentAt: Int
}

// Create an AsyncAPI document
let asyncAPI = AsyncAPI(
    asyncapi: "3.0.0",
    info: .init(
        title: "Streetlights API",
        version: "1.0.0"
    ),
    components: .init(
        messages: [
            "lightMeasured": .init(
                name: "lightMeasured",
                contentType: "application/json",
                payload: LightMeasured.schema.schemaValue.value,
                title: "Light measured",
                summary: "Inform about environmental lighting conditions"
            )
        ]
    )
)

// Encode to JSON
let encoder = JSONEncoder()
let json = try encoder.encode(asyncAPI)

AsyncAPI conforms to Codable. You can use Yams to encode to yaml.

See the full Streetlights test for a full example.

Supported Features

  • Message definitions
  • Server configurations
  • Channel definitions
  • Operation definitions
  • Security schemes
  • Components
  • Tags and external documentation

Documentation

Documentation available through SPI here

Installation

Add the package to your Package.swift:

dependencies: [
    .package(url: "https://github.com/yourusername/swift-asyncapi.git", from: "0.1.0")
]

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

Description

  • Swift Tools 6.1.0
View More Packages from this Author

Dependencies

Last updated: Sun Jun 08 2025 22:02:31 GMT-0900 (Hawaii-Aleutian Daylight Time)