Conversation
…rs from path segments. This is a bit of a hack but it allows us to support dynamic paths without having to define them in the spec.
There was a problem hiding this comment.
Pull request overview
This PR adds a new Path abstraction to pkg/httprequest to centralize HTTP path handling, OpenAPI PathItem generation, and extracting {param} segments from URL paths, along with initial unit tests.
Changes:
- Added
Pathtype with method registration (Register), handler dispatch (Handler), and OpenAPI export (Spec). - Implemented
parametersFromPathhelper to extract/deduplicate{param}segments into OpenAPI path parameters. - Added unit tests for parameter extraction and (intended) immutability behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pkg/httprequest/path.go | Introduces Path and OpenAPI integration, including method registration and path-parameter extraction. |
| pkg/httprequest/path_test.go | Adds tests covering parametersFromPath behavior and a parameter “immutability” check. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new
Pathabstraction to thehttprequestpackage, which encapsulates HTTP path handling, OpenAPI operation registration, and parameter extraction from URL paths. It also adds comprehensive unit tests to ensure correct parameter extraction and immutability of internal state.New
Pathabstraction and OpenAPI integration:Pathstruct inpath.goto manage HTTP paths, associate handlers by method, and generate OpenAPIPathItemspecifications, including automatic extraction and registration of path parameters.Registermethod to associate HTTP methods with handlers and update the OpenAPI spec accordingly, with error handling for unsupported methods.parametersFromPathhelper to parse and deduplicate path parameters, generating OpenAPI parameter definitions for each.Testing and validation:
path_test.gowith tests for parameter extraction logic and to verify that the internal parameter slice is not mutated by external changes, ensuring robustness and correctness.…rs from path segments. This is a bit of a hack but it allows us to support dynamic paths without having to define them in the spec.