Skip to content
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

Variadic route options #176

Merged
merged 20 commits into from
Oct 1, 2024
Merged

Variadic route options #176

merged 20 commits into from
Oct 1, 2024

Conversation

EwenQuim
Copy link
Member

@EwenQuim EwenQuim commented Aug 28, 2024

Implements & closes #174.

See the petstore for an example of the feature (examples/petstore/controllers/pets.go)

Still in progress.

  • We need to apply this pattern to Groups too
  • Add checks for typing, nullable/required etc in the controller

Summary by CodeRabbit

  • New Features

    • Introduced automatic fixing of linting issues for Go files.
    • Added filtering functionality for pets in the pet store API, allowing retrieval based on criteria like name and age.
    • Enhanced OpenAPI documentation with new query and header parameters, including pagination options.
    • Introduced a structured approach for managing route options and parameters in the web framework.
    • Improved clarity and organization of API endpoint definitions with explicit option parameters.
  • Bug Fixes

    • Corrected naming inconsistencies in test functions for improved clarity.
  • Documentation

    • Updated README and OpenAPI specifications to reflect new features and improved parameter handling.
  • Tests

    • Added comprehensive tests for new functionalities, including filtering and parameter handling in the API.

option/option.go Outdated Show resolved Hide resolved
@EwenQuim EwenQuim force-pushed the variadic-route-options branch 8 times, most recently from 0f9dc75 to 81c56fb Compare August 30, 2024 13:06
@EwenQuim EwenQuim marked this pull request as ready for review August 30, 2024 13:06
@EwenQuim
Copy link
Member Author

EwenQuim commented Aug 30, 2024

@dylanhitt ready for review

The amount of work is quite huge at the moment on Fuego but once v0.15 will be released, we'll be good for some time :)

This might be one of the last big features.

Don't feel obliged to review all the code and quickly, this is open-source, we do what we can :)

@dylanhitt
Copy link
Collaborator

Okay nice, how much of a hurry is this? It’s a 3 day weekend in the states and I’m out of town.

Is next Tuesday or Wednesday fine?

@EwenQuim
Copy link
Member Author

Yes of course it will be OK, it will let me time to update the documentation website and maybe 1/2 additional tests.

Thanks again!

This was referenced Sep 1, 2024
mux.go Show resolved Hide resolved
ctx.go Show resolved Hide resolved
ctx.go Show resolved Hide resolved
ctx_params_test.go Outdated Show resolved Hide resolved
option/option.go Outdated Show resolved Hide resolved
Co-authored-by: Dylan Hitt <[email protected]>
Copy link

coderabbitai bot commented Sep 3, 2024

Walkthrough

The changes introduce enhancements to the Fuego web framework, focusing on improved error handling, refined query parameter management, and the addition of new middleware functionalities. The routing system has been restructured for better organization, and new testing capabilities have been implemented to ensure robust functionality. OpenAPI integration has been expanded, allowing for more detailed API documentation and improved usability. These modifications aim to enhance the framework's flexibility and maintainability.

Changes

File(s) Change Summary
Makefile, README.md, check-all-modules.sh Modified the lint target to include the --fix option for golangci-lint, refactored OpenAPI options in the main function, and added set -euo pipefail for improved error handling in the script.
cmd/fuego/commands/controller_test.go, ctx.go, ctx_params_test.go Corrected type names, modified query parameter methods to remove defaultValue, and introduced unit tests for query parameter handling.
examples/basic/go.mod, examples/full-app-gourmet/go.mod Updated multiple dependencies, including github.com/rs/cors and others, to their latest versions.
examples/full-app-gourmet/main.go, server/server.go, views/*.go Modified error logging, introduced caching middleware, and updated routing logic for pagination options.
examples/petstore/controllers/pets.go, pets_test.go, models/Pet.go, services/in_memory_pets.go Added filtering functionality for pets, introduced new test cases, and updated pet models to include new fields.
go.mod Added github.com/thejerf/slogassert dependency at version v0.3.4 and updated other dependencies.
middleware/cache/cache_test.go, mux.go, mux_test.go Updated middleware application in tests, introduced BaseRoute struct for better route management, and updated tests to reflect new route definitions.
openapi.go, openapi_operations.go Encapsulated route registration details into BaseRoute struct and enhanced OpenAPIParamOption struct with new fields.
option/option.go, option/option_test.go Introduced functions for managing route options and parameters, along with tests for middleware functionality and parameter handling.
param/param.go, param/param_test.go Defined a package for managing OpenAPI parameters with functional options and added tests for parameter handling capabilities.
security_test.go, serve.go, serve_test.go Updated function calls and tests to include new optional parameters for configuration.
documentation/docs/guides/openapi.md Refactored the invocation of fuego.Get in the main function to pass options as parameters for better clarity and organization, and introduced a new query parameter.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant Middleware
    participant Controller

    User->>Server: Send request
    Server->>Middleware: Apply middleware
    Middleware->>Server: Process request
    Server->>Controller: Invoke controller
    Controller-->>Server: Return response
    Server-->>User: Send response
Loading

🐇 "Hopping through code, what a delight,
New features and fixes, all shining bright!
With routes and options, so neatly aligned,
A framework so clever, it's truly refined.
Let's celebrate changes, with joy and with cheer,
For a future of coding, that's finally here!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator

@dylanhitt dylanhitt left a comment

Choose a reason for hiding this comment

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

Just a few things mentioned.

I'm going to take one more pass through this tomorrow.

Other than that. This was excellent. Very readable

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range, codebase verification and nitpick comments (2)
examples/full-app-gourmet/views/admin.ingredient.go (1)

65-66: Confirm the need for default values for pagination parameters.

The removal of default values for PerPage and Page query parameters in the adminIngredients function may lead to zero values being used for pagination, potentially affecting the application's behavior and breaking existing clients. Consider providing default values to maintain backward compatibility.

  • File: examples/full-app-gourmet/views/admin.ingredient.go
  • Lines: 65-66
Analysis chain

Verify the impact of removing default values for pagination parameters.

The removal of default values for PerPage and Page query parameters may break existing clients that rely on the default values.

Run the following script to verify the usage of the adminIngredients function:

Consider providing default values for PerPage and Page to maintain backward compatibility:

searchParams := components.SearchParams{
    Name:    c.QueryParam("name"),
    PerPage: fuego.DefaultInt(c.QueryParamInt("perPage"), 20),
    Page:    fuego.DefaultInt(c.QueryParamInt("page"), 1),
    URL:     "/admin/ingredients",
    Lang:    c.MainLang(),
}
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `adminIngredients` function.

# Test 1: Search for calls to the `adminIngredients` function. 
# Expect: Identify calls that do not provide `perPage` and `page` query parameters.
rg --type go -A 5 $'adminIngredients'

# Test 2: Search for usages of the `/admin/ingredients` endpoint in the codebase.
# Expect: Identify usages that do not provide `perPage` and `page` query parameters.
rg --type go -A 5 $'"/admin/ingredients"'

Length of output: 2525


Script:

#!/bin/bash
# Description: Investigate the definition and usage of `optionPagination`.

# Search for the definition of `optionPagination`.
rg --type go 'optionPagination'

# Search for middleware or functions that handle default values for query parameters.
rg --type go 'default' -A 5

Length of output: 25667

examples/petstore/controllers/pets_test.go (1)

27-43: Add more context to the test logs.

The test logs can be improved by adding more context about the expected behavior.

Apply this diff to add more context to the test logs:

-		t.Log(w.Body.String())
+		t.Log("Filtering pets by name should return the matching pets:", w.Body.String())
 		require.Equal(t, http.StatusOK, w.Code)
 
 		w = httptest.NewRecorder()
 		r = httptest.NewRequest("GET", "/pets/?name=kit&younger_than=1", nil)
 		s.Mux.ServeHTTP(w, r)
-		t.Log(w.Body.String())
+		t.Log("Filtering pets by name and age should return the matching pets:", w.Body.String())
 		require.Equal(t, http.StatusOK, w.Code)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 40840eb and 23cd32f.

Files ignored due to path filters (3)
  • examples/basic/go.sum is excluded by !**/*.sum
  • examples/full-app-gourmet/go.sum is excluded by !**/*.sum
  • go.sum is excluded by !**/*.sum
