8000 feat: ✨ add openapi documentation by ueberBrot · Pull Request #101 · Ovi/DummyJSON · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ueberBrot
Copy link

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:

  • Adding JSDoc comments across routes and creating model schema files.
  • Integrating Scalar’s API Reference UI for interactive OpenAPI documentation.

Motivation

  • Improved Developer Experience: JSDoc comments and interactive docs make onboarding and collaboration easier.
  • API Consumer Support: Scalar UI provides a user-friendly way for external developers to explore and test the API.
  • Maintainability: Well-documented code and schemas reduce the risk of misunderstandings and bugs.

Changes Made

1. JSDoc Comments

  • Added comprehensive JSDoc comments to all major route handlers in src/routes/ (e.g., user.js, product.js, etc.).
  • Documented model schemas in src/models/openapi-schemas/ for better clarity and type safety.
  • Ensured consistency and completeness in parameter, return type, and function descriptions.

2. Scalar API Reference Integration

  • Added Scalar’s API Reference UI, accessible at /api-docs, for interactive OpenAPI documentation.
  • Created/updated src/middleware/openapi.js to dynamically load 8000 and serve the Scalar UI.
  • Updated src/routes/api-docs.js to route documentation requests to Scalar and the OpenAPI spec.

Testing

  • Verified JSDoc rendering in IDEs and with documentation tools.
  • Confirmed /api-docs and /api-docs/openapi.json endpoints serve the correct content.
  • Ensured no breaking changes to existing API routes or middleware.

ueberBrot and others added 2 commits May 13, 2025 20:18
- 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
@Ovi Ovi requested a review from Copilot June 17, 2025 17:56
Copy link
@Copilot Copilot AI left a 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) => {
Copy link
Preview
Copilot AI Jun 17, 2025

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.

Suggested change
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) => {
Copy link
Preview
Copilot AI Jun 17, 2025

Choose 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.

Suggested change
router.use('/:identifier', cacheMiddleware, async (req, res, next) => {
router.get('/:identifier', cacheMiddleware, async (req, res, next) => {

Copilot uses AI. Check for mistakes.

@ueberBrot
Copy link
Author

Hey @Ovi Copilot's review lists two things that I didn't touch. What do you want to do here?

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

Successfully merging this pull request may close these issues.

1 participant
0