Skip to content

feat: Switch packages for typescript generation code #1196

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

Merged
merged 18 commits into from
Apr 28, 2022
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
2 changes: 2 additions & 0 deletions codersdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func New(serverURL *url.URL) *Client {
}

// Client is an HTTP caller for methods to the Coder API.
// @typescript-ignore Client
type Client struct {
HTTPClient *http.Client
SessionToken string
Expand Down Expand Up @@ -113,6 +114,7 @@ func readBodyAsError(res *http.Response) error {
}

// Error represents an unaccepted or invalid request to the API.
// @typescript-ignore Error
type Error struct {
httpapi.Response

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ require (
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
golang.org/x/text v0.3.7
golang.org/x/tools v0.1.10
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f
google.golang.org/api v0.75.0
google.golang.org/protobuf v1.28.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,7 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
40 changes: 40 additions & 0 deletions scripts/apitypings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# APITypings
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Wonderful documentation!


This main.go generates typescript types from the codersdk types in Go.

# Features

- Supports Go types
- [x] Basics (string/int/etc)
- [x] Maps
- [x] Slices
- [x] Enums
- [x] Pointers
- [ ] External Types (uses `any` atm)
- Some custom external types are hardcoded in (eg: time.Time)


## Type overrides

```golang
type Foo struct {
// Force the typescript type to be a number
CreatedAt time.Duration `json:"created_at" typescript:"number"`
}
```

## Ignore Types

Do not generate ignored types.

```golang
// @typescript-ignore InternalType
type InternalType struct {
// ...
}
```

# Future Ideas

- Should `omitempty` in the `json` tag indicate optional?
- Use a yaml config for overriding certain types
Loading