Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing #1

Open
jneuendorf-i4h opened this issue May 8, 2023 · 1 comment
Open

Typing #1

jneuendorf-i4h opened this issue May 8, 2023 · 1 comment

Comments

@jneuendorf-i4h
Copy link

Hi,

while working with your router, I came up with the following type declaration:

declare module "koa-router-ajv-swaggergen" {
    import KoaRouter from "@koa/router"
    import { JSONSchemaType } from "ajv"

    // type SchemaRouterMethod = "del" | "get" | "post" | "put"

    type Handler =
        | ((
              this: Router,
              path: string,
              schema: JSONSchemaType<any>,
              ...handlers: KoaRouter.Middleware[]
          ) => ReturnType<KoaRouter.Middleware>)
        // | ((
        //       this: Router,
        //       path: string,
        //       config: { schema?: object; pre?: KoaRouter.Middleware[] },
        //       ...handlers: KoaRouter.Middleware[]
        //   ) => ReturnType<KoaRouter.Middleware>)

    export default class Router {
        rootDoc: {
            openapi: string
            info: {
                title: string
                description: string
                version: string
            }
            tags: string[]
            servers: string[]
        }

        constructor(router: KoaRouter, prefix: string)

        routes: KoaRouter["routes"]
        use: KoaRouter["use"]
        prefix: KoaRouter["prefix"]
        param: KoaRouter["param"]
        allowedMethods: KoaRouter["allowedMethods"]

        get(
            path: string,
            schema: JSONSchemaType<any>,
            ...handlers: KoaRouter.Middleware[]
        ): ReturnType<KoaRouter.Middleware>
        // get: Handler
        post: Handler
        put: Handler
        del: Handler
    }
    export function setupJsonErrors(app: any): void
}

Maybe, this is useful for you. ;)

@samarjit
Copy link
Owner

I really appreciate your help. I hope to integrate this soon and perhaps add some documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants