Skip to content

Commit ee9b725

Browse files
committed
review
Signed-off-by: flakey5 <[email protected]>
1 parent bcde0e4 commit ee9b725

File tree

13 files changed

+87
-26
lines changed

13 files changed

+87
-26
lines changed

src/generators/json-all/__tests__/index.test.mjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { test } from 'node:test';
55
import { Validator } from 'jsonschema';
66
import { SemVer } from 'semver';
77

8+
import { BASE_URL } from '../../../constants.mjs';
89
import createGenerator from '../../../generators.mjs';
910
import createMarkdownLoader from '../../../loaders/markdown.mjs';
1011
import createMarkdownParser from '../../../parsers/markdown.mjs';
12+
import { SCHEMA_FILENAME } from '../constants.mjs';
13+
import jsonAll from '../index.mjs';
1114
import { generateJsonSchema } from '../util/generateJsonSchema.mjs';
1215

1316
const FIXTURES_DIR = join(
@@ -53,3 +56,65 @@ test('generator output complies with json schema', async () => {
5356

5457
assert.ok(validator.validate(result, schema).valid);
5558
});
59+
60+
test('combines json correctly', async () => {
61+
const version = 'v1.2.3';
62+
63+
/**
64+
* @type {Array<import('../../json/generated.d.ts').NodeJsAPIDocumentationSchema>}
65+
*/
66+
const jsonOutput = [
67+
{
68+
$schema: `https://nodejs.org/docs/${version}/api/node-doc-schema.json`,
69+
source: 'doc/api/some-module.md',
70+
type: 'module',
71+
'@name': 'Some Module',
72+
'@module': 'node:module',
73+
classes: [],
74+
},
75+
{
76+
$schema: `https://nodejs.org/docs/${version}/api/node-doc-schema.json`,
77+
source: 'doc/api/some-module.md',
78+
type: 'text',
79+
'@name': 'Some Module',
80+
description: 'asdf',
81+
text: [
82+
{
83+
type: 'text',
84+
'@name': 'asdf',
85+
description: 'bla bla bla',
86+
},
87+
],
88+
},
89+
];
90+
91+
const result = await jsonAll.generate(jsonOutput, {
92+
version: new SemVer(version),
93+
});
94+
95+
assert.deepStrictEqual(result, {
96+
$schema: `${BASE_URL}docs/${version}/api/${SCHEMA_FILENAME}`,
97+
modules: [
98+
{
99+
type: 'module',
100+
'@name': 'Some Module',
101+
'@module': 'node:module',
102+
classes: [],
103+
},
104+
],
105+
text: [
106+
{
107+
type: 'text',
108+
'@name': 'Some Module',
109+
description: 'asdf',
110+
text: [
111+
{
112+
type: 'text',
113+
'@name': 'asdf',
114+
description: 'bla bla bla',
115+
},
116+
],
117+
},
118+
],
119+
});
120+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const SCHEMA_FILENAME = 'node-doc-all-schema.json';

src/generators/json-all/index.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import { writeFile } from 'node:fs/promises';
44
import { join } from 'node:path';
55

6-
import { BASE_URL, DOC_NODE_VERSION } from '../../constants.mjs';
6+
import { SCHEMA_FILENAME } from './constants.mjs';
7+
import { BASE_URL } from '../../constants.mjs';
78
import { generateJsonSchema } from './util/generateJsonSchema.mjs';
89

910
/**
@@ -34,8 +35,10 @@ export default {
3435
* @returns {Promise<object>}
3536
*/
3637
async generate(input, { version, output }) {
38+
const versionString = `v${version.toString()}`;
39+
3740
const generatedValue = {
38-
$schema: `${BASE_URL}/docs/${DOC_NODE_VERSION}/api/node-doc-all-schema.jsonc`,
41+
$schema: `${BASE_URL}docs/${versionString}/api/${SCHEMA_FILENAME}`,
3942
modules: [],
4043
text: [],
4144
};
@@ -64,13 +67,10 @@ export default {
6467
});
6568

6669
if (output) {
67-
const schema = generateJsonSchema(version);
70+
const schema = generateJsonSchema(versionString);
6871

6972
// Write the parsed JSON schema to the output directory
70-
await writeFile(
71-
join(output, 'node-doc-schema.json'),
72-
JSON.stringify(schema)
73-
);
73+
await writeFile(join(output, SCHEMA_FILENAME), JSON.stringify(schema));
7474
}
7575

7676
return generatedValue;

src/generators/json-all/util/generateJsonSchema.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
'use strict';
22

33
import { BASE_URL } from '../../../constants.mjs';
4+
import { SCHEMA_FILENAME } from '../constants.mjs';
45
import jsonAll from '../index.mjs';
56

67
/**
78
* @param {string} version
89
*/
910
export function generateJsonSchema(version) {
10-
const jsonSchemaUrl = `${BASE_URL}/docs/${version}/api/node-doc-schema.json`;
11+
const jsonSchemaUrl = `${BASE_URL}/docs/${version}/api/${SCHEMA_FILENAME}`;
1112

1213
return {
1314
$schema: 'http://json-schema.org/draft-07/schema#',

src/generators/json/constants.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
export const SCHEMA_FILENAME = 'node-doc-schema.json';
4+
35
// Grabs the default value if present
46
export const DEFAULT_EXPRESSION = /^(?:D|d)efault(?:s|):$/;
57

src/generators/json/index.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { writeFile } from 'node:fs/promises';
44
import { join } from 'node:path';
55

6+
import { SCHEMA_FILENAME } from './constants.mjs';
67
import { parseSchema } from './utils/parseSchema.mjs';
78
import { createSection } from './utils/sections/index.mjs';
89
import { groupNodesByModule } from '../../utils/generators.mjs';
@@ -51,7 +52,7 @@ export default {
5152
throw new TypeError(`no grouped nodes found for ${head.api}`);
5253
}
5354

54-
return createSection(head, nodes, version);
55+
return createSection(head, nodes, `v${version.toString()}`);
5556
};
5657

5758
/**
@@ -87,10 +88,7 @@ export default {
8788
const schema = await parseSchema();
8889

8990
// Write the parsed JSON schema to the output directory
90-
await writeFile(
91-
join(output, 'node-doc-schema.json'),
92-
JSON.stringify(schema)
93-
);
91+
await writeFile(join(output, SCHEMA_FILENAME), JSON.stringify(schema));
9492
}
9593

9694
return generatedValues;

src/generators/json/schema.jsonc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@
190190
},
191191
"required": [
192192
"type",
193-
"@constructor",
194-
"methods",
195-
"staticMethods",
196-
"properties",
197193
],
198194
},
199195
],
@@ -231,6 +227,7 @@
231227
"$ref": "#/definitions/MethodReturnType",
232228
},
233229
},
230+
"required": ["parameters", "@returns"]
234231
},
235232

236233
"MethodParameter": {

src/generators/json/utils/__tests__/createParameterGroupings.test.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-check
21
'use strict';
32

43
import assert from 'node:assert';

src/generators/json/utils/createParameterGroupings.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-check
21
'use strict';
32

43
import { ParameterTree } from './parameter-tree.mjs';

src/generators/json/utils/parameter-tree.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-check
21
'use strict';
32

43
/**

0 commit comments

Comments
 (0)