Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
swallez committed Jan 5, 2024
1 parent 7f3edae commit b030f44
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions docs/modeling-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,45 @@ property: Dictionary<string, string | long>

### Enum

Represents a set of allowed values:
Represents a set of allowed values.


```ts
enum MyEnum {
first = 0,
second = 1,
third = 2
first,
second,
third
}

property: MyEnum
```

Note that you don't have to provide both identifiers and values as is common in TypeScript. When there's only an identifier, the API specification compiler will use it for both the identifier and the value of enum members.

Also do not use identifiers and values for the sole purpose of providing upper-case identifiers (e.g. `FOO = 'foo'`). Each language generator will use the identifier casing that is expected by that language.

Some enumerations contain values that aren't identifiers, or that are not explicit enough. In that case you can either assign values to enum members or use the `@codegen_name` jsdoc tag to define the identifier that will be used by code generators:

```ts
enum MyEnum {
percent_of_sum,
mean,
/** @codegen_name z_score */
'z-score',
softmax
}

export enum IntervalUnit {
second = 's',
minute = 'm',
hour = 'h',
day = 'd',
week = 'w'
}
```

**Use custom identifiers for enum members sparingly**: we want to keep identifiers as close as possible to their value in JSON payloads to that usesr can easily map values found in the Elasticsearch reference documentation to code identifiers in the client libraries.

Some enumerations accept alternate values for some of their members. The `@aliases` jsdoc tac can be used to capture these values:

```ts
Expand Down

0 comments on commit b030f44

Please sign in to comment.