Files selected for processing (35)
  • Makefile (1 hunks)
  • README.md (1 hunks)
  • check-all-modules.sh (1 hunks)
  • cmd/fuego/commands/controller_test.go (1 hunks)
  • ctx.go (6 hunks)
  • ctx_params_test.go (1 hunks)
  • ctx_test.go (2 hunks)
  • examples/basic/go.mod (1 hunks)
  • examples/full-app-gourmet/go.mod (2 hunks)
  • examples/full-app-gourmet/main.go (1 hunks)
  • examples/full-app-gourmet/server/server.go (2 hunks)
  • examples/full-app-gourmet/views/admin.ingredient.go (1 hunks)
  • examples/full-app-gourmet/views/admin.recipe.go (1 hunks)
  • examples/full-app-gourmet/views/views.go (2 hunks)
  • examples/petstore/controllers/pets.go (4 hunks)
  • examples/petstore/controllers/pets_test.go (1 hunks)
  • examples/petstore/lib/testdata/doc/openapi.golden.json (6 hunks)
  • examples/petstore/models/Pet.go (1 hunks)
  • examples/petstore/services/in_memory_pets.go (2 hunks)
  • examples/petstore/services/in_memory_pets_test.go (2 hunks)
  • go.mod (1 hunks)
  • middleware/cache/cache_test.go (2 hunks)
  • mux.go (4 hunks)
  • mux_test.go (9 hunks)
  • openapi.go (1 hunks)
  • openapi_description.go (1 hunks)
  • openapi_handler_test.go (1 hunks)
  • openapi_operations.go (4 hunks)
  • option/option.go (1 hunks)
  • option/option_test.go (1 hunks)
  • param/param.go (1 hunks)
  • param/param_test.go (1 hunks)
  • security_test.go (3 hunks)
  • serve.go (2 hunks)
  • serve_test.go (10 hunks)
Files skipped from review due to trivial changes (3)
  • cmd/fuego/commands/controller_test.go
  • examples/basic/go.mod
  • examples/full-app-gourmet/main.go
Additional context used
GitHub Check: tests
ctx_params_test.go

[failure] 35-35:
undefined: http

Additional comments not posted (119)
check-all-modules.sh (1)

3-3: LGTM! The command enhances error handling and script robustness.

The addition of the set -euo pipefail command is a great improvement to the script's error handling and robustness. Here's a breakdown of what each flag does:

  • -e: Immediately exits the script if any command fails, preventing the script from continuing execution in the event of errors.
  • -u: Treats unset variables as an error, helping to catch potential issues related to undefined variables.
  • -o pipefail: Returns the status of the last command in a pipeline that failed, ensuring that the script's exit status accurately reflects any failures in the pipeline.

These modifications enhance the control flow of the script by enforcing stricter error handling, which is crucial for scripts that manage multiple modules and dependencies.

examples/petstore/models/Pet.go (3)

14-14: LGTM!

The new IsAdopted field is correctly defined with the appropriate JSON tag and description.


20-20: LGTM!

The new IsAdopted field is correctly defined with the appropriate JSON tag and description.


26-26: LGTM!

The new IsAdopted field is correctly defined as a pointer with the appropriate JSON tag and description, allowing for the representation of an optional adoption status.

go.mod (1)

12-12: LGTM!

The addition of the github.com/thejerf/slogassert dependency at version v0.3.4 is approved.

The new dependency can enhance the project's logging and testing capabilities, as suggested by the AI-generated summary. The version constraint is specified, and the dependency is added in the correct location, following the alphabetical order of the existing dependencies.

ctx_params_test.go (1)

14-39: LGTM!

The test function is well-structured and correctly tests the default values of query parameters. The use of the require package from the github.com/stretchr/testify library is a good practice.

Tools
GitHub Check: tests

[failure] 35-35:
undefined: http

param/param.go (8)

5-9: LGTM!

The code changes are approved.


11-15: LGTM!

The code changes are approved.


17-21: LGTM!

The code changes are approved.


23-27: LGTM!

The code changes are approved.


29-33: LGTM!

The code changes are approved.


35-39: LGTM!

The code changes are approved.


41-45: LGTM!

The code changes are approved.


48-55: LGTM!

The code changes are approved.

param/param_test.go (1)

13-43: LGTM!

The test function TestParam is well-structured and covers all the options for query parameters. It checks the route and parameter metadata thoroughly using assertions. The test follows the best practices for writing unit tests in Go.

Makefile (1)

36-36: LGTM! But review the automatic fixes.

The --fix option is a great addition that can help streamline the development workflow by automatically resolving linting issues.

However, please ensure that you review the automatic fixes made by golangci-lint to confirm that they do not introduce unintended changes or break the code.

openapi_handler_test.go (1)

12-18: LGTM!

The new dummyMiddleware function is a useful addition for testing scenarios that depend on request and response headers. The code is well-structured and the comments clearly describe its purpose.

examples/full-app-gourmet/server/server.go (2)

21-27: LGTM!

The cache middleware function is well-implemented and follows the middleware pattern. It is reusable and can be applied to any handler. The function is well-named and the purpose is clear.


53-58: LGTM!

The changes to the static file handler registration improve the organization of the code by separating concerns and promoting reuse of the caching logic across different handlers. The changes enhance code readability and maintainability and are consistent with the rest of the codebase.

