mm-ninja-turtles / turtle-express

My attempt of making Express.JS a typesafe router with Zod.
3 stars 0 forks source link

[feature]: open api with swagger ui #42

Open wai-lin opened 2 years ago

wai-lin commented 2 years ago

Generate open api json from the request and response schemas and also generate swagger ui route. And research about the type safe api client sdk generation. Also create custom Swagger UI if possible.

wai-lin commented 2 years ago

zod-to-json-schema is awesome and it seems to be a well maintained. I'll be choosing this library to generate OPEN API Schemas for now.

wai-lin commented 2 years ago

Also get some inspiration from zod-to-openapi.

wai-lin commented 2 years ago

For now, I'm rethinking the api.

  1. createRouter would be defining the base OPEN API Schema.
  2. router.path will create a new path
  3. handler function will generate the actual request, response schemas.

So it would be like

const router = createRouter(Router(), {
  basePath: '/v1',
  info: {
    title: 'My Awesome App API',
    version: '1.0.0',
  },
  servers: [
    { url: 'http://localhost:8080/v1' }
  ],
})
wai-lin commented 2 years ago

Found the a bunch of zod to open api generators but they don't seems to satisfy the need of our features.

Also found this and I'll try with this code and reengineer it to suite our use-case. Credit to the original source code 💯 .