Giter Site home page Giter Site logo

swift-openapi-vapor's Introduction

Swift OpenAPI Vapor

This package provides Vapor Bindings for the OpenAPI generator.

Usage

In entrypoint.swift add:

// 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, which contains step-by-step tutorials!

Additionally, see the request injection tutorial to learn how you can use swift-dependencies to inject Request into APIProtocol:

struct MyAPIProtocolImpl: APIProtocol {
    @Dependency(\.request) var request


    func 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)
            ]
        )
    }
}

swift-openapi-vapor's People

Contributors

0xtim avatar joannis avatar mahdibm avatar marius-se avatar samdogg7 avatar tib avatar tomerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-openapi-vapor's Issues

Add documentation on how to use Fluent(Kit)

Currently, I am working on a side project using this Vapor OpenAPI generated package. I am missing documentation on how to use Fluent with the generated code. I would like to use Fluent and I think this is going to be a big use case.

An example of my code:

import FluentKit
import Foundation
import OpenAPIRuntime
import Vapor

struct UserController: APIProtocol {
    typealias CreationInput = Operations.createUser.Input
    typealias CreationOutput = Operations.createUser.Output

    private let db: any Database

    init(db: any Database) {
        self.db = db
    }

    /// Create a user
    ///
    /// - Remark: HTTP `POST /users`.
    /// - Remark: Generated from `#/paths//users/post(createUser)`.
    func createUser(_ input: CreationInput) async throws -> CreationOutput {
        guard case let CreationInput.Body.json(input) = input.body else { fatalError() }

        let user = try User
            .Signup(name: input.name, email: input.email, password: input.password)
            .createUser()

        try await user.save(on: db)

        let newUser = Components.Schemas.User(
            name: user.name,
            createdAt: user.createdAt ?? .now,
            updatedAt: user.updatedAt ?? .now
        )
        let jsonBody: CreationOutput.Created.Body = .json(newUser)
        let body = CreationOutput.Created(body: jsonBody)

        return .created(body)
    }
}

Which results in a warning: Stored property 'db' of 'Sendable'-conforming struct 'UserController' has non-sendable type 'any Database'. Therefore, I would like to request documentation on how I am supposed to build out my Vapor app with FluentKit.

Question on scaling

Hi all, thanks for answering my question a while back on Fluent, @0xTim and @MahdiBM.

I have a broader question about the usage of the OpenAPI Vapor package. If I were to build a bigger OpenAPI document over time, the implementation of the Handler would grow quite fast. What would your suggestion be on managing this scaling up?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.