examples/full-app-gourmet/go.mod (4)

6-6: LGTM!

The version update of github.com/a-h/templ from v0.2.747 to v0.2.771 is approved.


9-9: LGTM!

The version update of github.com/go-fuego/fuego/extra/markdown from v0.0.0-20240817052016-11e0974d8e77 to v0.0.0-20240830083148-46b1f9a12d8c is approved.


15-15: LGTM!

The version update of github.com/rs/cors from v1.11.0 to v1.11.1 is approved.


52-52: LGTM!

The version update of modernc.org/libc from v1.59.9 to v1.60.0 is approved.

examples/full-app-gourmet/views/views.go (6)

10-12: LGTM!

The code changes are approved.


14-16: LGTM!

The code changes are approved.


22-23: LGTM!

The code changes are approved.


36-38: LGTM!

The code changes are approved.


44-46: LGTM!

The code changes are approved.


54-56: LGTM!

The code changes are approved.

examples/petstore/services/in_memory_pets_test.go (1)

49-58: LGTM!

The new test case for the FilterPets method is well-structured and covers two relevant scenarios:

  1. Filter pets by name ("kit") and age (younger than 5), expecting to find one pet named "kitkat".
  2. Filter pets younger than 1, expecting to find none.

It uses appropriate assertions from the testify library to verify the expected behavior. The test case enhances the coverage of the filtering functionality.

The code changes are approved.

openapi_description.go (4)

63-80: LGTM!

The code changes in the main function significantly improve the API's documentation, usability, and functionality by:

  • Incorporating detailed OpenAPI options such as Description, Summary, Tags, and Deprecated.
  • Introducing query and header parameters for more flexible API usage.
  • Utilizing custom OpenAPI options optionPagination and optionCustomBehavior to encapsulate pagination options and custom behaviors.

The changes align the API with best practices for RESTful services.


82-85: LGTM!

The optionPagination variable correctly encapsulates pagination options for the route by defining query parameters for "page" and "perPage". This facilitates the retrieval of paginated data.


87-89: Verify the custom behavior.

The optionCustomBehavior variable sets the XXX field of the *fuego.BaseRoute to "YYY". Please verify the purpose and impact of this custom behavior on the route.


99-104: LGTM!

The getAllPets controller function is correctly updated to utilize query parameters. It retrieves the "name" and "per_page" query parameters using ctx.QueryParam("name") and ctx.QueryParamIntErr("per_page"), respectively. This allows the function to respond dynamically based on the input received from the client.

examples/petstore/controllers/pets.go (7)

4-5: LGTM!

The code changes are approved.


8-10: LGTM!

The code changes are approved.


12-15: LGTM!

The code changes are approved.


25-38: LGTM!

The code changes are approved.


56-61: LGTM!

The code changes are approved.


103-106: LGTM!

The code changes are approved.


113-113: LGTM!

The code changes are approved.

examples/petstore/controllers/pets_test.go (1)

19-19: LGTM!

The request path has been updated to match the test function name.

serve.go (2)

78-80: LGTM!

The comment accurately describes the updated function signature and the optional route parameter.


88-90: LGTM!

The check ensures that the route parameter is always initialized, even if it's not provided by the user. This allows the HTTPHandler to operate without explicit route configuration while still allowing for customization when needed.

middleware/cache/cache_test.go (2)

9-9: LGTM!

The code changes are approved.


110-110: LGTM!

The code changes are approved.

openapi_operations.go (9)

25-30: LGTM!

The addition of new fields to the OpenAPIParamOption struct enhances its flexibility by allowing to specify additional properties for OpenAPI parameters. The changes are approved.


34-38: LGTM!

Marking the Description method as deprecated and providing an example of the new option.Description helps guide the users to transition to the new API. The changes are approved.


45-49: LGTM!

Marking the Summary method as deprecated and providing an example of the new option.Summary helps guide the users to transition to the new API. The changes are approved.


56-60: LGTM!

Marking the OperationID method as deprecated and providing an example of the new option.OperationID helps guide the users to transition to the new API. The changes are approved.


90-94: LGTM!

Marking the Header method as deprecated and providing an example of the new option.Header helps guide the users to transition to the new API. The changes are approved.


101-105: LGTM!

Marking the Cookie method as deprecated and providing an example of the new option.Cookie helps guide the users to transition to the new API. The changes are approved.


112-116: LGTM!

Marking the QueryParam method as deprecated and providing an example of the new option.Query helps guide the users to transition to the new API. The changes are approved.


124-128: LGTM!

Marking the Tags method as deprecated and providing an example of the new option.Tags helps guide the users to transition to the new API. The changes are approved.


200-205: LGTM!

The addition of the Deprecated method aligns with the new option-based approach for marking routes as deprecated. Providing an example of the new option.Deprecated helps guide the users to transition to the new API. The changes are approved.

option/option.go (7)

54-54: The existing review comment is still valid:
"""
dylanhitt: nit:

//	QueryInt("age", "Filter by age (in years)", param.Example("3 years old", 3), param.Nullable())

"""


221-221: The existing review comment is still valid:
"""
dylanhitt: What is the plan here?

Also RequestContentType
"""


113-136: LGTM!

The code changes are approved.


139-183: LGTM!

The code changes are approved.


186-190: LGTM!

The code changes are approved.


193-197: LGTM!

The code changes are approved.


200-204: LGTM!

The code changes are approved.

mux.go (9)

47-48: LGTM!

The code changes are approved. Embedding the BaseRoute struct in the Route struct simplifies the route definition process and enhances code clarity.


50-57: LGTM!

The code changes are approved. The introduction of the BaseRoute struct consolidates common route attributes, allowing for a more organized and extensible approach to route management.


63-64: LGTM!

The code changes are approved. The introduction of the variadic options parameter enhances the flexibility of route registration by allowing middleware and other options to be applied more seamlessly.


67-68: LGTM!

The code changes are approved. The updates to the Get, Post, Delete, Put, and Patch functions are consistent with the changes made to the All function. They enhance the flexibility of route registration for these HTTP methods by allowing middleware and other options to be applied more seamlessly.

Also applies to: 71-72, 75-76, 79-80, 83-84


88-91: LGTM!

The code changes are approved. The updates to the Register function enhance the flexibility of route registration by processing the options parameter and applying them to modify the BaseRoute fields before proceeding with the registration of the route.


100-104: LGTM!

The code changes are approved. Returning a pointer to Route instead of Route reflects the modifications in the struct definitions and ensures that the routes are handled consistently throughout the codebase.


122-124: LGTM!

The code changes are approved. Setting the Operation.Description field with a combination of the controller name and the existing description provides additional context about the controller associated with the route in the OpenAPI documentation.


143-149: LGTM!

