Skip to content

Commit

Permalink
Adding fixup and hack for Network.CookiePartitionKey type
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Jun 26, 2024
1 parent 9c107ad commit e5a9e6d
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 116 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2018 Kenneth Shaw
Copyright (c) 2016-2024 Kenneth Shaw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions fixup/fixup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
// - add Error() method to `Runtime.ExceptionDetails` so that it can be used
// as error.
// - change `Network.Headers` type to map[string]interface{}.
// - add special unmarshaler to `Network.CookiePartitionKey` type to handle
// different versions.
//
// Please note that the above is not an exhaustive list of all modifications
// applied to the domains, however it does attempt to give a comprehensive
Expand Down Expand Up @@ -253,6 +255,12 @@ const ModifierCommand Modifier = ModifierMeta
}
}
}

// add unmarshaler for CookiePartitionKey type
if t.Name == "CookiePartitionKey" {
t.Extra += gotpl.ExtraCookiePartitionKeyUnmarshaler(snaker.ForceCamelIdentifier(t.Name))
t.SwapEasyJSONUnmarshaler = true
}
}

case "Page":
Expand Down
29 changes: 29 additions & 0 deletions gen/gotpl/extra.qtpl
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,35 @@ func (t *{%s= typ %}) UnmarshalJSON(buf []byte) error {
}
{% endfunc %}


// ExtraCookiePartitionKeyUnmarshaler is a template that handles unmarshaling
// Network.CookiePartitionKey.
{% func ExtraCookiePartitionKeyUnmarshaler(typ string) %}
// UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
func (t *{%s= typ %}) UnmarshalEasyJSONZZ(in *jlexer.Lexer) {
buf := in.Raw()
if l := len(buf); l > 2 && buf[0] == '"' && buf[l-1] == '"' {
var err error
if t.TopLevelSite, err = strconv.Unquote(string(buf)); err != nil {
in.AddError(err)
}
return
}
dec := json.NewDecoder(bytes.NewReader(buf))
dec.DisallowUnknownFields()
var v struct{
TopLevelSite string `json:"topLevelSite"`
HasCrossSiteAncestor bool `json:"hasCrossSiteAncestor"`
}
if err := dec.Decode(&v); err != nil {
in.AddError(err)
} else {
t.TopLevelSite, t.HasCrossSiteAncestor = v.TopLevelSite, v.HasCrossSiteAncestor
}
}
{% endfunc %}


// ExtraExecutorTemplate is the additional shared executor interface for all
// the domains.
{% func ExtraExecutorTemplate() %}
Expand Down
Loading

0 comments on commit e5a9e6d

Please sign in to comment.