elastic / elastic/elasticsearch-specification

Support for enums which serialize as a numeric value

Open
#477 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
158
Forks
136
Avg merge
19h 48m
Merged PRs (30d)
54

Description

Right now, most enums are treated as strings when serialized where the name of members is the string that is used in the JSON.

I'm looking at `GeoTilePrecision` which right now is defined as `export type GeoTilePrecision = number`. In the .NET client, we [define this](https://github.com/elastic/elasticsearch-net/blob/7.x/src/Nest/Aggregations/Bucket/GeoTileGrid/GeoTilePrecision.cs) as an enum since the range is limited 0-29 and most values have a specific meaning which we include in the IntelliSense documentation e.g.
```c#
public enum GeoTilePrecision
{
///
/// Whole world
///
Precision0 = 0,
Precision1 = 1,
///
/// Subcontinental area
///
Precision2 = 2,
...
}
```
This provides a way to help consumers choose a valid value, while also providing a descriptive tooltip for values where possible.

I'd like to encode this in the spec, but I believe right now, it would assume the value to be serialised to/from a string. It's a similar story for `GeoHashPrecision`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked elasticsearch-net file src/Nest/Aggregations/Bucket/GeoTileGrid/GeoTilePrecision.cs and compare it with the specification's current enum serialization behavior. Trace how GeoTilePrecision and GeoHashPrecision would be represented, then define the spec behavior for numeric enum serialization and verify it against the affected generated clients.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.