Skip to content
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: make schemas consistent with API #348

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hcloud/schema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ type Image struct {
Description string `json:"description"`
ImageSize *float32 `json:"image_size"`
DiskSize float32 `json:"disk_size"`
Created time.Time `json:"created"`
Created *time.Time `json:"created"`
CreatedFrom *ImageCreatedFrom `json:"created_from"`
BoundTo *int64 `json:"bound_to"`
OSFlavor string `json:"os_flavor"`
OSVersion *string `json:"os_version"`
Architecture string `json:"architecture"`
RapidDeploy bool `json:"rapid_deploy"`
Protection ImageProtection `json:"protection"`
Deprecated time.Time `json:"deprecated"`
Deleted time.Time `json:"deleted"`
Deprecated *time.Time `json:"deprecated"`
Deleted *time.Time `json:"deleted"`
Labels map[string]string `json:"labels"`
}

Expand Down
12 changes: 6 additions & 6 deletions hcloud/schema/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import "time"

// ISO defines the schema of an ISO image.
type ISO struct {
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
Architecture *string `json:"architecture"`
Deprecated time.Time `json:"deprecated"`
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
Architecture *string `json:"architecture"`
Deprecated *time.Time `json:"deprecated"`
DeprecatableResource
}

Expand Down
1 change: 1 addition & 0 deletions hcloud/schema/server_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ServerType struct {
Architecture string `json:"architecture"`
IncludedTraffic int64 `json:"included_traffic"`
Prices []PricingServerTypePrice `json:"prices"`
Deprecated bool `json:"deprecated"`
DeprecatableResource
}

Expand Down
17 changes: 17 additions & 0 deletions hcloud/schema_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,17 @@ type converter interface {
ServerTypeFromSchema(schema.ServerType) *ServerType

// goverter:map Pricings Prices
// goverter:map DeprecatableResource.Deprecation Deprecated | isDeprecationNotNil
SchemaFromServerType(*ServerType) schema.ServerType

ImageFromSchema(schema.Image) *Image

SchemaFromImage(*Image) schema.Image

// Needed because of how goverter works internally, see https://github.com/jmattheis/goverter/issues/114
// goverter:map ImageSize | mapZeroFloat32ToNil
intSchemaFromImage(Image) schema.Image

// goverter:ignore Currency
// goverter:ignore VATRate
PriceFromSchema(schema.Price) Price
Expand Down Expand Up @@ -906,3 +911,15 @@ func rawSchemaFromErrorDetails(v interface{}) json.RawMessage {
msg, _ := json.Marshal(d)
return msg
}

func mapZeroFloat32ToNil(f float32) *float32 {
fmt.Println(f)
if f == 0 {
return nil
}
return &f
}

func isDeprecationNotNil(d *DeprecationInfo) bool {
return d != nil
}
92 changes: 37 additions & 55 deletions hcloud/zz_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.