The code changes are approved. The updates to the Handle, AllStd, GetStd, PostStd, DeleteStd, PutStd, and PatchStd functions are consistent with the changes made to the other route registration functions. They enhance the flexibility of route registration by allowing middleware and other options to be applied more seamlessly. Returning a pointer to Route instead of Route ensures that the routes are handled consistently throughout the codebase.

Also applies to: 152-153, 156-157, 160-161, 164-165, 168-169, 172-174


176-189: LGTM!

The code changes are approved. The updates to the registerFuegoController and registerStdController functions are consistent with the changes made to the other route registration functions. They enhance the flexibility of route registration by processing the options parameter and applying them to modify the BaseRoute fields before proceeding with the registration of the route.

Also applies to: 191-203

option/option_test.go (7)

41-73: LGTM!

The test function TestPerRouteMiddleware is well-structured and covers the necessary scenarios to test per-route middleware functionality. It creates a server, registers routes with and without middleware, sends requests, and asserts the response body and headers to ensure the middleware is applied correctly.


75-145: LGTM!

The test function TestUse is well-structured and covers various scenarios related to middleware registration using the Use function. It contains multiple subtests that test different aspects of middleware registration and execution order, such as registering a single middleware, multiple middleware, and using variadic arguments. The subtests create a server, register middleware and routes, send requests, and assert the order of middleware execution using custom headers.


149-195: LGTM!

The test function TestParam is well-structured and tests an important aspect of parameter handling in the OpenAPI configuration. It creates a server with a custom log handler, registers routes with correct and incorrect parameter usage, sends requests, and asserts the presence or absence of warning messages in the log handler. This test ensures that a warning is logged when a parameter is used in the controller but not defined in the OpenAPI configuration, indicating a potential typo or mismatch.


197-212: LGTM!

The test function TestHeader is simple but effective in testing the declaration of a header parameter for a route. It creates a server, registers a route with a header parameter, sends a request, and asserts the response body. This test ensures that the route can be registered with a header parameter and that the route handler can be executed successfully.


214-231: LGTM!

The test function TestOpenAPI is well-structured and tests the declaration of OpenAPI parameters for a route. It creates a server, registers a route with various OpenAPI parameters (summary, description, tags, deprecated, operation ID), and asserts the values of the corresponding fields in the route's Operation struct. This test ensures that the provided OpenAPI parameters are correctly set in the route's metadata, allowing for proper documentation and API specification.


233-251: LGTM!

The test function TestGroup is well-structured and tests the declaration of a group parameter for a route. It creates a paramsGroup variable with a group of parameters (header, query, cookie), registers a route with the paramsGroup, and asserts the presence and values of the parameters in the route's Params and Operation structs. This test ensures that the parameters defined in the group are correctly added to the route's metadata, allowing for reusable and modular parameter definitions.


253-279: LGTM!

The test function TestQuery is well-structured and tests important validation scenarios for query parameter declarations. It contains two subtests that verify the framework panics when invalid example or default values are provided for specific query parameter types (QueryInt, QueryBool, Query). This test ensures that the framework enforces type safety and consistency in the API documentation by catching invalid parameter declarations at runtime.

README.md (3)

148-152: LGTM!

The updated import statements are necessary to support the new functionality being introduced in the main function.


157-168: Excellent refactoring!

The changes to the fuego.Post function call significantly improve the clarity and maintainability of the API's configuration. The introduction of new query and header parameters, along with the use of optionPagination and optionCustomBehavior variables, enhances the API's capabilities and promotes a more structured approach to specifying OpenAPI options.

The changes are consistent with the AI-generated summary and do not introduce any issues or inconsistencies.


173-180: Great addition of reusable options!

The introduction of the optionPagination and optionCustomBehavior variables is a great way to promote code reusability and maintainability. By encapsulating related options into separate variables, the code becomes more modular and easier to understand.

The pagination options included in optionPagination are essential for implementing pagination in API responses, while the optionCustomBehavior variable allows for flexible customization of the route.

The changes are consistent with the AI-generated summary and the list of alterations. They do not introduce any issues or inconsistencies.

security_test.go (3)

432-432: The same verification process applies to this code segment.

Refer to the previous comment for the verification script.


445-445: The same verification process applies to this code segment.

Refer to the previous comments for the verification script.


419-419: Verify the impact of the HTTPHandler function signature change.

The HTTPHandler function signature has been updated to include an additional parameter. Ensure that all calls to this function have been updated accordingly throughout the codebase.

Run the following script to verify the HTTPHandler function usage:

Verification successful

Verification successful: HTTPHandler function signature change is consistent across the codebase.

All instances of the HTTPHandler function have been updated to include the additional parameter, ensuring consistency with the new function signature. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `HTTPHandler` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'HTTPHandler'

Length of output: 4722

openapi.go (1)

126-129: LGTM!

The changes to encapsulate the route registration details into a BaseRoute struct are approved. This enhances the organization of route-related data and allows for easier future modifications.

ctx.go (6)

44-46: LGTM!

The changes to QueryParamInt and QueryParamBool methods look good. Sourcing default values from the OpenAPI spec instead of passing them as arguments is a great way to ensure consistency between the implementation and the spec.


127-128: LGTM!

The addition of the params field to the ContextNoBody struct is a good change. It allows the struct to have access to the expected query parameters declared in the OpenAPI spec, which can be used for validation and handling of query parameters.


270-273: LGTM!

The changes to the QueryParamArr method look good. Checking if the query parameter is expected in the OpenAPI spec and logging a warning for unexpected parameters is a great way to identify potential issues or inconsistencies between the implementation and the spec.


278-296: LGTM!

The changes to the QueryParam method look great! The added validation check, warning log for unexpected parameters, and returning the default value from the OpenAPI spec when the parameter is missing are all excellent improvements that enhance the method's functionality and align it with the OpenAPI spec.


303-307: LGTM!

The changes to the QueryParamInt method look good. Returning the default value from the OpenAPI spec when the parameter is missing in the request is a great improvement that aligns the method with the changes made to the QueryParam method and ensures consistency in handling missing parameters.

Also applies to: 324-334


349-353: LGTM!

The changes to the QueryParamBool method look great! Returning the default value from the OpenAPI spec when the parameter is missing and returning false instead of nil when the parameter is missing or invalid are excellent improvements. These changes enhance the method's functionality, ensure consistency with other query parameter methods, and provide a more appropriate return value for a boolean method.

Also applies to: 369-372

ctx_test.go (3)

65-69: LGTM!

The changes to the QueryParamInt method usage and assertions are consistent with the updated method signature that no longer accepts a default value.


71-72: LGTM!

The assertion correctly expects 0 when the QueryParamInt method is called with a non-integer parameter value.


94-98: LGTM!

The changes to the QueryParamBool method usage and assertions are consistent with the updated method signature that no longer accepts a default value.

serve_test.go (11)

