FountainAI-OpenAPIs is a foundational Swift library providing OpenAPI specifications for the modular microservices ecosystem that drives FountainAI. This repository acts as the core mechanism for API versioning and resource management, enabling developers to seamlessly integrate FountainAI microservices into their projects.
The FountainAI-OpenAPIs library is designed to:
- Centralize API Versioning: Ensures consistent and maintainable access to the latest OpenAPI specifications for all FountainAI microservices.
- Provide Modular API Access: Supports individual services like
Character-Service
,Story-Factory-Service
, andSession-And-Context-Service
, with their respective OpenAPI definitions available in a unified framework. - Enable Resource Discovery: Swift's resource management APIs (e.g.,
Bundle.module
) provide seamless access to OpenAPI files at runtime for dynamic interaction and tooling. - Support Scalable Development: Integrates directly with client/server code generators, enabling developers to scaffold solutions around FountainAI microservices.
Add the library to your project using Swift Package Manager (SPM):
dependencies: [
.package(url: "https://github.com/Contexter/FountainAI-OpenAPIs.git", from: "1.1.0")
]
Integrate the library into your target:
.target(
name: "MyTarget",
dependencies: [
"FountainAI-OpenAPIs"
]
)
The library is organized into three primary components:
-
OpenAPI Resource Management:
- Each microservice (e.g.,
Action-Service
,Character-Service
) has a corresponding OpenAPI YAML file in theResources
directory. - These resources are bundled and made accessible via
Bundle.module
.
- Each microservice (e.g.,
-
Versioning and Updates:
- Each release is versioned, ensuring developers can lock their applications to specific API versions.
- OpenAPI updates follow semantic versioning for clarity and predictability.
-
Swift Library Integration:
- The Swift library format ensures compatibility with tools like Xcode and SPM.
- It supports modular imports and direct resource loading, allowing seamless integration into any Swift-based project.
The library bundles OpenAPI definitions for all FountainAI microservices in a single Swift package. This allows applications to:
- Dynamically load and parse API specifications.
- Generate client/server code using tools like OpenAPI Generator.
Each release of FountainAI-OpenAPIs corresponds to a specific set of API versions:
- Enables locking to a stable API version (
from: "1.1.0"
). - Ensures forward compatibility with new microservice features.
Built for Swift:
- Use
Bundle.module
to access OpenAPI files at runtime. - Generate and validate API requests/responses directly within Swift.
The OpenAPI files are bundled as resources and can be accessed via Bundle.module
:
import Foundation
import FountainAI_OpenAPIs
func loadOpenAPI(for serviceName: String) -> String? {
guard let url = Bundle.module.url(forResource: serviceName, withExtension: "yml") else {
print("Error: \(serviceName) OpenAPI file not found.")
return nil
}
do {
return try String(contentsOf: url, encoding: .utf8)
} catch {
print("Failed to load \(serviceName): \(error)")
return nil
}
}
// Example Usage
if let actionServiceSpec = loadOpenAPI(for: "Action-Service") {
print(actionServiceSpec)
}
- Load the desired OpenAPI file using
Bundle.module
. - Use the loaded YAML content with tools like
Yams
for parsing:import Yams if let yamlString = loadOpenAPI(for: "Character-Service") { let parsed = try Yams.load(yaml: yamlString) print("Parsed YAML: \(parsed)") }
- Generate client/server code or validate interactions with the corresponding APIs.
We welcome contributions to FountainAI-OpenAPIs:
- Fork the repository.
- Add or update OpenAPI files in
Sources/FountainAI-OpenAPIs/Resources
. - Submit a pull request with a detailed description.
This library is licensed under the MIT License. You are free to use, modify, and distribute it under the terms of the license.
The FountainAI-OpenAPIs library is the backbone of API versioning for FountainAI microservices, enabling dynamic resource discovery and scalable development. Its integration as a Swift package ensures consistency, ease of use, and compatibility with modern development workflows. Let us know if you encounter any issues or have suggestions for improvement!