π Proposal: Use JSDoc Comments to Drive OpenAPI β Enable True "Contract-as-Code" with Elysia + Zod #1582
eastgold15
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
π Proposal: Use JSDoc Comments to Drive OpenAPI β Enable True "Contract-as-Code" with Elysia + Zod
π Why This Matters
Modern frontend ecosystems (e.g., shadcn/ui + React Hook Form) widely adopt Zod for form validation.
If we use Zod on both frontend and backend to define request/response schemas, we can:
UserSchemaused everywhere)Elysiaβs composable, chainable design aligns perfectly with Zodβs declarative schema style β but the current OpenAPI annotation method holds us back.
β Current Approach: Configuration Objects Intrude into Business Logic
t.Object.β Proposed Solution: JSDoc Comments as OpenAPI Source
Inspired by Apifox and Swagger: comments are the contract.
β¨ Benefits:
π§ How Could This Work? (Conceptual Prototype)
We could build an
@elysiajs/jsdoc-openapiplugin:This plugin would:
@summary,@description,@tags,@responseto OpenAPI fields;π Full-Stack Contract Layer: Zod as the Bridge
CreateUserSchema;/users;β Write once, validate everywhere β with end-to-end type safety.
π£ Closing Thoughts
Elysia is already an innovative framework.
By embracing βcomments as documentationβ and βZod as the universal contractβ, it could become the gold standard for full-stack TypeScript development.
Iβd love to hear community feedback
Feel free to post this directly in a GitHub Discussion! Let me know if you'd like a version with syntax highlighting optimized for GitHub, or if you want help drafting a follow-up comment with a working plugin demo.
Beta Was this translation helpful? Give feedback.
All reactions