feat: add /api endpoint returning OpenAPI 3.0.0 specification#196
feat: add /api endpoint returning OpenAPI 3.0.0 specification#196MridulTailor wants to merge 4 commits intocdnjs:masterfrom
Conversation
There was a problem hiding this comment.
Thanks for working on this, this new approach w/ the Zod-based library looks much better! A few thoughts:
-
Running this through https://editor.swagger.io/, it reports that the
Errorschema is defined but unused, do you need to pass a reference to that when you're defining the 404 responses, instead of using the Zod schema directly there? -
Should all the endpoints also define a 500 response using that schema?
-
Should each route be given a tag? Perhaps a
librariestag for the three library routes, and ametatag for the others (stats, whitelist, api)? -
Can you make sure the documentation you have for each endpoint matches exactly the documentation on the existing API docs, with the correct linebreaks and markdown for code/italics?
(Don't worry about the documentation for the response schemas, that can be done as a follow-up, so that your changes in this PR remain isolated to just this new route.)
Signed-off-by: Mridul Tailor <mtailor729@gmail.com>
|
Thanks for the feedback! I've addressed all the points:
|
|
Thank you! I'll try to take another pass through this later this week. Would you mind resolving the conflicts with the dependency you added (easiest is probably to checkout package* from master, and then reinstall your new dependency). |
Type of Change
/apiendpoint insrc/routes/api.tswhich returns an OpenAPI 3.0.0 specification dynamically generated from the existing Zod schemas usingOpenAPIRegistry. Integrated intosrc/index.ts.src/utils/openapi.tsto globally initializeextendZodWithOpenApi(z).src/routes/api.spec.tswith 7 tests covering CORS headers, cache headers, status codes, trailing slash resolution, and structural validation of the returned OpenAPI JSON spec.What issue does this relate to?
Closes #189
What should this PR do?
/apiendpoint that returns an OpenAPI 3.0.0 JSON specification for the cdnjs API.@asteasolutions/zod-to-openapias a dependency to dynamically generate the OpenAPI definitions directly from existing Zod schemas (library.schema.ts,libraries.schema.ts, etc.), ensuring response shapes are never manually duplicated and remain easily maintainable.autoupdateproperty) and intersections (required: ['name']) are automatically parsed and translated to OpenAPIoneOf/allOfattributes by the library./apiitself and a servers block pointing tohttps://api.cdnjs.com.libraries.tsandstats.ts) rather than a long-lived immutable cache, keeping the spec updatable as the API evolves.What are the acceptance criteria?
/apiendpoint returns a valid OpenAPI JSON object with descriptions matching the original cdnjs API documentation.npm run types,npm run lint).@cloudflare/vitest-pool-workersthat affects the entire test suite — unrelated to this PR. See Cloudflare Workers known issues.