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

too specific #181

Open
mbsanchez01 opened this issue Sep 28, 2023 · 1 comment
Open

too specific #181

mbsanchez01 opened this issue Sep 28, 2023 · 1 comment

Comments

@mbsanchez01
Copy link

mbsanchez01 commented Sep 28, 2023

This npm package is a perfect starting point for the Open API generation on Koa projects. But it's very specific, you are forcing people to use the controller as a class and to use your swagger router as an entry point.

What happens if I just want to user the Koa Router like this:

import Router from 'koa-router';
import { Context, Next } from 'koa';

const publicUserRouter = new Router({});

publicUserRouter.get('/users', (ctx: Context, next: Next) => {
   console.log('logic to get the users');
   ctx.body = {};
   return next();
});

It would be great if we could annotate that definition in some way. Moreover, I think this package does not detect headers and query parameters automatically from the code. Also, you don't give the user the possibility to name the types, you are given names using the class name, and the method name, which IMHO is awful. What if the user wants to reuse the type for other endpoint inputs/outputs?

Maybe you should find a more generic approach like swagger-autogen, the only drawback is that swagger-autogen does not support zod as input types. That is why I was looking for other alternatives without luck until now.

I congrats you for you efforts, but i know it could be better. Thank you in advance.

@Cody2333
Copy link
Owner

Cody2333 commented Oct 7, 2023

  1. SwaggerRouter extends the koa-router class, so you can simply using SwaggerRouter as a replacement of koa-router.
import { SwaggerRouter } from 'koa-swagger-decorator';
const router = new SwaggerRouter({});
router.get('/xxx', (ctx, next) => {...}
  1. i would try to add support for customizing schema names soon. You can simply resue your defined zod schemas in your code

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