Skip to content

Added first version of Path handler#121

Merged
djthorpe merged 3 commits intomainfrom
djt/0330/pathhandlers
Mar 30, 2026
Merged

Added first version of Path handler#121
djthorpe merged 3 commits intomainfrom
djt/0330/pathhandlers

Conversation

@djthorpe
Copy link
Copy Markdown
Member

This pull request introduces a new Path abstraction to the httprequest package, 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 Path abstraction and OpenAPI integration:

  • Introduced the Path struct in path.go to manage HTTP paths, associate handlers by method, and generate OpenAPI PathItem specifications, including automatic extraction and registration of path parameters.
  • Implemented the Register method to associate HTTP methods with handlers and update the OpenAPI spec accordingly, with error handling for unsupported methods.
  • Added the parametersFromPath helper to parse and deduplicate path parameters, generating OpenAPI parameter definitions for each.

Testing and validation:

  • Added path_test.go with 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.

…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.
Copilot AI review requested due to automatic review settings March 30, 2026 07:01
@djthorpe djthorpe self-assigned this Mar 30, 2026
Copy link
Copy Markdown

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 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 Path type with method registration (Register), handler dispatch (Handler), and OpenAPI export (Spec).
  • Implemented parametersFromPath helper 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.

Comment thread pkg/httprequest/path.go
Comment thread pkg/httprequest/path.go Outdated
Comment thread pkg/httprequest/path.go Outdated
Comment thread pkg/httprequest/path.go
Comment thread pkg/httprequest/path_test.go Outdated
@djthorpe djthorpe merged commit 7df1174 into main Mar 30, 2026
@djthorpe djthorpe deleted the djt/0330/pathhandlers branch March 30, 2026 07:27
@djthorpe djthorpe restored the djt/0330/pathhandlers branch April 1, 2026 18:33
@djthorpe djthorpe deleted the djt/0330/pathhandlers branch April 1, 2026 19:21
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.

2 participants