Skip to content

[7.17] Add the "es_quirk" annotation to capture snowflakes in ES behavior (#1674) #1678

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 1 commit into from
May 5, 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
4 changes: 4 additions & 0 deletions compiler/src/model/metamodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class Property {
aliases?: string[]
/** If the enclosing class is a variants container, is this a property of the container and not a variant? */
containerProperty?: boolean
/** If this property has a quirk that needs special attention, give a short explanation about it */
esQuirk?: string
}

// ------------------------------------------------------------------------------------------------
Expand All @@ -158,6 +160,8 @@ export abstract class BaseType {
docUrl?: string
docId?: string
deprecation?: Deprecation
/** If this endpoint has a quirk that needs special attention, give a short explanation about it */
esQuirk?: string
kind: string
/** Variant name for externally tagged variants */
variantName?: string
Expand Down
14 changes: 12 additions & 2 deletions compiler/src/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ export function modelEnumDeclaration (declaration: EnumDeclaration): model.Enum
type.isOpen = true
}

if (typeof tags.es_quirk === 'string') {
type.esQuirk = tags.es_quirk
}

return type
}

Expand Down Expand Up @@ -639,7 +643,8 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
// We want to enforce a single jsDoc block.
assert(jsDocs, jsDocs.length < 2, 'Use a single multiline jsDoc block instead of multiple single line blocks')

const validTags = ['class_serializer', 'doc_url', 'doc_id', 'behavior', 'variants', 'variant', 'shortcut_property', 'codegen_names', 'non_exhaustive']
const validTags = ['class_serializer', 'doc_url', 'doc_id', 'behavior', 'variants', 'variant', 'shortcut_property',
'codegen_names', 'non_exhaustive', 'es_quirk']
const tags = parseJsDocTags(jsDocs)
if (jsDocs.length === 1) {
const description = jsDocs[0].getDescription()
Expand Down Expand Up @@ -671,6 +676,8 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
type.kind === 'type_alias' && type.type.kind === 'union_of' && type.type.items.length === type.codegenNames.length,
'@codegen_names must have the number of items as the union definition'
)
} else if (tag === 'es_quirk') {
type.esQuirk = value
} else {
assert(jsDocs, false, `Unhandled tag: '${tag}' with value: '${value}' on type ${type.name.name}`)
}
Expand All @@ -684,7 +691,8 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
// We want to enforce a single jsDoc block.
assert(jsDocs, jsDocs.length < 2, 'Use a single multiline jsDoc block instead of multiple single line blocks')

const validTags = ['stability', 'prop_serializer', 'doc_url', 'aliases', 'codegen_name', 'since', 'server_default', 'variant', 'doc_id']
const validTags = ['stability', 'prop_serializer', 'doc_url', 'aliases', 'codegen_name', 'since', 'server_default',
'variant', 'doc_id', 'es_quirk']
const tags = parseJsDocTags(jsDocs)
if (jsDocs.length === 1) {
const description = jsDocs[0].getDescription()
Expand Down Expand Up @@ -764,6 +772,8 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
} else if (tag === 'variant') {
assert(jsDocs, value === 'container_property', `Unknown 'variant' value '${value}' on property ${property.name}`)
property.containerProperty = true
} else if (tag === 'es_quirk') {
property.esQuirk = value
} else {
assert(jsDocs, false, `Unhandled tag: '${tag}' with value: '${value}' on property ${property.name}`)
}
Expand Down
14 changes: 14 additions & 0 deletions docs/modeling-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ export class TermQuery extends QueryBase {
}
```

### Tracking Elasticsearch quirks

There are a few places where Elasticsearch has an uncommon behavior that does not deserve a specific feature in the API specification metamodel. These quirks still have to be captured so that code generators can act on them. The `eq_quirk` jsdoc tag is meant for that, and can be used on type definitions and properties.

```ts
/**
* @es_quirk This enum is a boolean that evolved into a tri-state enum. True and False have
* to be (de)serialized as JSON booleans.
*/
enum Foo { true, false, bar }
```

Code generators should track the `es_quirk` they implement and fail if a new unhandled quirk is present on a type or a property. This behavior allows code generators to be updated whenever a new quirk is identified in the API specification.

### Additional information

If needed, you can specify additional information on each type with the approariate JSDoc tag.
Expand Down
Loading