Skip to content

Add router export and type schema generation; add Codec.Name()#109

Open
Suhaibinator wants to merge 1 commit intoclaude/s-router-export-spec-lMj0ifrom
codex/plan-implementation-of-export-feature
Open

Add router export and type schema generation; add Codec.Name()#109
Suhaibinator wants to merge 1 commit intoclaude/s-router-export-spec-lMj0ifrom
codex/plan-implementation-of-export-feature

Conversation

@Suhaibinator
Copy link
Copy Markdown
Owner

Motivation

  • Provide a machine-readable export of registered routes and service configuration for documentation, tooling and runtime introspection via a standardized spec.
  • Capture request/response shapes for generic routes by reflecting Go types so external tools can understand payload schemas.
  • Expose codec identity so exported metadata can record which codec (e.g., json, proto) a route uses.

Description

  • Add Name() to the Codec interface and implement it in JSONCodec and ProtoCodec, and update test/mock codecs to implement Name() so codecs can be identified in metadata via Codec.Name().
  • Introduce router metadata support by adding routeMetadata and metadataMu to Router, and append RouteMetadata in RegisterRoute, registerSubRouter, and the generic route registration path (registerGenericRouteInternal).
  • Add reflect.go to build TypeSchema trees from Go types (handling nested structs, slices, maps and json tags) and use reflection to populate Request and Response schemas for generic routes.
  • Add export.go to produce ExportSpec and helpers ExportJSON/ExportJSONFile, and include conversion helpers for auth, CORS, rate-limit and source types.
  • Add tests for the reflection and export features in reflect_test.go and export_test.go, and update existing tests/mocks (cors_test.go, route_test.go) to conform to the new Codec interface and metadata behavior.

Testing

  • Ran unit tests for the router package with go test ./pkg/router which executed TestBuildTypeSchema and TestExportSpecIncludesRegisteredRoutes and they passed.
  • Ran project-wide tests with go test ./... to validate integration with modified interfaces and tests, and they completed successfully.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 321df40daa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +46 to +48

tag := field.Tag.Get("json")
if tag != "" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip fields tagged json:"-" when building schemas

The schema builder still appends exported fields even when the JSON tag is "-", because the tag parsing only avoids setting JSONName and never short-circuits field inclusion. That makes exported route schemas include fields intentionally excluded from request/response JSON payloads, which can mislead tooling and expose internal field names/types in ExportSpec. Add a continue for json:"-" before appending the field schema.

Useful? React with 👍 / 👎.

}

r.metadataMu.RLock()
routes := append([]RouteMetadata(nil), r.routeMetadata...)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Return a deep copy from ExportSpec

ExportSpec currently copies only the top-level routeMetadata slice, but each RouteMetadata still shares nested references (Methods slice and pointer fields like Request, Response, RateLimit, AuthToken) with router internals. If callers modify the returned spec, they can mutate the router’s stored metadata and affect subsequent exports, violating snapshot semantics and risking races in concurrent use. Construct a deep copy of each route entry before returning.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant