Skip to content

Add Register method and update request handling#162

Merged
djthorpe merged 4 commits into
mainfrom
djt/0701/register
Jul 5, 2026
Merged

Add Register method and update request handling#162
djthorpe merged 4 commits into
mainfrom
djt/0701/register

Conversation

@djthorpe

@djthorpe djthorpe commented Jul 5, 2026

Copy link
Copy Markdown
Member

This pull request introduces a major refactor to the OpenAPI HTTP handler and the httprequest package, focusing on improving the ergonomics and flexibility of OpenAPI operation registration and documentation. The changes modernize the way HTTP handlers and OpenAPI metadata are registered, making the API more composable and expressive. Additionally, dependency versions are updated throughout the project.

OpenAPI Handler Refactor and Registration Improvements:

  • The OpenAPI handler (pkg/openapi/httphandler/handler.go) now uses a new, more flexible PathItem and PathOperation interface for registering HTTP endpoints and their OpenAPI documentation. The handler registration is rewritten to support richer metadata and documentation, including embedding and parsing README.md for endpoint descriptions. [1] [2]

httprequest Package API Redesign:

  • The PathItem interface is extended to support per-method registration (Get, Post, Put, etc.) with a callback for configuring the operation, and a new PathOperation interface allows for fluent configuration of tags, descriptions, parameters, request/response schemas, and more. This replaces the previous, more rigid approach. [1] [2] [3] [4]
  • Helper functions such as parametersFromQuery are added to support automatic extraction of query parameters from JSON schemas.
  • The router (pkg/httprouter/router.go) gains a new Register method that simplifies endpoint registration using the new interface.

Dependency Updates:

  • Multiple dependencies in go.mod are updated to their latest versions, including OpenTelemetry, jsonschema-go, go-client, and others, ensuring compatibility and security. [1] [2]

Documentation:

  • A new README.md is added to pkg/openapi/httphandler documenting the available OpenAPI endpoints and their formats.

Most important changes:

API Redesign and Handler Registration:

  • Introduced a new PathItem/PathOperation interface in pkg/httprequest/path.go for flexible, fluent OpenAPI operation registration, replacing the old method-based registration with a more expressive and composable API. [1] [2] [3] [4]
  • Refactored the OpenAPI handler in pkg/openapi/httphandler/handler.go to use the new registration API and to embed documentation from README.md for better endpoint descriptions. [1] [2]

Router Enhancements:

  • Added a new Register method to the router in pkg/httprouter/router.go to support the new endpoint registration workflow.

Dependency Updates:

  • Updated major dependencies in go.mod to their latest versions, including OpenTelemetry, jsonschema-go, and several others, improving security and compatibility. [1] [2]

Documentation:

  • Added a comprehensive README.md to pkg/openapi/httphandler describing the OpenAPI endpoints and their formats.

Copilot AI review requested due to automatic review settings July 5, 2026 08:37
@djthorpe
djthorpe merged commit b9622ef into main Jul 5, 2026
@djthorpe
djthorpe deleted the djt/0701/register branch July 5, 2026 08:37

Copilot AI left a comment

Copy link
Copy Markdown

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 refactors HTTP/OpenAPI endpoint registration to a new fluent PathItem/PathOperation API, updates the OpenAPI handler to register endpoints via the new router API (including embedded README-based descriptions), and bumps multiple Go dependencies.

Changes:

  • Added Router.Register to simplify route registration via a callback that configures a httprequest.PathItem.
  • Redesigned httprequest.PathItem to register per-method handlers with a PathOperation configuration callback (responses, description, query params, etc.).
  • Updated OpenAPI handler to embed README.md and populate tag/operation descriptions from parsed Markdown; updated module dependencies.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/openapi/httphandler/README.md Adds endpoint documentation used as embedded source for OpenAPI descriptions.
pkg/openapi/httphandler/handler.go Switches OpenAPI endpoint registration to new Router.Register + Markdown-derived descriptions/schemas.
pkg/httprouter/router.go Introduces Router.Register helper wrapping RegisterPath.
pkg/httprequest/path.go Introduces new PathItem/PathOperation API and query-parameter extraction helper.
go.mod Updates multiple dependencies (OpenTelemetry, jsonschema-go, etc.).
go.sum Updates checksums consistent with the dependency bumps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/httprouter/router.go
Comment on lines +221 to +225
func (r *Router) Register(path string, params *jsonschema.Schema, fn func(pathitem httprequest.PathItem)) error {
// Resolve the path with the router prefix
path = r.resolvePath(path)
pathitem := httprequest.NewPathItem("SUMMARY", "DESCRIPTION")

Comment thread pkg/httprequest/path.go
Comment on lines +25 to +27
// Get registers a GET handler with the given summary and operation options.
Get(handler http.HandlerFunc, fn func(PathOperation)) PathItem

Comment thread pkg/httprequest/path.go
Comment on lines +139 to +142
func (p *pathitem) Get(handler http.HandlerFunc, fn func(PathOperation)) PathItem {
p.handlers[http.MethodGet] = handler
p.spec.Get = types.Ptr(openapi_op.Operation(http.MethodGet, openapi_op.WithTags(p.tags...)))
if fn != nil {
Comment thread pkg/httprouter/router.go
Comment on lines +216 to +231
// Register registers a [PathItem] handler at path. If path is relative
// the router prefix is prepended. Any security schemes referenced by the
// path item's OpenAPI operations must already be registered on the router;
// matching handlers are wrapped with those security schemes before the
// router's middleware chain is applied.
func (r *Router) Register(path string, params *jsonschema.Schema, fn func(pathitem httprequest.PathItem)) error {
// Resolve the path with the router prefix
path = r.resolvePath(path)
pathitem := httprequest.NewPathItem("SUMMARY", "DESCRIPTION")

// Populate the path item by calling the provided function
fn(pathitem)

// Register the path item
return r.RegisterPath(path, params, pathitem)
}
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