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

feat: add conversion methods from schema to hcloud objects #343

Merged
merged 9 commits into from
Dec 12, 2023
Merged

Conversation

phm07
Copy link
Contributor

@phm07 phm07 commented Nov 23, 2023

This PR adds automatic generation of schema conversion methods in schema.go with goverter.

Previously, schema.go was manually written. This is a tedious task and is also prone to errors.

This PR also adds new methods to convert hcloud objects back into schemas. This allows for round trip testing (converting schema -> hcloud -> schema or hcloud -> schema -> hcloud and testing for equality) and allows for removal of redundant code in hcloud/cli.

Since the round trip tests ensure that a schema converts into an hcloud object and back, formatting will be consistent between conversions. This would fix issues like hetznercloud/cli#461.

@phm07 phm07 self-assigned this Nov 23, 2023
@phm07 phm07 force-pushed the goverter branch 2 times, most recently from 4fbf0f6 to 74c1bd4 Compare November 30, 2023 15:14
@phm07 phm07 marked this pull request as ready for review November 30, 2023 15:14
@phm07 phm07 requested a review from a team as a code owner November 30, 2023 15:14
@phm07 phm07 force-pushed the goverter branch 2 times, most recently from 047a226 to 701f381 Compare November 30, 2023 15:32
@phm07
Copy link
Contributor Author

phm07 commented Dec 2, 2023

@jmattheis Feel free to leave some feedback here 🙂 Maybe something can be done better/more efficiently than how I did it

Copy link

@jmattheis jmattheis left a comment

Choose a reason for hiding this comment

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

The goverter usage looks good to me. I've added two "maybe" improvements as comments.

hcloud/schema_gen.go Outdated Show resolved Hide resolved
hcloud/schema_gen.go Show resolved Hide resolved
@phm07 phm07 changed the title refactor: automatically generate schema conversions with goverter feat: add conversion methods from schema to hcloud objects Dec 7, 2023
script/generate_schema.sh Outdated Show resolved Hide resolved
hcloud/schema.go Show resolved Hide resolved
hcloud/schema_gen.go Show resolved Hide resolved
hcloud/schema_gen.go Show resolved Hide resolved
hcloud/schema_gen.go Show resolved Hide resolved
phm07 and others added 9 commits December 12, 2023 08:41
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| golang.org/x/net | require | minor | `v0.18.0` -> `v0.19.0` |

---

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuODEuMyIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Copy link
Member

@apricote apricote left a comment

Choose a reason for hiding this comment

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

🚀

@phm07 phm07 merged commit 6feda4d into main Dec 12, 2023
5 checks passed
@phm07 phm07 deleted the goverter branch December 12, 2023 07:46
phm07 added a commit that referenced this pull request Dec 12, 2023
Multiple properties were missing, even though they are documented in the
API docs.

This PR needs #343 to be
merged first.

Continuation of #347
phm07 pushed a commit that referenced this pull request Dec 12, 2023
🤖 I have created a release *beep* *boop*
---


##
[2.5.0](v2.4.0...v2.5.0)
(2023-12-12)


### Features

* add conversion methods from schema to hcloud objects
([#343](#343))
([6feda4d](6feda4d))
* add interfaces for client structs
([#342](#342))
([4f9390f](4f9390f))
* add missing properties
([#349](#349))
([c8a28d0](c8a28d0))
* **error:** include http response in api errors
([#320](#320))
([9558239](9558239))


### Bug Fixes

* make schemas consistent with API
([#348](#348))
([b0d7055](b0d7055))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants