Skip to content

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

Merged
mafredri merged 6 commits into
mafredri/feat-paginate-template-versions-endpointfrom
mafredri/feat-improve-generated-typings
May 10, 2022
Merged

mafredri merged 6 commits into
mafredri/feat-paginate-template-versions-endpointfrom
mafredri/feat-improve-generated-typings

Conversation

@mafredri

@mafredri mafredri commented May 6, 2022

Copy link
Copy Markdown
Member

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 May 6, 2022 09:26
@mafredri mafredri self-assigned this May 6, 2022
@mafredri
mafredri requested review from a team, BrunoQuaresma and presleyp May 6, 2022 09:26
@codecov

codecov Bot commented May 6, 2022 •

Copy link
Copy Markdown

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.

@presleyp presleyp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great, thanks!

Comment thread Makefile Resolved
Comment thread Makefile Resolved
@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
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