Skip to content

ajevans99/swift-asyncapi

Repository files navigation

Swift AsyncAPI Generator

CI

A Swift library for generating AsyncAPI documents.

Important

Work in progress.

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.jsonSchema,
                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/ajevans99/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

About

A Swift library for generating AsyncAPI documents.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •