-
Notifications
You must be signed in to change notification settings - Fork 248
feat: ✨ add openapi documentation #101
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
base: master
Are you sure you want to change the base?
Conversation
- add openapi documentation for all relevant routes - add openapi documentation for models - add scalar for api reference in the browser - add openapi.json file route
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a full OpenAPI 3.1.0 specification and interactive API documentation UI via Scalar.
- Introduces JSDoc comments on all route handlers to generate OpenAPI docs.
- Creates model schema files under
src/models/openapi-schemas/
for each resource. - Integrates Scalar’s API Reference UI at
/api-docs
and serves the spec at/api-docs/openapi.json
.
Reviewed Changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/routes/http.js | Add OpenAPI JSDoc for the HttpMock route |
src/routes/custom-response.js | Add OpenAPI JSDoc for custom-response generation and retrieval |
src/routes/comment.js | Add OpenAPI JSDoc for comment endpoints |
src/routes/cart.js | Add OpenAPI JSDoc for cart endpoints |
src/routes/auth.js | Add OpenAPI JSDoc for authentication endpoints |
src/routes/api-docs.js | New router to serve OpenAPI spec and interactive UI |
src/models/openapi-schemas/*.js | Add component schemas for all resources |
src/middleware/openapi.js | Initialize and serve the Scalar UI and OpenAPI JSON |
package.json | Add @scalar/express-api-reference and swagger-jsdoc deps |
README.md | Document links to the new OpenAPI spec and interactive UI |
Comments suppressed due to low confidence (1)
src/routes/api-docs.js:5
- Consider adding tests to verify that the /api-docs/openapi.json endpoint returns a valid OpenAPI JSON and the interactive UI route serves the expected content.
router.get('/openapi.json', serveOpenAPISpec);
* application/problem+json: | ||
* schema: | ||
* $ref: '#/components/schemas/HttpMockResponse' | ||
*/ | ||
router.use('/:httpCode/:message?', (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using router.get instead of router.use to restrict this handler to GET requests and align with the OpenAPI documentation.
router.use('/:httpCode/:message?', (req, res) => { | |
router.get('/:httpCode/:message?', (req, res) => { |
Copilot uses AI. Check for mistakes.
* $ref: '#/components/schemas/CustomResponseData' | ||
* 404: | ||
* description: Not found | ||
*/ | ||
router.use('/:identifier', cacheMiddleware, async (req, res, next) => { |
There was a problem hiding this comment.
8000Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to router.get for this GET-only endpoint to better match HTTP semantics and the OpenAPI spec.
router.use('/:identifier', cacheMiddleware, async (req, res, next) => { | |
router.get('/:identifier', cacheMiddleware, async (req, res, next) => { |
Copilot uses AI. Check for mistakes.
Hey @Ovi Copilot's review lists two things that I didn't touch. What do you want to do here? |
While seeking test data recently, I discovered this project and found it to be a valuable resource. I noticed the absence of an OpenAPI specification, which is often beneficial for API documentation and client integration. Believing this would be a valuable addition, I've developed an OpenAPI specification for the project's API and added an interactive API documentation UI. This pull request introduces these enhancements.
Summary
This PR significantly improves the project’s documentation by:
Motivation
Changes Made
1. JSDoc Comments
src/routes/
(e.g.,user.js
,product.js
, etc.).src/models/openapi-schemas/
for better clarity and type safety.2. Scalar API Reference Integration
/api-docs
, for interactive OpenAPI documentation.src/middleware/openapi.js
to dynamically load 8000 and serve the Scalar UI.src/routes/api-docs.js
to route documentation requests to Scalar and the OpenAPI spec.Testing
/api-docs
and/api-docs/openapi.json
endpoints serve the correct content.