Add Register method and update request handling#162
Merged
Conversation
There was a problem hiding this comment.
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.Registerto simplify route registration via a callback that configures ahttprequest.PathItem. - Redesigned
httprequest.PathItemto register per-method handlers with aPathOperationconfiguration callback (responses, description, query params, etc.). - Updated OpenAPI handler to embed
README.mdand 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 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 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 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 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) | ||
| } |
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 major refactor to the OpenAPI HTTP handler and the
httprequestpackage, 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:
pkg/openapi/httphandler/handler.go) now uses a new, more flexiblePathItemandPathOperationinterface for registering HTTP endpoints and their OpenAPI documentation. The handler registration is rewritten to support richer metadata and documentation, including embedding and parsingREADME.mdfor endpoint descriptions. [1] [2]httprequestPackage API Redesign:PathIteminterface is extended to support per-method registration (Get,Post,Put, etc.) with a callback for configuring the operation, and a newPathOperationinterface allows for fluent configuration of tags, descriptions, parameters, request/response schemas, and more. This replaces the previous, more rigid approach. [1] [2] [3] [4]parametersFromQueryare added to support automatic extraction of query parameters from JSON schemas.pkg/httprouter/router.go) gains a newRegistermethod that simplifies endpoint registration using the new interface.Dependency Updates:
go.modare updated to their latest versions, including OpenTelemetry,jsonschema-go,go-client, and others, ensuring compatibility and security. [1] [2]Documentation:
README.mdis added topkg/openapi/httphandlerdocumenting the available OpenAPI endpoints and their formats.Most important changes:
API Redesign and Handler Registration:
PathItem/PathOperationinterface inpkg/httprequest/path.gofor flexible, fluent OpenAPI operation registration, replacing the old method-based registration with a more expressive and composable API. [1] [2] [3] [4]pkg/openapi/httphandler/handler.goto use the new registration API and to embed documentation fromREADME.mdfor better endpoint descriptions. [1] [2]Router Enhancements:
Registermethod to the router inpkg/httprouter/router.goto support the new endpoint registration workflow.Dependency Updates:
go.modto their latest versions, including OpenTelemetry,jsonschema-go, and several others, improving security and compatibility. [1] [2]Documentation:
README.mdtopkg/openapi/httphandlerdescribing the OpenAPI endpoints and their formats.