Skip to content

Commit aebc6fe

Browse files
authored
Add doc_id support to all types (elastic#1508)
1 parent 2a61324 commit aebc6fe

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/src/model/metamodel.ts

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export abstract class BaseType {
156156
description?: string
157157
/** Link to public documentation */
158158
docUrl?: string
159+
docId?: string
159160
deprecation?: Deprecation
160161
kind: string
161162
/** Variant name for externally tagged variants */

compiler/src/model/utils.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
647647
// We want to enforce a single jsDoc block.
648648
assert(jsDocs, jsDocs.length < 2, 'Use a single multiline jsDoc block instead of multiple single line blocks')
649649

650-
const validTags = ['class_serializer', 'doc_url', 'behavior', 'variants', 'variant', 'shortcut_property', 'codegen_names']
650+
const validTags = ['class_serializer', 'doc_url', 'doc_id', 'behavior', 'variants', 'variant', 'shortcut_property', 'codegen_names']
651651
const tags = parseJsDocTags(jsDocs)
652652
if (jsDocs.length === 1) {
653653
const description = jsDocs[0].getDescription()
@@ -668,6 +668,12 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
668668
} else if (tag === 'doc_url') {
669669
assert(jsDocs, isValidUrl(value), '@doc_url is not a valid url')
670670
type.docUrl = value
671+
} else if (tag === 'doc_id') {
672+
assert(jsDocs, value.trim() !== '', `Type ${type.name.namespace}.${type.name.name}'s @doc_id cannot be empty`)
673+
type.docId = value.trim()
674+
const docUrl = docIds.find(entry => entry[0] === value.trim())
675+
assert(jsDocs, docUrl != null, `The @doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
676+
type.docUrl = docUrl[1]
671677
} else if (tag === 'codegen_names') {
672678
type.codegenNames = value.split(',').map(v => v.trim())
673679
assert(jsDocs,

0 commit comments

Comments
 (0)