docs: resolve example tag in DML properties (#14383)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-12-22 17:52:24 +02:00
1 parent 04a6343951
commit 662ec7430b
8 files changed
+40 -2

No files matched your search

@@ -133,7 +133,7 @@ const TypeListItem = ({
return ( return (
<DetailsSummary <DetailsSummary
subtitle={ subtitle={
item.description || item.defaultValue ? ( item.description || item.defaultValue || item.example ? (
<> <>
{item.description && ( {item.description && (
<MarkdownContent <MarkdownContent
@@ -176,6 +176,11 @@ const TypeListItem = ({
Default: <InlineCode>{item.defaultValue}</InlineCode> Default: <InlineCode>{item.defaultValue}</InlineCode>
</p> </p>
)} )}
{item.example && (
<div className="mt-0.5">
Example: <InlineCode>{item.example}</InlineCode>
</div>
)}
</> </>
) : undefined ) : undefined
} }
@@ -13,6 +13,7 @@ export type Type = {
type: string type: string
optional?: boolean optional?: boolean
defaultValue?: string defaultValue?: string
example?: string
description?: string description?: string
featureFlag?: string featureFlag?: string
expandable: boolean expandable: boolean
@@ -607,12 +607,14 @@ class DefaultKindGenerator<T extends ts.Node = ts.Node> {
sinceTag: ts.JSDocTag | undefined sinceTag: ts.JSDocTag | undefined
featureFlagTag: ts.JSDocTag | undefined featureFlagTag: ts.JSDocTag | undefined
summary: string | undefined summary: string | undefined
example: ts.JSDocTag | undefined
} { } {
const nodeComments = ts.getJSDocCommentsAndTags(node) const nodeComments = ts.getJSDocCommentsAndTags(node)
let deprecatedTag: ts.JSDocTag | undefined let deprecatedTag: ts.JSDocTag | undefined
let sinceTag: ts.JSDocTag | undefined let sinceTag: ts.JSDocTag | undefined
let featureFlagTag: ts.JSDocTag | undefined let featureFlagTag: ts.JSDocTag | undefined
let summary: string | undefined let summary: string | undefined
let example: ts.JSDocTag | undefined
nodeComments.forEach((comment) => { nodeComments.forEach((comment) => {
if (!("tags" in comment)) { if (!("tags" in comment)) {
@@ -637,6 +639,10 @@ class DefaultKindGenerator<T extends ts.Node = ts.Node> {
if (tag.tagName.getText() === "featureFlag") { if (tag.tagName.getText() === "featureFlag") {
featureFlagTag = tag featureFlagTag = tag
} }
if (tag.tagName.getText() === "example") {
example = tag
}
}) })
}) })
@@ -645,6 +651,7 @@ class DefaultKindGenerator<T extends ts.Node = ts.Node> {
sinceTag, sinceTag,
featureFlagTag, featureFlagTag,
summary, summary,
example,
} }
} }
@@ -243,7 +243,7 @@ class DmlKindGenerator extends DefaultKindGenerator<ts.CallExpression> {
) )
const isBoolean = propertyTypeStr.includes("BooleanProperty") const isBoolean = propertyTypeStr.includes("BooleanProperty")
const relationName = isRelation ? camelToWords(propertyName) : undefined const relationName = isRelation ? camelToWords(propertyName) : undefined
const { summary, sinceTag, deprecatedTag, featureFlagTag } = const { summary, sinceTag, deprecatedTag, featureFlagTag, example } =
this.getInformationFromTags(propertyNode) this.getInformationFromTags(propertyNode)
let propertyDescription = let propertyDescription =
@@ -286,6 +286,12 @@ class DmlKindGenerator extends DefaultKindGenerator<ts.CallExpression> {
}` }`
} }
if (example) {
propertyDescription += `\n\n@example ${
this.formatJSDocTag(example) ?? ""
}`
}
properties[propertyName] = propertyDescription properties[propertyName] = propertyDescription
}) })
@@ -16,6 +16,7 @@ const FILE_NAME_REGEX = /packages\/modules\/(?<module>[a-z-]+)/
const SINCE_REGEX = /@since\s+([\d.]+)/ const SINCE_REGEX = /@since\s+([\d.]+)/
const DEPRECATED_REGEX = /@deprecated\s+(.+)/ const DEPRECATED_REGEX = /@deprecated\s+(.+)/
const FEATURE_FLAG_REGEX = /@featureFlag\s+(\S+)/ const FEATURE_FLAG_REGEX = /@featureFlag\s+(\S+)/
const EXAMPLE_REGEX = /@example\s+([\s\S]+)/
export function load(app: Application) { export function load(app: Application) {
app.converter.on( app.converter.on(
@@ -132,6 +133,7 @@ function getDescriptionsFromJson(
const sinceMatch = description.match(SINCE_REGEX) const sinceMatch = description.match(SINCE_REGEX)
const featureFlagMatch = description.match(FEATURE_FLAG_REGEX) const featureFlagMatch = description.match(FEATURE_FLAG_REGEX)
const deprecatedMatch = description.match(DEPRECATED_REGEX) const deprecatedMatch = description.match(DEPRECATED_REGEX)
const exampleMatch = description.match(EXAMPLE_REGEX)
comment.summary.push({ comment.summary.push({
kind: "text", kind: "text",
@@ -140,6 +142,7 @@ function getDescriptionsFromJson(
.replace(SINCE_REGEX, "") .replace(SINCE_REGEX, "")
.replace(FEATURE_FLAG_REGEX, "") .replace(FEATURE_FLAG_REGEX, "")
.replace(DEPRECATED_REGEX, "") .replace(DEPRECATED_REGEX, "")
.replace(EXAMPLE_REGEX, "")
.trim(), .trim(),
}) })
@@ -180,6 +183,17 @@ function getDescriptionsFromJson(
) )
} }
if (exampleMatch) {
comment.blockTags.push(
new CommentTag("@example", [
{
kind: "text",
text: exampleMatch[1],
},
])
)
}
propertyReflection.comment = comment propertyReflection.comment = comment
} }
) )
@@ -30,6 +30,7 @@ export type Parameter = {
type: string type: string
optional?: boolean optional?: boolean
defaultValue?: string defaultValue?: string
example?: string
description?: string description?: string
featureFlag?: string featureFlag?: string
expandable: boolean expandable: boolean
@@ -133,6 +133,7 @@ export function reflectionComponentFormatter({
reflection.flags.isOptional || reflection.flags.isOptional ||
reflection.kind === ReflectionKind.EnumMember reflection.kind === ReflectionKind.EnumMember
const comments = getComments(reflection) const comments = getComments(reflection)
const example = comments?.blockTags.find((tag) => tag.tag === "@example")
const deprecatedTag = comments?.blockTags.find( const deprecatedTag = comments?.blockTags.find(
(tag) => tag.tag === "@deprecated" (tag) => tag.tag === "@deprecated"
) )
@@ -159,6 +160,8 @@ export function reflectionComponentFormatter({
: "", : "",
optional, optional,
defaultValue, defaultValue,
example:
example?.content?.map((c) => stripCode(c.text)).join("") || undefined,
expandable: reflection.comment?.hasModifier(`@expandable`) || false, expandable: reflection.comment?.hasModifier(`@expandable`) || false,
featureFlag: Handlebars.helpers.featureFlag(reflection.comment), featureFlag: Handlebars.helpers.featureFlag(reflection.comment),
children: [], children: [],
+1
View File
@@ -313,6 +313,7 @@ export declare type DmlFile = {
description?: string description?: string
} }
featureFlag?: string featureFlag?: string
example?: string
} }
} }