96-96: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


103-103: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


114-114: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


128-128: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


139-139: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


150-150: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


161-161: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


172-172: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


182-182: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


200-200: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.


216-216: LGTM!

The code change is approved. The addition of the nil parameter is consistent with the updated HTTPHandler function signature.

examples/petstore/lib/testdata/doc/openapi.golden.json (6)

94-94: LGTM!

The change in the example value for age is approved.


101-104: LGTM!

The new is_adopted property is a valid addition to the Pets schema.


121-121: LGTM!

The changes to the PetsCreate schema, including the updated example value for age and the addition of the is_adopted property, are approved.

Also applies to: 126-129


146-146: LGTM!

The changes to the PetsUpdate schema, including the updated example value for age and the addition of the is_adopted property, are approved.

Also applies to: 151-155


Line range hint 180-290: LGTM!

The changes to the /pets/ path, including the updated operation description and the addition of new query parameters for filtering pets, are approved.


357-452: LGTM!

The addition of the new /pets/all path, which allows retrieving all pets with pagination support, is approved. It enhances the API's functionality and usability.

mux_test.go (8)

361-364: LGTM!

The code changes are approved. The updated route definition using the BaseRoute struct improves the structure and organization of the code.


374-382: LGTM!

The code changes are approved. Nesting the Operation field within the BaseRoute struct is consistent with the updated route definition structure.


389-389: LGTM!

The code changes are approved. The assertion correctly verifies the Description field of the Operation.


397-405: LGTM!

The code changes are approved. Nesting the Operation field within the BaseRoute struct is consistent with the updated route definition structure, even with the presence of overrides.


783-785: LGTM!

The code changes are approved. Nesting the FullName field within the BaseRoute struct is consistent with the updated route definition structure.


793-795: LGTM!

The code changes are approved. Nesting the FullName field within the BaseRoute struct is consistent with the updated route definition structure, even with the presence of the camelToHuman option.


806-808: LGTM!

The code changes are approved. Nesting the FullName field within the BaseRoute struct is consistent with the updated route definition structure across both code segments, even with the presence of various options.

Also applies to: 822-824


676-676: Verify the warning for the group path ending with a slash.

The code change itself is valid, but the comment mentions that using a path ending with a slash will generate a warning.

If the trailing slash is not needed, consider removing it to avoid the warning. You can use the following script to search for the warning message in the test output:

Verification successful

Warning for Group Path Ending with a Slash Confirmed

The Group function logs a warning when the path ends with a slash. Consider removing the trailing slash if it is not needed to avoid this warning.

  • Location of Warning: mux.go in the Group function implementation.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for the warning message in the test output.

# Test: Run the tests and search for the warning message. Expect: The warning message is found.
go test -v | rg $'warning.*slash'  

Length of output: 104


Script:

#!/bin/bash
# Search for the implementation of the Group function in the codebase.
ast-grep --lang go --pattern 'func Group($_, $_) { $$$ }'

# Search for comments or documentation mentioning warnings related to trailing slashes.
rg 'warning.*slash' -A 5

Length of output: 86


Script:

#!/bin/bash
# Search for the usage and definition of the Group function more broadly.
rg 'Group' -A 3

# Search for any logging or configuration files that might handle warnings.
rg 'log' -A 3

Length of output: 83417

ctx_params_test.go Show resolved Hide resolved
examples/petstore/services/in_memory_pets.go Show resolved Hide resolved
examples/petstore/controllers/pets.go Show resolved Hide resolved
@dylanhitt
Copy link
Collaborator

Looking to look this over one more time tomorrow.

Been a bit busy lately.

@EwenQuim
Copy link
Member Author

The last commit was fixing the last details. Ready for release

@EwenQuim
Copy link
Member Author

Btw testing CodeRabbit has been a little disappointing haha

Do you think we should remove it?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range and nitpick comments (2)
ctx.go (2)

324-337: Update the comment to reflect the new behavior.

The function comment needs to be updated to reflect that the default value is now taken from the OpenAPI spec instead of being passed as a parameter.

Apply this diff to update the comment:

-// QueryParamInt returns the query parameter with the given name as an int.
-// If it does not exist, it returns the default value declared in the OpenAPI spec.
-// For example, if the query parameter is declared as:
-//
-//	fuego.Get(s, "/test", myController,
-//	  option.QueryInt("page", "Page number", param.Default(1))
-//	)
-//
-// and the query parameter does not exist, it will return 1.
-// If the query parameter does not exist and there is no default value, or if it is not an int, it returns 0.
+// QueryParamInt returns the query parameter with the given name as an int.
+// If the query parameter does not exist, it returns the default value declared in the OpenAPI spec.
+// If the query parameter does not exist and there is no default value, or if it is not an int, it returns 0.
+//
+// Example:
+//
+//	fuego.Get(s, "/test", myController,
+//	  option.QueryInt("page", "Page number", param.Default(1))
+//	)
+//
+// If the "page" query parameter does not exist in the HTTP request, it will return the default value of 1.

376-389: Update the comment to reflect the new behavior and fix the inaccuracy.

The function comment needs to be updated to reflect that:

  1. The default value is now taken from the OpenAPI spec instead of being passed as a parameter.
  2. The function always returns a bool, so the part about returning nil needs to be removed.

Apply this diff to update the comment:

-// QueryParamBool returns the query parameter with the given name as a bool.
-// If the query parameter does not exist or is not a bool, it returns false.
-// Accepted values are defined as [strconv.ParseBool]
-// Example:
-//
-//	fuego.Get(s, "/test", myController,
-//	  option.QueryBool("is_ok", "Is OK?", param.Default(true))
-//	)
-//
-// and the query parameter does not exist in the HTTP request, it will return true.
+// QueryParamBool returns the query parameter with the given name as a bool.
+// If the query parameter does not exist, it returns the default value declared in the OpenAPI spec.
+// If the query parameter does not exist and there is no default value, or if it is not a bool, it returns false.
+// Accepted values are defined as [strconv.ParseBool].
+//
+// Example:
+//  
+//	fuego.Get(s, "/test", myController,  
+//	  option.QueryBool("is_ok", "Is OK?", param.Default(true))
+//	)
+//
+// If the "is_ok" query parameter does not exist in the HTTP request, it will return the default value of true.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 23cd32f and 5473971.

Files ignored due to path filters (8)
  • cmd/fuego/go.sum is excluded by !**/*.sum
  • examples/acme-tls/go.sum is excluded by !**/*.sum
  • examples/basic/go.sum is excluded by !**/*.sum
  • examples/custom-serializer/go.sum is excluded by !**/*.sum
  • examples/full-app-gourmet/go.sum is excluded by !**/*.sum
  • examples/hello-world/go.sum is excluded by !**/*.sum
  • examples/openapi/go.sum is excluded by !**/*.sum
  • go.sum is excluded by !**/*.sum
