-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lwcomponent): better JSON handling components #946
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -239,7 +239,7 @@ var ( | |||||
type Artifact struct { | ||||||
OS string `json:"os"` | ||||||
ARCH string `json:"arch"` | ||||||
URL string `json:"url"` | ||||||
URL string `json:"url,omitempty"` | ||||||
Signature string `json:"signature"` | ||||||
//Size ? | ||||||
} | ||||||
|
@@ -255,12 +255,45 @@ type Component struct { | |||||
Name string `json:"name"` | ||||||
Description string `json:"description"` | ||||||
Type Type `json:"type"` | ||||||
LatestVersion semver.Version `json:"version"` | ||||||
LatestVersion semver.Version `json:"-"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're way to smart! |
||||||
Artifacts []Artifact `json:"artifacts"` | ||||||
Breadcrumbs Breadcrumbs `json:"breadcrumbs,omitempty"` | ||||||
|
||||||
// @dhazekamp command_name required when CLICommand is true? | ||||||
CommandName string `json:"command_name"` | ||||||
CommandName string `json:"command_name,omitempty"` | ||||||
} | ||||||
|
||||||
func (c *Component) UnmarshalJSON(data []byte) error { | ||||||
type ComponentAlias Component | ||||||
type T struct { | ||||||
*ComponentAlias `json:",inline"` | ||||||
LatestVersionString string `json:"version"` | ||||||
} | ||||||
|
||||||
temp := &T{ComponentAlias: (*ComponentAlias)(c)} | ||||||
err := json.Unmarshal(data, temp) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
latestVersion, err := semver.NewVersion(temp.LatestVersionString) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
c.LatestVersion = *latestVersion | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
func (c Component) MarshalJSON() ([]byte, error) { | ||||||
type ComponentAlias Component | ||||||
type T struct { | ||||||
ComponentAlias `json:",inline"` | ||||||
LatestVersionString string `json:"version"` | ||||||
} | ||||||
|
||||||
obj := &T{ComponentAlias: (ComponentAlias)(c), LatestVersionString: c.LatestVersion.String()} | ||||||
return json.Marshal(obj) | ||||||
} | ||||||
|
||||||
// RootPath returns the component's root path ("Dir()/{name}") | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see
MarshalJSON()
andUnmarshalJSON()
methods forComponent
which properly handles this field viaLatestVersionString
. AlsoTestJSON
shows this properly being marshaled and unmarshaled.