Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Add support for json omitempty and embedded structs in apitypings #1318

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

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented May 6, 2022

Note: This PR targets #1308, it is a continuation but I felt it warranted a separate PR.

This PR adds support for the JSON omitempty tag (reflected as a TypeScript optional) and embedded structs in the codersdk package. The properties of embedded structs now appear directly on the struct that embeds them via TypeScript interface .. extends. This behaves the same way as the Go json.Marshal and json.Unmarshal do when a struct is embedded (example playground).

As discussed in #1308 (comment), the generated typings are not ideal for comfortable use in the frontend, this tries to amend that.

If we don't want the above behavior, the field can either be named or a have json tag added.

Do these changes seem reasonable/are they helpful @presleyp @BrunoQuaresma?

@mafredri mafredri requested a review from a team as a code owner May 6, 2022 09:26
@mafredri mafredri self-assigned this May 6, 2022
@mafredri mafredri requested review from BrunoQuaresma, presleyp and a team May 6, 2022 09:26
@codecov
Copy link

codecov bot commented May 6, 2022

Codecov Report

Merging #1318 (3650ed7) into mafredri/feat-paginate-template-versions-endpoint (13fc406) will decrease coverage by 10.25%.
The diff coverage is 0.00%.

@@                                  Coverage Diff                                   @@
##           mafredri/feat-paginate-template-versions-endpoint    #1318       +/-   ##
======================================================================================
- Coverage                                              66.78%   56.52%   -10.26%     
======================================================================================
  Files                                                    282      152      -130     
  Lines                                                  18471    16624     -1847     
  Branches                                                 235        0      -235     
======================================================================================
- Hits                                                   12335     9397     -2938     
- Misses                                                  4866     6128     +1262     
+ Partials                                                1270     1099      -171     
Flag Coverage Δ
unittest-go-macos-latest 54.01% <0.00%> (-0.08%) ⬇️
unittest-go-postgres- ?
unittest-go-ubuntu-latest 56.44% <0.00%> (?)
unittest-js ?
Impacted Files Coverage Δ
codersdk/pagination.go 100.00% <ø> (ø)
scripts/apitypings/main.go 0.00% <0.00%> (ø)
coderd/devtunnel/tunnel.go 0.00% <0.00%> (-79.67%) ⬇️
coderd/database/queries.sql.go 0.00% <0.00%> (-77.91%) ⬇️
coderd/database/pubsub.go 0.00% <0.00%> (-77.78%) ⬇️
coderd/database/db.go 0.00% <0.00%> (-55.18%) ⬇️
coderd/database/migrate.go 0.00% <0.00%> (-45.00%) ⬇️
cli/config/file.go 67.64% <0.00%> (-8.83%) ⬇️
coderd/coderdtest/coderdtest.go 93.73% <0.00%> (-5.13%) ⬇️
cli/server.go 53.87% <0.00%> (-3.62%) ⬇️
... and 139 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13fc406...3650ed7. Read the comment docs.

Copy link
Contributor

@presleyp presleyp left a comment

Choose a reason for hiding this comment

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

This looks great, thanks!

@mafredri mafredri force-pushed the mafredri/feat-paginate-template-versions-endpoint branch from 04b3b1f to 13fc406 Compare May 10, 2022 07:30
@mafredri mafredri force-pushed the mafredri/feat-improve-generated-typings branch from ccade36 to 3650ed7 Compare May 10, 2022 07:33
@mafredri mafredri merged commit aab400c into mafredri/feat-paginate-template-versions-endpoint May 10, 2022
@mafredri mafredri deleted the mafredri/feat-improve-generated-typings branch May 10, 2022 07:36
mafredri added a commit that referenced this pull request May 10, 2022
…1308)

* feat: Implement pagination for template versions

* feat: Use unified pagination between users and template versions

* Sync codepaths between users and template versions

* Create requestOption type in codersdk and add test

* Fix created_at edge case for pagination cursor in queries

* feat: Add support for json omitempty and embedded structs in apitypings (#1318)

* Add scripts/apitypings/main.go to Makefile
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
…1308)

* feat: Implement pagination for template versions

* feat: Use unified pagination between users and template versions

* Sync codepaths between users and template versions

* Create requestOption type in codersdk and add test

* Fix created_at edge case for pagination cursor in queries

* feat: Add support for json omitempty and embedded structs in apitypings (#1318)

* Add scripts/apitypings/main.go to Makefile
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.

5 participants