Add router export and type schema generation; add Codec.Name()#109
Add router export and type schema generation; add Codec.Name()#109Suhaibinator wants to merge 1 commit intoclaude/s-router-export-spec-lMj0ifrom
Conversation
There was a problem hiding this comment.
💡 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".
|
|
||
| tag := field.Tag.Get("json") | ||
| if tag != "" { |
There was a problem hiding this comment.
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...) |
There was a problem hiding this comment.
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 👍 / 👎.
Motivation
json,proto) a route uses.Description
Name()to theCodecinterface and implement it inJSONCodecandProtoCodec, and update test/mock codecs to implementName()so codecs can be identified in metadata viaCodec.Name().routeMetadataandmetadataMutoRouter, and appendRouteMetadatainRegisterRoute,registerSubRouter, and the generic route registration path (registerGenericRouteInternal).reflect.goto buildTypeSchematrees from Go types (handling nested structs, slices, maps andjsontags) and use reflection to populateRequestandResponseschemas for generic routes.export.goto produceExportSpecand helpersExportJSON/ExportJSONFile, and include conversion helpers for auth, CORS, rate-limit and source types.reflect_test.goandexport_test.go, and update existing tests/mocks (cors_test.go,route_test.go) to conform to the newCodecinterface and metadata behavior.Testing
go test ./pkg/routerwhich executedTestBuildTypeSchemaandTestExportSpecIncludesRegisteredRoutesand they passed.go test ./...to validate integration with modified interfaces and tests, and they completed successfully.Codex Task