Open
Description
I recently needed to serialize some objects from the go SDK and noticed that the objects do not serialize/deserialize consistently with the JSON encoding.
This is due to json:"-"
tags in the go objects from the SDK.
Exemple:
type GetServerRequest struct {
// Zone:
//
// Zone to target. If none is passed will use default zone from the config
Zone scw.Zone `json:"-"`
// ServerID: UUID of the server you want to get
ServerID string `json:"-"`
}
I understand that this makes sense when generating request bodies because these fields are actually passed in the url. But, as a user of the SDK this behaviour is surprising and makes using these objects outside of just api requests difficult.
So i think you should either:
- document this limitation
- fix these objects so they can have a more standard behaviour
A possible workaround is having exported objects without the json tags and implementing internal objects that have the same structure but include the tags.
Example:
type GetServerRequest struct {
Zone string
ServerID string
}
type internalGetServerRequest struct {
Zone string `json:"-"`
ServerID string `json:"-"`
}
type GetServerResponse struct {
// ...
}
func GetServer(ctx context.Context, req *GetServerRequest) (*GetServerResponse, error) {
ireq := (*internalGetServerRequest)(req)
// do the api call using json representation of ireq instead of req
}