A Swift library for generating AsyncAPI documents.
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.
- Message definitions
- Server configurations
- Channel definitions
- Operation definitions
- Security schemes
- Components
- Tags and external documentation
Documentation available through SPI here
Add the package to your Package.swift
:
dependencies: [
.package(url: "https://github.com/yourusername/swift-asyncapi.git", from: "0.1.0")
]
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.