-
Notifications
You must be signed in to change notification settings - Fork 209
feat: Add --raw-jsdoc option to include full JSDoc in schema #2224
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
Open
alexchexes
wants to merge
3
commits into
vega:next
Choose a base branch
from
alexchexes:feature/jsdoc-raw
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ts from "typescript"; | ||
|
||
export function getRawJsDoc(node: ts.Node): string | undefined { | ||
const sourceFile = node.getSourceFile(); | ||
const jsDocNodes = ts.getJSDocCommentsAndTags(node); | ||
|
||
if (!jsDocNodes || jsDocNodes.length === 0) { | ||
return undefined; | ||
} | ||
|
||
let rawText = ""; | ||
|
||
for (const jsDoc of jsDocNodes) { | ||
rawText += jsDoc.getFullText(sourceFile) + "\n"; | ||
} | ||
|
||
rawText = rawText.trim(); | ||
|
||
return getTextWithoutStars(rawText).trim(); | ||
} | ||
|
||
function getTextWithoutStars(inputText: string) { | ||
const innerTextWithStars = inputText.replace(/^\/\*\*[^\S\n]*\n?/, "").replace(/(\r?\n)?[^\S\n]*\*\/$/, ""); | ||
arthurfiorette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return innerTextWithStars | ||
.split(/\n/) | ||
.map((line) => { | ||
const trimmedLine = line.trimStart(); | ||
|
||
if (trimmedLine[0] !== "*") { | ||
return line; | ||
} | ||
|
||
const textStartPos = trimmedLine[1] === " " ? 2 : 1; | ||
|
||
return trimmedLine.substring(textStartPos); | ||
}) | ||
.join("\n"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/** | ||
* @title Raw Test Schema Interface | ||
* @description Top-level interface: This interface is used to test the rawJsDoc output. | ||
* It includes various formatting quirks, inline tags such as {@link SomeReference}, and multiple JSDoc sections. | ||
* | ||
* @markdownDescription **Markdown version:** Markdown description which should be <b>preserved</b> | ||
* | ||
* Additional info: Top-level details should be completely preserved in raw form. | ||
*/ | ||
export interface MyObject { | ||
/** | ||
* @title Single-line Title and Description | ||
* @description Single-line comment for raw extraction. | ||
*/ | ||
singleLine: string; | ||
|
||
/** | ||
* @title Multiline Field Title | ||
* @description This is a multiline description. | ||
* It spans multiple lines to test the preservation of newlines. | ||
* | ||
* @note 123 | ||
* @format date-time | ||
*/ | ||
multilineField: number; | ||
|
||
/** | ||
* This field has a comment without explicit tags. | ||
* It includes an inline reference: {@link ExampleReference} and extra text on several lines. | ||
* | ||
* The raw output should preserve this whole block as is. | ||
*/ | ||
noTagField: boolean; | ||
|
||
/** | ||
* @title Field with Special Formatting | ||
* @description Extra spaces and indentation should be preserved. | ||
* | ||
* @pattern /^\w+$/ | ||
*/ | ||
specialFormat: string; | ||
|
||
/** | ||
* Some initial descriptive text that is not tagged. | ||
* | ||
* @description Field with initial untagged text followed by a tag. | ||
* @default 42 | ||
* | ||
* Further comments in the same block should be preserved entirely. | ||
*/ | ||
initialText: number; | ||
|
||
/** | ||
* Some *code block*: | ||
* ```yaml | ||
* name: description | ||
* length: 42 | ||
* ``` | ||
* | ||
* Some list: | ||
* - one | ||
* - two | ||
* - and three... | ||
* | ||
* @description This field tests `inline code` and <b>bold text</b>. | ||
* | ||
* Also includes an inline link: {@link https://example.com} and additional commentary. | ||
*/ | ||
markdownField: string; | ||
|
||
/** | ||
* @title Tag Only Field | ||
* @note Only raw content should be available. | ||
* @customTag Tag only content! | ||
*/ | ||
tagOnlyField: string; | ||
|
||
/** | ||
* @title Tag Only Field | ||
* @description | ||
* @note Only raw content should be available. | ||
* @customTag Tag only content! | ||
*/ | ||
tagOnlyFieldWithDescription: string; | ||
|
||
/** Some text */ | ||
oneLineJsDoc: string; | ||
|
||
/** Some *text* - {@link https://example.com} - @see the `link` */ | ||
oneLineJsDocComplex: string; | ||
|
||
/** */ | ||
emptyJsDoc1?: null; | ||
|
||
/** | ||
* | ||
*/ | ||
emptyJsDoc2?: null; | ||
|
||
noJsDoc?: null; | ||
|
||
/** | ||
* Some ignored comment description | ||
* | ||
* @description Export field description | ||
* @default {"length": 10} | ||
* @nullable | ||
*/ | ||
exportString: MyExportString; | ||
/** | ||
* @description Export field description | ||
* @default "private" | ||
*/ | ||
privateString: MyPrivateString; | ||
|
||
/** | ||
* @title Non empty array | ||
*/ | ||
numberArray: MyNonEmptyArray<number>; | ||
|
||
/** | ||
* @nullable | ||
*/ | ||
number: number; | ||
|
||
/** | ||
* Some more examples: | ||
* ```yaml | ||
* name: description | ||
* length: 42 | ||
* ``` | ||
*/ | ||
description: InheritedExample["description"]; | ||
|
||
/** | ||
* @default "" | ||
*/ | ||
inheritedDescription: InheritedExample["description"]; | ||
} | ||
|
||
/** | ||
* @title My export string | ||
*/ | ||
export type MyExportString = string; | ||
/** | ||
* @title My private string | ||
*/ | ||
type MyPrivateString = string; | ||
/** | ||
* @minItems 1 | ||
*/ | ||
export type MyNonEmptyArray<T> = T[]; | ||
|
||
/** | ||
* @title Inherited Example Interface | ||
* @description This interface is used to test inherited descriptions. | ||
*/ | ||
export interface InheritedExample { | ||
/** | ||
* This is an inherited description. | ||
* | ||
* It may include multiple at-tags: | ||
* @title Inherited Title | ||
* @description Inherited description text. | ||
* | ||
* It contains an inline link: {@link https://example.com} and additional commentary. | ||
*/ | ||
description: string; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
--raw-jsDoc
since we have--jsDoc
already?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I would replace
--jsDoc
with--jsdoc
or--js-doc
, but that's up to you guysThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd too if we started over but let's not break it now.