Skip to content

Conversation

@flakey5
Copy link
Member

@flakey5 flakey5 commented May 31, 2025

Closes #214

TODO:

@codecov-commenter
Copy link

codecov-commenter commented May 31, 2025

Codecov Report

❌ Patch coverage is 93.86531% with 266 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.42%. Comparing base (9285e74) to head (1cf5261).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/generators/json/utils/sections/method.mjs 80.96% 67 Missing ⚠️
src/generators/json/utils/sections/event.mjs 76.11% 42 Missing and 1 partial ⚠️
src/utils/generator-error.mjs 21.05% 30 Missing ⚠️
src/generators/json/utils/sections/property.mjs 81.16% 29 Missing ⚠️
src/generators/json/utils/sections/index.mjs 78.94% 23 Missing and 1 partial ⚠️
src/generators/json/index.mjs 80.20% 19 Missing ⚠️
src/utils/assertAstType.mjs 80.00% 11 Missing ⚠️
...generators/json/utils/createParameterGroupings.mjs 91.17% 9 Missing ⚠️
src/generators/json-all/index.mjs 89.74% 8 Missing ⚠️
src/generators/json/utils/sections/base.mjs 95.07% 7 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #287      +/-   ##
==========================================
+ Coverage   74.60%   82.42%   +7.81%     
==========================================
  Files         112      140      +28     
  Lines       10700    15034    +4334     
  Branches      722     1027     +305     
==========================================
+ Hits         7983    12392    +4409     
+ Misses       2714     2637      -77     
- Partials        3        5       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avivkeller avivkeller mentioned this pull request Jun 24, 2025
6 tasks
@avivkeller
Copy link
Member

@flakey5 is this still in progress? Need any help?

@flakey5
Copy link
Member Author

flakey5 commented Sep 30, 2025

Still in progress just haven't been committing, I do wanna get this ready for review within the next coming weeks though

@flakey5 flakey5 force-pushed the flakey5/20240909/new-json-gen branch from a4cd425 to d711fee Compare October 6, 2025 20:16
@vercel
Copy link

vercel bot commented Oct 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
api-docs-tooling Ready Ready Preview Dec 1, 2025 1:38am

@flakey5
Copy link
Member Author

flakey5 commented Nov 10, 2025

Bulk of this is done, with only two main things left:

  • Couple of failing tests for createParameterGroupings
  • Adding the @constructor property to class sections

I'm leaving this as a draft until those are done, but the rest is ready for review

Copy link
Member

@avivkeller avivkeller left a 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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a seperate generator error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exists just to give the general spot in the ast that an error happens to assist with debugging, can definitely be removed if unwanted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nodejs/web-infra im +1 on removing, WDYT?

'use strict';

// Grabs the default value if present
export const DEFAULT_EXPRESSION = /^(D|d)efault(s|):$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's re-use the DEFAULT_EXPRESSION constant from the legacy generator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't since this is used for matching against the text in the ast which doesn't have the asterisks, while the one in the legacy generator is going off of the stringified version in textRaw which does

@flakey5
Copy link
Member Author

flakey5 commented Nov 29, 2025

Marking ready for review, should be all there minus #287 (comment)

@flakey5 flakey5 marked this pull request as ready for review November 29, 2025 02:49
@flakey5 flakey5 requested a review from a team as a code owner November 29, 2025 02:49
Comment on lines +46 to +53
input.forEach(section => {
const copiedSection = {};

Object.keys(section).forEach(key => {
if (!propertiesToIgnore.includes(key)) {
copiedSection[key] = section[key];
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
input.forEach(section => {
const copiedSection = {};
Object.keys(section).forEach(key => {
if (!propertiesToIgnore.includes(key)) {
copiedSection[key] = section[key];
}
});
input.forEach({ ignoreThisKey, ...section } => {

WDYT?

Comment on lines +55 to +64
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}`);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

*/
async generate(input, { version, output }) {
const generatedValue = {
$schema: `${BASE_URL}/docs/${DOC_NODE_VERSION}/api/node-doc-all-schema.jsonc`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make a SCHEMA_URL constant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really since it intakes the version given by the generator options, same for the rest of the schema url instances

* @param {string} version
*/
export function generateJsonSchema(version) {
const jsonSchemaUrl = `${BASE_URL}/docs/${version}/api/node-doc-schema.json`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on the constant

// Returns: {string}
// Returns {string}
// Returns: {string} bla bla bla
export const METHOD_RETURN_TYPE_EXTRACTOR = /^(?:R|r)eturns(:?) {(.*)}( .*)?$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather do a case insensitive search

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't just checking if it starts with Returns: though, it's extracting the type information and possible description from it as well

}

return {
$schema: `${BASE_URL}docs/${version}/api/node-doc-schema.json`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on the constant

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nodejs/web-infra im +1 on removing, WDYT?

Signed-off-by: flakey5 <[email protected]>
Signed-off-by: flakey5 <[email protected]>
);
}

if (rest[0]?.type === 'link') {
Copy link
Member

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"?


parameter['@name'] = 'value';

const { types, endingIndex } = parseTypeList(parameterAst.children);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we could dedup this


break;
}
case 'text': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like more duped code

// it
const { types, endingIndex } = parseTypeList(paragraph.children, 2);

if (types.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like more duped code

}
case 'link': {
const { types, endingIndex } = parseTypeList(paragraph.children, 1);
if (types.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like more duped code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we mhave this file output be in a different folder? Like a generated folder?

Copy link
Member

@ovflowd ovflowd Nov 30, 2025

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?

Copy link
Member Author

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

Copy link
Member

@ovflowd ovflowd left a 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.

Signed-off-by: flakey5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New JSON generator schema

5 participants