Skip to content

Commit 456a02b

Browse files
committed
codegen/json: write an unset type_expr as null again
The regex that stripped the member from protojson's output was a hack around EmitUnpopulated, which has no per-field form. A column the legacy path typed now carries "type_expr": null like every other unset message field, and the goldens are regenerated. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rfiHyC4iRLyRWc3UmYEtT
1 parent 61ee60d commit 456a02b

3 files changed

Lines changed: 9916 additions & 4975 deletions

File tree

‎internal/codegen/json/gen.go‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
ejson "encoding/json"
77
"fmt"
8-
"regexp"
98

109
"google.golang.org/protobuf/encoding/protojson"
1110

@@ -53,7 +52,6 @@ func Generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.Generat
5352
if err != nil {
5453
return nil, err
5554
}
56-
data = dropUnsetTypeExpr(data)
5755
var rm ejson.RawMessage = data
5856
blob, err := ejson.MarshalIndent(rm, "", indent)
5957
if err != nil {
@@ -68,18 +66,3 @@ func Generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.Generat
6866
},
6967
}, nil
7068
}
71-
72-
// unsetTypeExpr matches a column's type_expr member when it is unset, with
73-
// the comma that joins it to the member before it. It is the last member
74-
// of a column, so protojson writes it after a comma, with whatever
75-
// whitespace it chose around the separators.
76-
var unsetTypeExpr = regexp.MustCompile(`,\s*"type_expr"\s*:\s*null`)
77-
78-
// dropUnsetTypeExpr removes the type_expr member from columns that have
79-
// none. The member is only set when the analysis core typed the column,
80-
// and a column the legacy path typed is written the way it was before the
81-
// member existed rather than with an explicit null. A JSON string cannot
82-
// hold an unescaped quote, so the match never lands inside one.
83-
func dropUnsetTypeExpr(data []byte) []byte {
84-
return unsetTypeExpr.ReplaceAll(data, nil)
85-
}

0 commit comments

Comments
 (0)