-
Notifications
You must be signed in to change notification settings - Fork 24
feat: json, json-all generators #287
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
base: main
Are you sure you want to change the base?
Conversation
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
|
@flakey5 is this still in progress? Need any help? |
|
Still in progress just haven't been committing, I do wanna get this ready for review within the next coming weeks though |
a4cd425 to
d711fee
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
2d10df1 to
e4dbbe4
Compare
6bfc555 to
1bcf93d
Compare
|
Bulk of this is done, with only two main things left:
I'm leaving this as a draft until those are done, but the rest is ready for review |
avivkeller
left a comment
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.
the rest is ready for review
I've left a first round of reviews. Thank you so much for this effort!
ee1684d to
b37daee
Compare
b37daee to
8ebb3d6
Compare
|
Marking ready for review, should be all there minus #287 (comment) |
| switch (section.type) { | ||
| case 'module': | ||
| generatedValue.modules.push(copiedSection); | ||
| break; | ||
| case 'text': | ||
| generatedValue.text.push(copiedSection); | ||
| break; | ||
| default: | ||
| throw new TypeError(`unsupported root section type ${section.type}`); | ||
| } |
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.
| switch (section.type) { | |
| case 'module': | |
| generatedValue.modules.push(copiedSection); | |
| break; | |
| case 'text': | |
| generatedValue.text.push(copiedSection); | |
| break; | |
| default: | |
| throw new TypeError(`unsupported root section type ${section.type}`); | |
| } | |
| generatedValue[type === 'module' ? 'modules' : type].push(copiedSection) |
nit
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.
-1 imo, even though the error shouldn't ever be thrown I don't think we should assume it won't be. Otherwise if we do get a section that's not a module or text in the input, we run the risk of violating the json schema and not knowing about it
| ); | ||
| } | ||
|
|
||
| if (rest[0]?.type === 'link') { |
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.
Can we have these specific extractors on dedicated function for ... extracting these? Also are the types here only link and "else"?
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.
Shouldn't this be automatically generated?
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.
The schema should be maintained by hand. It doesn't need to be in a standalone json file though, we could have it be a function like with the json-all's schema. Only reason it is standalone currently is to make it so we can have better intellisense/autocomplete in editors when modifying the schema
ovflowd
left a comment
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.
Mostly LGTM, I think that we can dedup lots of the code, extract many of the utility functions within parsing things (such as event, property) into dedicated tiny functions that do one thing and then unit test them.
Makes the parent functions simpler, easier to read the code and understand what pieces does what, reusability and unit testing.
|
@flakey5 Is there a reason why many properties start with |
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.
Pull request overview
This PR introduces new JSON generators (json and json-all) for the Node.js documentation toolkit, providing machine-readable JSON representations of API documentation.
Key Changes:
- New
jsongenerator that outputs individual JSON files for each API module with comprehensive type information, method signatures, properties, and events - New
json-allgenerator that combines all JSON outputs into a single file - Comprehensive JSON schema definition with TypeScript type generation support
Reviewed changes
Copilot reviewed 39 out of 44 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
src/generators/json/index.mjs |
Main JSON generator implementation |
src/generators/json-all/index.mjs |
Aggregator generator for combined JSON output |
src/generators/json/schema.jsonc |
JSON schema definition for documentation structure |
src/generators/json/utils/sections/*.mjs |
Section parsers for modules, classes, methods, properties, and events |
src/generators/json/utils/parseTypeList.mjs |
Type list parsing utility |
src/generators/json/utils/createParameterGroupings.mjs |
Method signature parameter grouping logic |
src/utils/buildHierarchy.mjs |
Shared utility for building hierarchical entry structures |
src/utils/assertAstType.mjs |
AST node type assertion utilities |
src/utils/generator-error.mjs |
Custom error class for generator errors |
src/utils/unist.mjs |
Enhanced node transformation with support for break, delete, and link nodes |
scripts/generate-json-types.mjs |
Script to generate TypeScript definitions from JSON schema |
package.json |
New dependencies for JSON parsing and schema validation |
.github/workflows/generate.yml |
CI workflow integration for JSON generator |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "$ref": "#/definitions/MethodReturnType", | ||
| }, | ||
| }, | ||
| "required": ["parameters", "@returns"], |
Copilot
AI
Dec 3, 2025
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.
[nitpick] The MethodSignature.parameters property is defined as required (line 233), but in several places in the code, signatures are created with an empty parameters array instead of omitting it when there are no parameters. Consider making this property optional or consistently handling empty arrays.
| "required": ["parameters", "@returns"], | |
| "required": ["@returns"], |
avivkeller
left a comment
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.
More comments :-)
|
|
||
| // Not code, let's stringify it and add it to the description. | ||
| section.description ??= ''; | ||
| section.description += `${transformNodeToString(node)}${node.type === 'paragraph' ? '\n' : ' '}`; |
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.
Is this added newline needed?
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.
Yes
| } else { | ||
| section['@example'] = node.value; | ||
| } | ||
|
|
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.
| const examples = [...enforceArray(section['@example']), node.value]; | |
| section['@example'] = examples.length === 1 ? examples[0] : examples; |
| if (section.type !== 'module' && section.type !== 'text') { | ||
| throw new GeneratorError( | ||
| `expected root section to be a module or text, got ${section.type}`, | ||
| { entry: head } | ||
| ); | ||
| } | ||
|
|
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.
I think these if checks are too strict, IMO. I feel like there's nothing wrong with it having the wrong type (like, the generator should still work)
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.
The generator would work, but it would be violating the json schema which consumers would expect to be the source of truth
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
1cf5261 to
0ec318d
Compare
|
|
||
| return { | ||
| $schema: `${BASE_URL}docs/${version}/api/${SCHEMA_FILENAME}`, | ||
| source: head.api_doc_source, |
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.
Currently this is something like doc/api/buffer.md, I wonder if it'd be more useful to give an actual link to the source file like https://nodejs.org/docs/v25.0.0/api/buffer.md
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Co-authored-by: Aviv Keller <me@aviv.sh>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Closes #214
TODO: