Skip to content

Commit

Permalink
feat(go2proto): directly support `encoding.{TextMarshaler,BinaryMarsh…
Browse files Browse the repository at this point in the history
…aler}` (#3719)

Repeated fields of this type aren't supported yet, as that needs some
changes to support importing external types. Will do in a followup.
  • Loading branch information
alecthomas authored Dec 13, 2024
1 parent 46427d2 commit b7d6836
Show file tree
Hide file tree
Showing 21 changed files with 649 additions and 318 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.frontend.lock
.hermit/
.vscode/*
.registry/
Expand Down Expand Up @@ -53,4 +54,4 @@ charts/**/output/
__pycache__/
*.pyc
*.pyo
.venv/
.venv/
2 changes: 1 addition & 1 deletion backend/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestResponseBodyForVerb(t *testing.T) {
&schema.Data{
Name: "Test",
Fields: []*schema.Field{
{Name: "message", Type: &schema.String{}, Metadata: []schema.Metadata{&schema.MetadataAlias{Kind: schema.AliasKindJson, Alias: "msg"}}},
{Name: "message", Type: &schema.String{}, Metadata: []schema.Metadata{&schema.MetadataAlias{Kind: schema.AliasKindJSON, Alias: "msg"}}},
},
},
jsonVerb,
Expand Down
4 changes: 2 additions & 2 deletions backend/ingress/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func parseQueryParams(values map[string][]string, data *schema.Data) (map[string
}
var field *schema.Field
for _, f := range data.Fields {
if jsonAlias, ok := f.Alias(schema.AliasKindJson).Get(); (ok && jsonAlias == key) || f.Name == key {
if jsonAlias, ok := f.Alias(schema.AliasKindJSON).Get(); (ok && jsonAlias == key) || f.Name == key {
field = f
}
for _, typeParam := range data.TypeParameters {
Expand Down Expand Up @@ -369,7 +369,7 @@ func parsePathParams(values map[string]string, data *schema.Data) (map[string]an
for key, value := range values {
var field *schema.Field
for _, f := range data.Fields {
if jsonAlias, ok := f.Alias(schema.AliasKindJson).Get(); (ok && jsonAlias == key) || f.Name == key {
if jsonAlias, ok := f.Alias(schema.AliasKindJSON).Get(); (ok && jsonAlias == key) || f.Name == key {
field = f
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/ingress/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func bodyForType(typ schema.Type, sch *schema.Schema, data []byte) ([]byte, erro
}

err = schema.TransformAliasedFields(sch, t, response, func(obj map[string]any, field *schema.Field) string {
if jsonAlias, ok := field.Alias(schema.AliasKindJson).Get(); ok && field.Name != jsonAlias {
if jsonAlias, ok := field.Alias(schema.AliasKindJSON).Get(); ok && field.Name != jsonAlias {
obj[jsonAlias] = obj[field.Name]
delete(obj, field.Name)
return jsonAlias
Expand Down
Loading

0 comments on commit b7d6836

Please sign in to comment.