Skip to content

Conversation

@gaby
Copy link
Member

@gaby gaby commented Aug 21, 2025

Summary

  • auto-generate openapi.json file from app router
  • support per-operation IDs, tags, and deprecation metadata in the OpenAPI middleware
  • serve specs from grouped routes and verify raw JSON output in new tests
  • assert middleware JSON matches a fixture to guard against regressions

Fixes #2347 #1297 #3118

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 21, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-08-21-14-48-18

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gaby gaby changed the title feat: add openapi middleware 🔥 feat: Add OpenAPI middleware Aug 21, 2025
@gaby gaby added the v3 label Aug 21, 2025
@gaby gaby added this to v3 Aug 21, 2025
@gaby gaby added this to the v3 milestone Aug 21, 2025
@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 81.55556% with 83 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.63%. Comparing base (8fc239f) to head (2bab831).
⚠️ Report is 133 commits behind head on main.

Files with missing lines Patch % Lines
middleware/openapi/openapi.go 80.68% 26 Missing and 19 partials ⚠️
router.go 57.69% 22 Missing ⚠️
app.go 86.55% 10 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3702      +/-   ##
==========================================
- Coverage   91.81%   91.63%   -0.19%     
==========================================
  Files         114      117       +3     
  Lines       11498    10109    -1389     
==========================================
- Hits        10557     9263    -1294     
+ Misses        681      548     -133     
- Partials      260      298      +38     
Flag Coverage Δ
unittests 91.63% <81.55%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaby gaby moved this to In Progress in v3 Aug 21, 2025
@gaby
Copy link
Member Author

gaby commented Aug 21, 2025

/gemini review

@gemini-code-assist
Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@gaby
Copy link
Member Author

gaby commented Aug 21, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new OpenAPI middleware for auto-generating API specifications. The implementation is solid, with good test coverage and documentation. I've identified a potential improvement to prevent the middleware from documenting its own endpoint in the generated spec, which would make the output cleaner for API consumers. I also found a minor formatting issue in the documentation. Overall, this is a great feature addition.

@ReneWerner87
Copy link
Member

nice feature, thx @gaby
can you update and convert the DRAFT to READY (when it is ready for you)

@gaby gaby requested a review from Copilot October 25, 2025 16:44
@gaby
Copy link
Member Author

gaby commented Oct 25, 2025

/gemini review

Copy link
Contributor

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 introduces an OpenAPI middleware that auto-generates OpenAPI 3.0 specifications from registered Fiber routes. The implementation adds per-route metadata capabilities (summary, description, tags, parameters, request/response bodies, deprecation) that can be configured either through fluent route builders or global middleware configuration.

Key changes:

  • New OpenAPI middleware package with spec generation and JSON serving
  • Extended Route struct with OpenAPI-specific metadata fields
  • Added fluent API methods to both App and Group for route documentation

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
middleware/openapi/openapi.go Core middleware implementation generating OpenAPI spec from routes
middleware/openapi/config.go Configuration types for middleware and operation metadata
middleware/openapi/openapi_test.go Comprehensive test suite covering spec generation scenarios
middleware/openapi/testdata/openapi.json Golden file fixture for JSON output validation
router.go Extended Route struct with OpenAPI fields and helper types
router_test.go Tests for new route metadata methods
app.go Fluent API methods for documenting routes
group.go Group delegation methods for route documentation
group_test.go Tests for group-level route documentation
docs/middleware/openapi.md User-facing middleware documentation
docs/whats_new.md Release notes entry

@gaby
Copy link
Member Author

gaby commented Oct 25, 2025

@codex review and suggest feature improvements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new OpenAPI middleware to auto-generate API specifications from routes. The implementation is comprehensive, adding new methods to App and Group for route-level documentation, and providing configuration options for global overrides. The code is well-structured and includes extensive tests.

I have two main points of feedback. The most critical one is that the current implementation incorrectly includes middleware routes (from app.Use) in the generated OpenAPI spec, which should be fixed to ensure a clean and accurate API definition. The other is a minor improvement to an error message for better debugging. Overall, this is a great feature addition.

Comment on lines +102 to +104
if r.Method == fiber.MethodConnect {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Currently, middleware routes (registered with app.Use) are included in the generated OpenAPI specification. This is not ideal as it pollutes the spec with non-endpoint routes (e.g., a logging middleware would appear as an operation for every HTTP method). These routes should be filtered out.

This can be done by checking a flag on the Route struct that indicates if it's a middleware route. Assuming the use field from fiber.Route is exported to Use (as suggested in a separate comment on router.go), you should add a check here to skip middleware routes.

if r.Method == fiber.MethodConnect || r.Use {
    continue
}

Produces string `json:"produces"`
Deprecated bool `json:"deprecated"`
// Data for routing
use bool // USE matches path prefixes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use field is internal to the fiber package, which prevents other packages like the openapi middleware from identifying and filtering out middleware routes. This leads to middleware routes being incorrectly included in the generated OpenAPI specification.

To fix this, the use field should be exported (e.g., renamed to Use). This would make it accessible to external packages. Note that this change will require updating all internal usages of this field within the fiber package to use the exported field Use.

@gofiber gofiber deleted a comment from chatgpt-codex-connector bot Oct 25, 2025
@gaby
Copy link
Member Author

gaby commented Oct 25, 2025

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 24 to 31
return func(c fiber.Ctx) error {
if cfg.Next != nil && cfg.Next(c) {
return c.Next()
}

if !strings.HasSuffix(c.Path(), cfg.Path) {
return c.Next()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid suffix match when detecting spec route

The middleware treats any request whose path merely ends with the configured spec path as a hit (strings.HasSuffix(c.Path(), cfg.Path)). This means an instance registered at /openapi.json will intercept unrelated endpoints such as /reports/openapi.json or even other spec handlers for nested groups (/v1/openapi.json), preventing the intended handlers from ever running because the middleware returns the spec immediately. The effect is that legitimate routes become unreachable and multiple OpenAPI endpoints cannot coexist. Consider matching the exact path (or the expected group prefix plus cfg.Path) rather than a simple suffix check before serving the spec.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

🚀 [Feature]: allow to automatically generate OpenAPI docs based on route details, without additional in-code comments

3 participants