Skip to content
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
f0ssel committed Oct 24, 2022
commit cead44fabfbfaa6c70a83f98e768becc3eb2a2fd
28 changes: 23 additions & 5 deletions codersdk/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,38 @@ type DeploymentConfigField[T Flaggable] struct {
// nolint: revive
func (f *DeploymentConfigField[T]) MarshalJSON() ([]byte, error) {
if !f.Secret {
return json.Marshal(f)
return json.Marshal(struct {
Name string `json:"name"`
Usage string `json:"usage"`
Flag string `json:"flag"`
Shorthand string `json:"shorthand"`
Enterprise bool `json:"enterprise"`
Hidden bool `json:"hidden"`
Secret bool `json:"secret"`
Default T `json:"default"`
Value T `json:"value"`
}{
Name: f.Name,
Usage: f.Usage,
Flag: f.Flag,
Shorthand: f.Shorthand,
Enterprise: f.Enterprise,
Hidden: f.Hidden,
Secret: f.Secret,
Default: f.Default,
Value: f.Value,
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just marshal ourselves in this case?

json.Marshal(f)

Copy link
Contributor Author

@f0ssel f0ssel Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't! I did that first and you get an infinite loop because it just calls this marshaller again. LOL

}

type SafeField[T Flaggable] struct {
return json.Marshal(struct {
Name string `json:"name"`
Usage string `json:"usage"`
Flag string `json:"flag"`
Shorthand string `json:"shorthand"`
Enterprise bool `json:"enterprise"`
Hidden bool `json:"hidden"`
Secret bool `json:"secret"`
}

return json.Marshal(SafeField[T]{
}{
Name: f.Name,
Usage: f.Usage,
Flag: f.Flag,
Expand Down