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

[Suggestion] Parse OpenAPI specs to YAML on {route}.yml (zod-to-openapi) #163

Open
rafaell-lycan opened this issue Sep 19, 2023 · 1 comment

Comments

@rafaell-lycan
Copy link

rafaell-lycan commented Sep 19, 2023

Hi,

I've been playing with Hono (with Node) for a few days at work and we've seen some good performance from it.

After testing zod-to-openapi I realized that we could add an additional route with the extension .yml to output the specs as YAML when needed.

e.g.: The example below generates both /docs and /docs.yml routes

const app = new OpenAPIHono()
app.doc('/docs', swaggerOptions)

Reason
The scenario would be using it with an Online Swagger Editor or simply connecting to your editor of choice.

For performance reasons, it only parses it when the route is triggered:

Example

handler.openapi(routeSchama, async (c) => {
  const YAML = await import('js-yaml');
  const result = YAML.dump(json)
  
  return c.text(result)
})

Also, YAML parsing could be a new Hono helper such as hono/html if it becomes useful for more devs.

@yusukebe
Copy link
Member

Hi @rafaell-lycan

Thanks the suggestion.

I think you are right that we often create endpoints that output YAML. But in that case, I don't think it's necessary to go to the effort of inclusion in the Hono ecosystem, since we can simply use js-yaml in that case, in my opinion.

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