diff --git a/compile-to-definitions/index.js b/compile-to-definitions/index.js index 32cbe4d..ce38bb3 100644 --- a/compile-to-definitions/index.js +++ b/compile-to-definitions/index.js @@ -101,6 +101,13 @@ const resolvePath = (root, ref) => { }; const preprocessSchema = (schema, root = schema, path = []) => { + if (schema.default !== undefined) { + const defaultTag = `@default ${JSON.stringify(schema.default)}`; + schema.description = schema.description + ? `${schema.description}\n${defaultTag}` + : defaultTag; + delete schema.default; + } if (schema.experimental) { const experimental = typeof schema.experimental === "string" @@ -130,6 +137,7 @@ const preprocessSchema = (schema, root = schema, path = []) => { description: result.description, deprecated: result.deprecated, experimental: result.experimental, + default: result.default, anyOf: [property], }; } else if ( @@ -142,6 +150,8 @@ const preprocessSchema = (schema, root = schema, path = []) => { description: property.description || result.description, deprecated: property.deprecated || result.deprecated, experimental: property.experimental || result.experimental, + default: + property.default !== undefined ? property.default : result.default, anyOf: property.oneOf, }; preprocessSchema(schema.properties[key], root, [...path, key]); diff --git a/format-schemas/index.js b/format-schemas/index.js index 58d6c77..506d175 100644 --- a/format-schemas/index.js +++ b/format-schemas/index.js @@ -115,6 +115,8 @@ const PROPERTIES = [ "deprecated", "experimental", + + "default", ]; const processJson = processSchema.bind(null, { diff --git a/generate-types/index.js b/generate-types/index.js index 6a639b8..aa4426f 100644 --- a/generate-types/index.js +++ b/generate-types/index.js @@ -629,41 +629,29 @@ const printError = (diagnostic) => { .trim(); let commentText = normalizeText(symbol.getDocumentationComment(checker)); - const deprecatedTags = symbol - .getJsDocTags(checker) - .filter((tag) => tag.name === "deprecated"); - - const experimentalTags = symbol - .getJsDocTags(checker) - .filter((tag) => tag.name === "experimental"); + const jsDocTags = symbol.getJsDocTags(checker); + const forwardedTagNames = ["default", "deprecated", "experimental"]; + const forwardedTags = forwardedTagNames.flatMap((name) => + jsDocTags.filter((tag) => tag.name === name), + ); - if ( - !commentText && - deprecatedTags.length === 0 && - experimentalTags.length === 0 - ) { + if (!commentText && forwardedTags.length === 0) { return ""; } const lines = commentText ? commentText.split("\n") : []; - for (const tag of deprecatedTags) { - const text = normalizeText(tag.text); - if (text && !commentText) { - lines.push(...text.split("\n")); - lines.push("@deprecated"); - } else { - lines.push(text ? `@deprecated ${text}` : "@deprecated"); - } - } - - for (const tag of experimentalTags) { + for (const tag of forwardedTags) { const text = normalizeText(tag.text); - if (text && !commentText) { + if ( + text && + !commentText && + (tag.name === "deprecated" || tag.name === "experimental") + ) { lines.push(...text.split("\n")); - lines.push("@experimental"); + lines.push(`@${tag.name}`); } else { - lines.push(text ? `@experimental ${text}` : "@experimental"); + lines.push(text ? `@${tag.name} ${text}` : `@${tag.name}`); } } diff --git a/precompile-schemas/index.js b/precompile-schemas/index.js index 90b5949..cb8e4e0 100644 --- a/precompile-schemas/index.js +++ b/precompile-schemas/index.js @@ -111,6 +111,7 @@ const EXCLUDED_PROPERTIES = [ "description", "deprecated", "experimental", + "default", "cli", "implements", "tsType", diff --git a/schemas-lint/index.js b/schemas-lint/index.js index a1e7e96..ec25604 100644 --- a/schemas-lint/index.js +++ b/schemas-lint/index.js @@ -52,6 +52,7 @@ for (const filename of schemas) { "link", "deprecated", "experimental", + "default", ]; const isReference = (schema) => {