Files selected for processing (23)
  • cmd/fuego/commands/controller_test.go (1 hunks)
  • cmd/fuego/go.mod (3 hunks)
  • ctx.go (5 hunks)
  • ctx_params_test.go (1 hunks)
  • examples/acme-tls/go.mod (2 hunks)
  • examples/basic/go.mod (3 hunks)
  • examples/custom-serializer/go.mod (2 hunks)
  • examples/full-app-gourmet/go.mod (3 hunks)
  • examples/full-app-gourmet/templa/ingredient.list.templ (1 hunks)
  • examples/full-app-gourmet/views/admin.recipe.go (1 hunks)
  • examples/full-app-gourmet/views/ingredients.go (2 hunks)
  • examples/full-app-gourmet/views/recipe.go (1 hunks)
  • examples/hello-world/go.mod (2 hunks)
  • examples/openapi/go.mod (2 hunks)
  • examples/petstore/controllers/pets.go (4 hunks)
  • examples/petstore/lib/testdata/doc/openapi.golden.json (8 hunks)
  • go.mod (2 hunks)
  • middleware/cache/cache_test.go (2 hunks)
  • mux.go (4 hunks)
  • openapi.go (8 hunks)
  • openapi_operations.go (5 hunks)
  • openapi_test.go (1 hunks)
  • option/option.go (1 hunks)
Files skipped from review due to trivial changes (5)
  • cmd/fuego/commands/controller_test.go
  • examples/acme-tls/go.mod
  • examples/basic/go.mod
  • examples/hello-world/go.mod
  • examples/openapi/go.mod
Additional comments not posted (96)
examples/full-app-gourmet/templa/ingredient.list.templ (4)

8-10: LGTM!

The changes to the IngredientPageProps struct are approved:

  • The renaming aligns the struct name with its usage context.
  • The addition of the Header field enhances the properties available for the ingredient page.

13-19: LGTM!

The changes to the IngredientPage function are approved:

  • The renaming aligns the function name with the struct it uses.
  • The usage of the IngredientList component separates the concerns of rendering the ingredient page and the list of ingredients, promoting better modularity.

21-23: LGTM!

The addition of the IngredientListProps struct is approved:

  • The redefinition of the struct aligns with the separation of concerns introduced by the IngredientList component.
  • The struct encapsulates the properties required for rendering the list of ingredients.

25-34: LGTM!

The addition of the IngredientList function is approved:

  • The function encapsulates the rendering logic for the list of ingredients.
  • It enhances readability and maintainability by separating the concerns of rendering the ingredient page and the list of ingredients.
go.mod (6)

7-7: Dependency update looks good.

The minor version update to github.com/go-playground/validator/v10 should be safe to incorporate, as it likely includes bug fixes or small improvements without introducing breaking changes.


32-32: Dependency update looks good.

The minor version update to golang.org/x/crypto should be safe to incorporate, as it likely includes bug fixes or small improvements without introducing breaking changes.


33-33: Dependency update looks good.

The minor version update to golang.org/x/net should be safe to incorporate, as it likely includes bug fixes or small improvements without introducing breaking changes.


34-34: Dependency update looks good.

The minor version update to golang.org/x/sys should be safe to incorporate, as it likely includes bug fixes or small improvements without introducing breaking changes.


35-35: Dependency update looks good.

The minor version update to golang.org/x/text should be safe to incorporate, as it likely includes bug fixes or small improvements without introducing breaking changes.


12-12: New dependency addition looks good, but verify its usage.

The addition of github.com/thejerf/slogassert at version v0.3.4 seems to align with the goal of improving logging capabilities. However, please ensure that this dependency is being used correctly and consistently throughout the codebase.

To verify the usage of the new dependency, you can run the following script:

Verification successful

Dependency github.com/thejerf/slogassert is used appropriately in test files.

The github.com/thejerf/slogassert package is imported and used in option/option_test.go, indicating that it is utilized for logging assertions in test scenarios. This aligns with the intended purpose of the package and does not impact the production code. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `github.com/thejerf/slogassert` package.

# Test: Search for import statements of the package. Expect: At least one occurrence.
rg --type go $'github.com/thejerf/slogassert'

# Test: Search for usage of the package. Expect: Consistent usage across the codebase.
rg --type go -A 5 $'slogassert\.'

Length of output: 382

examples/custom-serializer/go.mod (5)

17-17: LGTM!

The version update of github.com/go-playground/validator/v10 from v10.22.0 to v10.22.1 is approved. It is a minor version bump that usually includes bug fixes or small improvements.


28-28: LGTM!

The version update of golang.org/x/crypto from v0.26.0 to v0.27.0 is approved. It is a minor version bump that usually includes bug fixes or small improvements.


29-29: LGTM!

The version update of golang.org/x/net from v0.28.0 to v0.29.0 is approved. It is a minor version bump that usually includes bug fixes or small improvements.


30-30: LGTM!

The version update of golang.org/x/sys from v0.24.0 to v0.25.0 is approved. It is a minor version bump that usually includes bug fixes or small improvements.


31-31: LGTM!

The version update of golang.org/x/text from v0.17.0 to v0.18.0 is approved. It is a minor version bump that usually includes bug fixes or small improvements.

ctx_params_test.go (1)

16-41: LGTM!

The test function is correctly implemented and tests the default values of query parameters.

examples/full-app-gourmet/views/ingredients.go (2)

14-17: LGTM!

The added conditional check for HTMX requests targeting the #page element enhances the function's responsiveness to client-side interactions. Returning the rendered ingredient list directly for such requests is a good approach.


37-39: LGTM!

The addition of the MetaRepository interface is a good design choice. It provides a contract for retrieving header information and allows for flexibility and extensibility by enabling different implementations of the interface. The method signature of GetHeaderInfo is appropriate, accepting a context and returning a string and an error.

cmd/fuego/go.mod (5)

11-11: Dependency update looks good, but verify compatibility.

The update to golang.org/x/text from v0.17.0 to v0.18.0 is approved.

However, ensure that this update is thoroughly tested to confirm that it is compatible with the rest of the codebase and doesn't introduce any issues.


23-23: LGTM!

The update to github.com/go-playground/validator/v10 from v10.22.0 to v10.22.1 is approved.


35-35: Dependency update looks good, but verify compatibility.

The update to golang.org/x/crypto from v0.26.0 to v0.27.0 is approved.

However, ensure that this update is thoroughly tested to confirm that it is compatible with the rest of the codebase and doesn't introduce any issues.


36-36: Dependency update looks good, but verify compatibility.

The update to golang.org/x/net from v0.28.0 to v0.29.0 is approved.

However, ensure that this update is thoroughly tested to confirm that it is compatible with the rest of the codebase and doesn't introduce any issues.


