Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swift-server/swift-openapi-vapor
Vapor Bindings for the OpenAPI Generator
https://github.com/swift-server/swift-openapi-vapor
Last synced: 13 days ago
JSON representation
Vapor Bindings for the OpenAPI Generator
- Host: GitHub
- URL: https://github.com/swift-server/swift-openapi-vapor
- Owner: swift-server
- License: apache-2.0
- Created: 2023-04-27T17:35:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-25T13:04:08.000Z (7 months ago)
- Last Synced: 2024-10-02T05:37:55.048Z (about 1 month ago)
- Language: Swift
- Size: 53.7 KB
- Stars: 80
- Watchers: 12
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Swift OpenAPI Vapor
This package provides Vapor Bindings for the [OpenAPI generator](https://github.com/apple/swift-openapi-generator).
## Usage
In `entrypoint.swift` add:
```swift
// Create a Vapor OpenAPI Transport using your application.
let transport = VaporTransport(routesBuilder: app)// Create an instance of your handler type that conforms the generated protocol
// defining your service API.
let handler = MyServiceAPIImpl()// Call the generated function on your implementation to add its request
// handlers to the app.
try handler.registerHandlers(on: transport)
```## Documentation
To get started, check out the full [documentation][docs-generator], which contains step-by-step tutorials!
Additionally, see the [request injection tutorial][request-injection-tutorial] to learn how you can use [swift-dependencies] to inject `Request` into `APIProtocol`:
```swift
struct MyAPIProtocolImpl: APIProtocol {
@Dependency(\.request) var requestfunc myOpenAPIEndpointFunction() async throws -> Operations.myOperation.Output {
/// Use `request` as if this is a normal Vapor endpoint function
request.logger.notice(
"Got a request!",
metadata: [
"request": .stringConvertible(request)
]
)
}
}
```[docs-generator]: https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
[swift-dependencies]: https://github.com/pointfreeco/swift-dependencies
[request-injection-tutorial]: https://swiftpackageindex.com/swift-server/swift-openapi-vapor/1.0.1/tutorials/swift-openapi-vapor/requestinjection