fix(openapiv3,ts): map Struct/Value/ListValue to their protojson JSON projection - #233
Open
SebastienMelki wants to merge 1 commit into
Open
fix(openapiv3,ts): map Struct/Value/ListValue to their protojson JSON projection#233SebastienMelki wants to merge 1 commit into
SebastienMelki wants to merge 1 commit into
Conversation
… projection google.protobuf.Struct, Value, and ListValue were emitted in openapiv3 and the TS generators (tscommon/tsclientgen/tsservergen) as their protobuf descriptor shape (the internal oneof/map fields) instead of the JSON they actually serialize to under protojson: a plain object, any JSON value, and a plain array respectively. This is the same class of defect #226 fixed for the wrapper types (DoubleValue, StringValue, ...), just not yet extended to these three well-known types. Adds internal/annotations/structpb_types.go with shared detection helpers, and mirrors the existing wrapper-type special-casing in both generators: Struct -> {type: object, additionalProperties: true} / Record<string, unknown> Value -> {} (any value) / unknown ListValue -> {type: array, items: {}} / unknown[] Covers singular, repeated, and map-value fields, direct RPC input/output, and (openapiv3) SSE streaming. Go (httpgen/clientgen) and Python (pyclientgen) were unaffected -- structpb already has correct protojson semantics natively in Go, and pyclientgen already special-cased these types correctly. Fixes #230 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
- Coverage 30.54% 30.46% -0.08%
==========================================
Files 67 68 +1
Lines 11404 11432 +28
==========================================
Hits 3483 3483
- Misses 7750 7776 +26
- Partials 171 173 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🔍 CI Pipeline Status✅ Lint: success 📊 Coverage Report: Available in checks above |
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.
Summary
google.protobuf.Struct,Value, andListValuewere emitted byopenapiv3and the TS generators (tscommon/tsclientgen/tsservergen) in their protobuf descriptor shape (internal oneof/map fields) instead of the JSON they actually serialize to underprotojson— a plain object, any JSON value, and a plain array, respectively.#226fixed for the wrapper types (DoubleValue,StringValue, ...); this extends the same mechanism toStruct/Value/ListValue.internal/annotations/structpb_types.gowith shared detection helpers (IsStructMessage,IsValueMessage,IsListValueMessage,IsStructWellKnownMessage,IsStructWellKnownField), consumed by both generators.Struct{type: object, additionalProperties: true}Record<string, unknown>Value{}(any value)unknownListValue{type: array, items: {}}unknown[]httpgen/clientgen) and Python (pyclientgen) were unaffected:structpbalready has correctprotojsonsemantics natively in Go, andpyclientgenalready special-cased these three types correctly.Fixes #230
Test plan
go build ./...gofmt -l .(clean)go vet ./...go test ./internal/annotations/... ./internal/openapiv3/... ./internal/tscommon/... ./internal/tsclientgen/... ./internal/tsservergen/... ./internal/httpgen/...structpb_types.proto) added for openapiv3 (incl. direct-WKT RPC + SSE) and ts-client/ts-server (incl. direct-WKT RPC as request/response type);UPDATE_GOLDEN=1output eyeballed to confirm noStruct/Value/ListValuedescriptor-shaped schema/interface leaks into generated output🤖 Generated with Claude Code