37-37: Dependency update looks good, but verify compatibility.

The update to golang.org/x/sys from v0.24.0 to v0.25.0 is approved.

However, ensure that this update is thoroughly tested to confirm that it is compatible with the rest of the codebase and doesn't introduce any issues.

examples/full-app-gourmet/go.mod (7)

6-6: Dependency version update looks good.

The minor version update for github.com/a-h/templ from v0.2.747 to v0.2.778 is approved.


9-9: Dependency version update looks good.

The pseudo-version update for github.com/go-fuego/fuego/extra/markdown from v0.0.0-20240817052016-11e0974d8e77 to v0.0.0-20240904160725-38b88648e0d4 is approved.


11-11: Dependency version update looks good.

The minor version update for github.com/golang-migrate/migrate/v4 from v4.17.1 to v4.18.1 is approved.


15-15: Dependency version update looks good.

The patch version update for github.com/rs/cors from v1.11.0 to v1.11.1 is approved.


17-17: Dependency version update looks good.

The minor version update for golang.org/x/text from v0.17.0 to v0.18.0 is approved.


18-18: Dependency version update looks good.

The minor version update for modernc.org/sqlite from v1.32.0 to v1.33.0 is approved.


30-30: Dependency version update looks good.

The patch version update for github.com/go-playground/validator/v10 from v10.22.0 to v10.22.1 is approved.

examples/full-app-gourmet/views/admin.recipe.go (1)

27-29: Duplicate comment: Handle missing query parameters to avoid potential issues.

The changes remove the default values for PerPage and Page query parameters, which allows for more flexible pagination based on user input. However, there is a risk of receiving undefined or unexpected values if the parameters are not supplied in the request.

To handle this case, consider adding default values for the query parameters as suggested in the past review comments.

examples/petstore/controllers/pets.go (3)

59-64: LGTM!

The code changes are approved. The filterPets function correctly retrieves the query parameters and passes them to the PetsService.FilterPets method using the PetsFilter struct.


53-55: Skipping comment on the page-with-typo parameter.

The existing comment from the previous review is still valid as the page-with-typo parameter is not removed.


106-109: LGTM!

The code changes are approved. The PetsFilter struct is correctly defined and used in the filterPets function to encapsulate the filtering criteria for pets.

middleware/cache/cache_test.go (2)

12-12: LGTM!

The import statement for the option package is valid and follows the correct syntax.


110-110: Looks good!

Wrapping the New middleware constructor with option.Middleware provides a more flexible way to apply middleware with additional options. Applying the middleware to a specific route using option.Middleware(New(Config{})) allows for fine-grained control over which routes have caching enabled.

This change is part of a test case that verifies the behavior when the Cache-Control header is set to no-store, ensuring that responses are not cached as expected.

openapi_operations.go (10)

25-30: LGTM!

The addition of the new fields Nullable, Default, Examples, and GoType to the OpenAPIParamOption struct enhances its capabilities and provides more flexibility in defining OpenAPI parameters.


34-38: LGTM!

The deprecation of the Description method in favor of using option.Description from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.


45-49: LGTM!

The deprecation of the Summary method in favor of using option.Summary from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.


56-60: LGTM!

The deprecation of the OperationID method in favor of using option.OperationID from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.


90-94: LGTM!

The deprecation of the Header method in favor of using option.Header from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.


101-105: LGTM!

The deprecation of the Cookie method in favor of using option.Cookie from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.


112-116: LGTM!

The deprecation of the QueryParam method in favor of using option.Query from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.


124-128: LGTM!

The deprecation of the Tags method in favor of using option.Tags from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.


136-142: LGTM!

The deprecation of the RequestContentType method in favor of using option.RequestContentType from the github.com/go-fuego/fuego/option package aligns with the new approach for defining route options.

The change from s to r.MainRouter in the SchemaTagFromType call is consistent with the usage in other parts of the code.


207-212: LGTM!

The addition of the Deprecated method provides a convenient way to mark a route as deprecated, aligning with the shift towards using options from the github.com/go-fuego/fuego/option package for route definitions.

examples/full-app-gourmet/views/recipe.go (1)

27-27: Verify the purpose and usage of the new MetaQueries field.

The new MetaQueries field of type MetaRepository is added to the Resource struct, but it is not being used in any of the handler methods.

Please ensure that:

  • The purpose and intended usage of this new field is clear.
  • The MetaRepository type is defined and imported correctly.
option/option.go (13)

12-26: LGTM!

The Group function is implemented correctly and provides a useful utility for grouping route options.


28-33: LGTM!

The Middleware function is implemented correctly and provides a convenient way to add middleware to a route.


35-47: LGTM!

The Query function is implemented correctly and provides a convenient way to declare a string query parameter for a route.


49-62: LGTM!

The QueryInt function is implemented correctly and provides a convenient way to declare an integer query parameter for a route.


64-77: LGTM!

The QueryBool function is implemented correctly and provides a convenient way to declare a boolean query parameter for a route.


79-91: LGTM!

The Header function is implemented correctly and provides a convenient way to declare a header parameter for a route.


93-105: LGTM!

The Cookie function is implemented correctly and provides a convenient way to declare a cookie parameter for a route.


107-111: LGTM!

The paramType function is implemented correctly and provides a convenient way to set the parameter type.


113-136: LGTM!

The panicsIfNotCorrectType function is implemented correctly and provides a runtime check to ensure that the example value matches the expected type.


138-183: LGTM!

The Param function is implemented correctly and provides a flexible way to register a parameter for a route. It handles the conversion between fuego.OpenAPIParam and openapi3.Parameter and applies the provided options.


185-190: LGTM!

The Tags function is implemented correctly and provides a convenient way to add tags to a route.


192-218: LGTM!

The Summary, Description, OperationID, and Deprecated functions are implemented correctly and provide convenient ways to set the corresponding fields of a route's operation.


220-250: LGTM!

The AddError, addResponse, and RequestContentType functions are implemented correctly and provide convenient ways to add error responses and set the accepted content types for a route.

mux.go (14)

47-48: LGTM!

The refactoring of the Route struct to inherit from a new BaseRoute struct is a good change. It consolidates common fields into the BaseRoute struct, allowing for clearer separation of concerns and code reuse.


50-58: LGTM!

The addition of the new BaseRoute struct is a good change. It consolidates common fields from the Route struct, allowing for clearer separation of concerns and code reuse.


64-65: LGTM!

The changes to the All function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The function now returns a pointer to the Route, which is a better practice.
  • The use of the new helper function registerFuegoController encapsulates the registration process and reduces redundancy.

68-69: LGTM!

The changes to the Get function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerFuegoController encapsulates the registration process and reduces redundancy.

72-73: LGTM!

The changes to the Post function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerFuegoController encapsulates the registration process and reduces redundancy.

