Skip to content

Commit

Permalink
feat: add option to render all struct-like objects with a name field
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-greene-ck committed Apr 16, 2019
1 parent 7d719f8 commit d1b31f8
Show file tree
Hide file tree
Showing 70 changed files with 1,281 additions and 1,777 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The available options are:
* --target: The core library to generate for, either 'apache' or 'thrift-server'. Defaults to 'apache'.
* --strictUnions: Should we generate strict unions (Only available for target = 'thrift-server'. More on this below). Defaults to undefined.
* --fallbackNamespace: The namespace to fallback to if no 'js' namespace exists. Defaults to 'java'. Set to 'none' to use no namespace.
* --withNameField: Should we generate a `__name` field on each struct-like object that contains its Thrift name (Only available for target = 'thrift-server'). Defaults to undefined.

All other fields are assumed to be source files.

Expand All @@ -50,6 +51,8 @@ You can gen code from more than one Thrift file:
$ thrift-typescript one.thrift two.thrift three.thrift
```

#### JavaScript API

You can also generate files using the JavaScript API:

```typescript
Expand All @@ -68,7 +71,9 @@ generate({
})
```

You can generate TypeScript from a string of Thrift without saving to file.
#### Thrift to String

You can also generate TypeScript from a string of Thrift without saving to file.

Note: This method of code generation does not support includes. The Thrift generator must be able to resolve all identifiers which it can't do without a description of the file structure.

Expand Down Expand Up @@ -264,6 +269,23 @@ export interface IUser {

Only fields that are explicitly required loose the `?`.

##### The `__name` Field

You can pass an option to generate an additional property on each struct-like (structs, unions, exceptions) object that is its literal name in the Thrift file.

For example if we rendered the `User` struct with the `--withNameField` option the generated TypeScript would change:

```typescript
export interface IUser {
__name: "User"
name: string
email?: string
id: number
}
```

When generating with this option any data types you create and pass into a client method do not need the `__name` field. However, any data you get back from a service will contain this additional property.

#### Union

Unions in Thrift are very similar to structs. The difference is they only allow one field to be set. They also require that one field is set. Implicitly all fields are optional, but one field must be set.
Expand Down
Loading

0 comments on commit d1b31f8

Please sign in to comment.