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

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
346 2 344 0
View the top 2 failed test(s) by shortest run time
test::module.md
Stack Traces | 0.0146s run time
[Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:

  assert.ok(validator.validate(result[0], schema).valid)
] {
  code: 'ERR_TEST_FAILURE',
  failureType: 'testCodeFailure',
  cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
  
    assert.ok(validator.validate(result[0], schema).valid)
  
      at TestContext.<anonymous> (file:.../json/__tests__/index.test.mjs:45:14)
      at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
      at async Test.run (node:internal/test_runner/test:1113:7)
      at async Suite.processPendingSubtests (node:internal/test_runner/test:788:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '==',
    diff: 'simple'
  }
}
test::text-doc.md
Stack Traces | 0.0596s run time
Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:

  assert.ok(validator.validate(result[0], schema).valid)

    at async Promise.all (index 0) {
  code: 'ERR_TEST_FAILURE',
  failureType: 'testCodeFailure',
  cause: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
  
    assert.ok(validator.validate(result[0], schema).valid)
  
      at TestContext.<anonymous> (file:.../json/__tests__/index.test.mjs:45:14)
      at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
      at async Test.run (node:internal/test_runner/test:1113:7)
      at async Promise.all (index 0)
      at async Suite.run (node:internal/test_runner/test:1518:7)
      at async startSubtestAfterBootstrap (node:internal/test_runner/harness:358:3) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '==',
    diff: 'simple'
  }
}

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@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 Review Updated (UTC)
api-docs-tooling Ready Ready Preview Jan 8, 2026 5:24am

@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!

@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 55 to 66
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

Copy link
Member Author

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') {
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"?

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.

@avivkeller
Copy link
Member

@flakey5 Is there a reason why many properties start with @? I feel like that makes it harder for consumers, since they now need to <>.["@prop"] instead of just <>.prop

Copy link
Contributor

Copilot AI left a 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 json generator that outputs individual JSON files for each API module with comprehensive type information, method signatures, properties, and events
  • New json-all generator 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"],
Copy link

Copilot AI Dec 3, 2025

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.

Suggested change
"required": ["parameters", "@returns"],
"required": ["@returns"],

Copilot uses AI. Check for mistakes.
@avivkeller avivkeller added this to the Web Generator Migration milestone Dec 3, 2025
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.

More comments :-)


// Not code, let's stringify it and add it to the description.
section.description ??= '';
section.description += `${transformNodeToString(node)}${node.type === 'paragraph' ? '\n' : ' '}`;
Copy link
Member

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?

Copy link
Member Author

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;
}

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
const examples = [...enforceArray(section['@example']), node.value];
section['@example'] = examples.length === 1 ? examples[0] : examples;

Comment on lines 102 to 108
if (section.type !== 'module' && section.type !== 'text') {
throw new GeneratorError(
`expected root section to be a module or text, got ${section.type}`,
{ entry: head }
);
}

Copy link
Member

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)

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

return {
$schema: `${BASE_URL}docs/${version}/api/${SCHEMA_FILENAME}`,
source: head.api_doc_source,
Copy link
Member Author

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