76-77: LGTM!

The changes to the Delete function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerFuegoController encapsulates the registration process and reduces redundancy.

80-81: LGTM!

The changes to the Put function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerFuegoController encapsulates the registration process and reduces redundancy.

84-85: LGTM!

The changes to the Patch function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerFuegoController encapsulates the registration process and reduces redundancy.

89-92: LGTM!

The changes to the Register function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The function now returns a pointer to the Route, which is a better practice.
  • The handling of middleware has been improved by combining the server's middlewares with those defined in the route's Middlewares field.
  • Setting the MainRouter field of the route to the server is a good addition.

Also applies to: 101-101, 105-105, 123-125, 129-129, 131-131


144-144: LGTM!

The changes to the Handle function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The function now returns a pointer to the Route, which is a better practice.
  • The use of the BaseRoute struct to initialize the Route is a good change, as it consolidates common fields into the BaseRoute struct, allowing for clearer separation of concerns and code reuse.

Also applies to: 146-150


153-154: LGTM!

The changes to the AllStd function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerStdController encapsulates the registration process and reduces redundancy.

157-158: LGTM!

The changes to the GetStd function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerStdController encapsulates the registration process and reduces redundancy.

161-162: LGTM!

The changes to the PostStd function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerStdController encapsulates the registration process and reduces redundancy.

165-166: LGTM!

The changes to the DeleteStd function are good:

  • The function signature has been updated to accept options for configuring the BaseRoute, making it more flexible.
  • The use of the new helper function registerStdController encapsulates the registration process and reduces redundancy.
openapi.go (12)

126-129: LGTM!

The introduction of the BaseRoute struct improves the organization of route-related data by encapsulating the HTTP method and path for the Swagger UI registration.


176-176: LGTM!

The renaming of schemaTagFromType to SchemaTagFromType adheres to Go's idiomatic naming conventions for exported functions.


178-180: LGTM!

The updates to the return type of SchemaTagFromType and the renaming of the internal fields of the schemaTag struct to follow the exported naming convention improve consistency and adhere to Go's idiomatic practices.


186-186: LGTM!

The update to the usage of the SchemaTag type in the RequestBody reference aligns with the updated struct definition and ensures consistency throughout the codebase.


198-201: LGTM!

The update to the usage of the SchemaTag type in the responseSchema variable aligns with the updated struct definition and ensures consistency throughout the codebase.


219-219: LGTM!

The update to the newRequestBody function to utilize the new SchemaTag type ensures that the request body creation process aligns with the updated struct definitions.


227-230: LGTM!

The renaming of the schemaTag struct to SchemaTag and the internal field name to Name ensures that the struct and field names follow the exported naming convention, which is crucial for JSON serialization and other reflective operations.


233-244: LGTM!

The renaming of the function schemaTagFromType to SchemaTagFromType and the update to the return type from schemaTag to SchemaTag reflect a shift towards a more consistent naming convention that adheres to Go's idiomatic practices.


246-246: LGTM!

The update to the usage of the SchemaTag type in the dive function call aligns with the updated struct definition and ensures consistency throughout the codebase.


Line range hint 256-264: LGTM!

The updates to the handling of the tag parameter in the dive function to use the new SchemaTag type align with the updated struct definition and ensure consistency throughout the codebase.


272-275: LGTM!

The updates to the usage of the SchemaTag type in the dive function when handling slice or array types align with the updated struct definition and ensure consistency throughout the codebase.


278-283: LGTM!

The updates to the usage of the SchemaTag type in the dive function when handling default cases align with the updated struct definition and ensure consistency throughout the codebase.

openapi_test.go (1)

195-196: LGTM!

The changes adhere to Go's naming conventions for exported identifiers and struct fields.

ctx.go (2)

278-296: LGTM!

The changes to the QueryParam function look good. Returning the default value from the OpenAPI spec when the query parameter doesn't exist is a nice improvement. The warning log for unexpected query parameters is also a helpful addition.


127-128: LGTM!

Adding the params field to hold the expected query parameters from the OpenAPI spec is a good change. It supports the new functionality of using the default values from the spec.

examples/petstore/lib/testdata/doc/openapi.golden.json (7)

Line range hint 6-12: LGTM!

Removing the application/xml content type for the PetsCreate schema is a good way to streamline the API, as long as XML support is not a requirement for creating pets.


Line range hint 18-24: Verify content type handling.

Changing the content type to */* for the PetsUpdate schema provides flexibility. However, please ensure that the API implementation properly handles and validates the different content types to prevent potential security risks or parsing issues.


91-94: LGTM!

Adding the is_adopted property to the PetsCreate and PetsUpdate schemas is a valuable enhancement for tracking and filtering pets based on their adoption status.

Also applies to: 116-119, 141-145


84-84: LGTM!

Changing the age example value from 18 to 2 in the PetsCreate and PetsUpdate schemas better represents a typical pet's age, improving the schema's clarity and usability.

Also applies to: 111-111, 136-136


Line range hint 170-336: LGTM!

The changes to the /pets/ endpoint significantly enhance its functionality and usability:

  1. The updated description and summary accurately reflect the endpoint's purpose of filtering pets.
  2. The new query parameters enable pagination and filtering based on specific criteria, providing more flexibility and control to clients.
  3. The 409 Conflict response improves error handling by informing clients when a pet with the same name already exists, helping to maintain data integrity.

Great work on these enhancements!


357-452: LGTM!

The new /pets/all endpoint is a valuable addition to the API, as it allows clients to retrieve all pets with pagination support. Including both JSON and XML response formats ensures compatibility with various client needs.


163-164: Great documentation update!

The revised API description, which includes a detailed explanation of the Fuego framework and its usage, significantly improves the documentation's clarity and usefulness. The Fuego Cheatsheet and code examples are particularly helpful for developers to understand how to work with the API effectively.

openapi_operations.go Show resolved Hide resolved
@dylanhitt
Copy link
Collaborator

#176 (comment)

Yes.


mainRouter *Server // ref to the main router, used to register the route in the OpenAPI spec
MainRouter *Server // PRIVATE ref to the main router, used to register the route in the OpenAPI spec
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
MainRouter *Server // PRIVATE ref to the main router, used to register the route in the OpenAPI spec
MainRouter *Server // ref to the main router, used to register the route in the OpenAPI spec

ctx.go Outdated Show resolved Hide resolved
openapi.go Show resolved Hide resolved
@EwenQuim
Copy link
Member Author

EwenQuim commented Oct 1, 2024

As always thanks @dylanhitt and @ccoVeille for your reviews !

@EwenQuim EwenQuim merged commit 6c7cdd9 into main Oct 1, 2024
4 of 5 checks passed
@EwenQuim EwenQuim deleted the variadic-route-options branch October 1, 2024 21:50
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.

3 participants