Skip to content

Commit 2d10df1

Browse files
committed
tmp
1 parent d711fee commit 2d10df1

17 files changed

+253
-610
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
import test from 'node:test';
4+
import assert from 'node:assert';
5+
import jsonAll from '../../json-all/index.mjs';
6+
import json from '../index.mjs';
7+
import { generateJsonSchema } from '../util/generateJsonSchema.mjs';
8+
9+
test('json-all generator matches json generator version match', () => {
10+
assert.strictEqual(jsonAll.version, json.version);
11+
});
12+
13+
test('schema version matches generator version', () => {
14+
const schema = generateJsonSchema();
15+
16+
assert.strictEqual(schema.$id, `nodejs-api-doc-all@v${jsonAll.version}`);
17+
});

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
// @ts-check
21
'use strict';
32

43
import { DOC_NODE_VERSION } from '../../../constants.mjs';
4+
import jsonAll from '../index.mjs';
55

66
const JSON_SCHEMA_URL = `https://nodejs.org/docs/${DOC_NODE_VERSION}/api/node-doc-schema.json`;
77

88
export const generateJsonSchema = () => ({
99
$schema: 'http://json-schema.org/draft-07/schema#',
10-
// This should be kept in sync with the generator version for this generator
11-
// AND the `json` generator and schema
12-
$id: '[email protected]', // This should be kept in sync with the generator version.
10+
$id: `nodejs-api-doc-all@${jsonAll.version}`,
1311
title: 'Node.js API Documentation Schema (All)',
1412
readOnly: true,
1513

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
import test from 'node:test';
4+
import assert from 'node:assert';
5+
import { readFile } from 'node:fs/promises';
6+
import { join } from 'node:path';
7+
import { parse as jsoncParse } from 'jsonc-parser';
8+
import json from '../index.mjs';
9+
10+
test('schema version matches generator version ', async () => {
11+
const schemaString = await readFile(
12+
join(import.meta.dirname, '..', 'schema.jsonc'),
13+
'utf8'
14+
);
15+
const schema = await jsoncParse(schemaString);
16+
17+
assert.strictEqual(schema.$id, `nodejs-api-doc@v${json.version}`);
18+
});

src/generators/json/constants.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ export const DEFAULT_EXPRESSION = /^(D|d)efault(s|):$/;
55

66
// Grabs the type and description of one of the formats for event types
77
export const EVENT_TYPE_DESCRIPTION_EXTRACTOR = /{(.*)}(.*)/;
8+
9+
// Grabs return type and optional description for a method signature
10+
// Accepts the following:
11+
// Returns: {string}
12+
// Returns {string}
13+
// Returns: {string} bla bla bla
14+
export const METHOD_RETURN_TYPE_EXTRACTOR = /^Returns(:?) {(.*)}( .*)?$/;

src/generators/json/generated.d.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ export interface Change {
163163
}
164164
export interface MethodSignature {
165165
parameters?: MethodParameter[];
166-
/**
167-
* The method signature's return type.
168-
*/
169-
'@returns'?: string | [string, ...string[]];
166+
'@returns'?: MethodReturnType;
170167
[k: string]: unknown;
171168
}
172169
export interface MethodParameter {
@@ -185,3 +182,14 @@ export interface MethodParameter {
185182
'@default'?: string;
186183
[k: string]: unknown;
187184
}
185+
/**
186+
* A method signature's return type.
187+
*/
188+
export interface MethodReturnType {
189+
description?: string;
190+
/**
191+
* The method signature's return type.
192+
*/
193+
'@type': string | [string, ...string[]];
194+
[k: string]: unknown;
195+
}

src/generators/json/schema.jsonc

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,9 @@
232232
// "$ref": "https://json-schema.org/draft-07/schema#",
233233
// },
234234
"@returns": {
235-
"description": "The method signature's return type.",
236-
"oneOf": [
237-
{
238-
"type": "string",
239-
"examples": ["string"],
240-
},
241-
{
242-
"type": "array",
243-
"items": { "type": "string" },
244-
"examples": [["string", "Promise<string>"]],
245-
"minItems": 1,
246-
},
247-
],
235+
"$ref": "#/definitions/MethodReturnType",
248236
},
249237
},
250-
"required": [],
251238
},
252239

253240
"MethodParameter": {
@@ -285,6 +272,32 @@
285272
"required": ["@name", "@type"],
286273
},
287274

275+
"MethodReturnType": {
276+
"type": "object",
277+
"description": "A method signature's return type.",
278+
"properties": {
279+
"description": {
280+
"type": "string",
281+
},
282+
"@type": {
283+
"description": "The method signature's return type.",
284+
"oneOf": [
285+
{
286+
"type": "string",
287+
"examples": ["string"],
288+
},
289+
{
290+
"type": "array",
291+
"items": { "type": "string" },
292+
"examples": [["string", "Promise<string>"]],
293+
"minItems": 1,
294+
},
295+
],
296+
},
297+
},
298+
"required": ["@type"],
299+
},
300+
288301
"Global": {
289302
"type": "object",
290303
"properties": {},

src/generators/json/tmp/addons.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/generators/json/tmp/buffer.json

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)