Skip to content

Commit 2b40637

Browse files
Fix redocument for other schemas
1 parent fbdfba5 commit 2b40637

7 files changed

Lines changed: 29 additions & 24 deletions

File tree

docs-site/eleventy.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
21
import { RenderPlugin } from '@11ty/eleventy';
2+
import syntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight';
33
import documentation from '../dist/documentation.json' with { type: 'json' };
44

55
export default function (eleventyConfig) {
66
eleventyConfig.addPlugin(syntaxHighlight);
77
eleventyConfig.addPlugin(RenderPlugin);
8-
eleventyConfig.addGlobalData('docs', Object.values(documentation["type.Configuration"]));
8+
eleventyConfig.addGlobalData('docs', Object.values(documentation['type.Configuration']));
99

1010
eleventyConfig.addFilter('json', (json) => {
1111
if (typeof json === 'object') {

docs/index.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ function flattenNestedAnyOf(doc: JsonSchema, schema: JsonSchema): void {
7878
}
7979
}
8080

81-
function getDocumentationEntry(
82-
gid: string,
83-
ctx: ProcessContext
84-
): DocumentationEntry | undefined {
81+
function getDocumentationEntry(gid: string, ctx: ProcessContext): DocumentationEntry | undefined {
8582
ctx.attemptedGids.add(gid);
8683
return ctx.documentationEntries[gid];
8784
}
@@ -117,9 +114,9 @@ function docToPage(
117114
if (isRootType) {
118115
thisPath = [];
119116
gid = config.rootTypeId;
120-
} else if (isTypeRef) {
121-
thisPath = [doc.id!];
122-
gid = doc.id!;
117+
} else if (isTypeRef && doc.id) {
118+
thisPath = [doc.id];
119+
gid = doc.id;
123120
} else if (key) {
124121
thisPath = [...docPath, key];
125122
gid = thisPath.join('.');
@@ -157,10 +154,10 @@ function docToPage(
157154
if (!thisPath.length) {
158155
url = config.urlPrefix;
159156
} else {
160-
url = `${config.urlPrefix}${thisPath.join('/').replace(/^type\./, 'types/').replaceAll('.', '/')}/`.replace(
161-
/\/+/g,
162-
'/'
163-
);
157+
url = `${config.urlPrefix}${thisPath
158+
.join('/')
159+
.replace(/^type\./, 'types/')
160+
.replaceAll('.', '/')}/`.replace(/\/+/g, '/');
164161
}
165162

166163
const page: Page = {

generate-schemas.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ const schemas = [
196196
convertSchemaAnys: true,
197197
addMarkdownDescription: true,
198198
stripId: true,
199+
redocument: true,
200+
docsFolder: 'docs/routing',
199201
},
200202
{
201203
schema: InitialSiteSettingsSchema.meta({
@@ -213,6 +215,8 @@ const schemas = [
213215
convertSchemaAnys: true,
214216
addMarkdownDescription: true,
215217
stripId: true,
218+
redocument: true,
219+
docsFolder: 'docs/initial-site-settings',
216220
},
217221
];
218222

@@ -258,7 +262,9 @@ for (const schemaConfig of schemas) {
258262
await fs.writeFile(fullSchemaPath, JSON.stringify(jsonSchema, null, ' '));
259263

260264
if (schemaConfig.redocument) {
261-
await redocumentSchema(fullSchemaPath, {
265+
const docsFolder =
266+
'docsFolder' in schemaConfig ? schemaConfig.docsFolder : 'docs/documentation';
267+
await redocumentSchema(fullSchemaPath, docsFolder, {
262268
stripId: schemaConfig.stripId,
263269
addMarkdownDescription: schemaConfig.addMarkdownDescription,
264270
});

redocument-schemas.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import fs from 'node:fs/promises';
22
import { readDocs } from './docs/docs.js';
33
import { type DocumentationEntry, type JsonSchema, slugify } from './docs/util.js';
44

5-
const documentationEntries: Record<string, DocumentationEntry> = await readDocs(
6-
'docs/documentation'
7-
);
8-
95
export async function redocumentSchema(
106
fullSchemaPath: string,
7+
folder: string,
118
options?: { stripId?: boolean; addMarkdownDescription?: boolean }
129
): Promise<void> {
10+
const documentationEntries: Record<string, DocumentationEntry> = await readDocs(folder);
11+
1312
const schemaRaw: string = await fs.readFile(fullSchemaPath, { encoding: 'utf8' });
1413
const schema: JsonSchema = JSON.parse(schemaRaw);
1514

src/routing.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ const RouteStatusCodes = {
1212
Gone: 410,
1313
} as const;
1414

15-
export const RouteStatusSchema = z.enum(RouteStatusCodes).default(RouteStatusCodes.MovedPermanently).meta({
16-
description:
17-
'The HTTP status code for this redirect rule. When using 200, 404, and 410 status codes, `to` must refer to a path on the same Site.',
18-
});
15+
export const RouteStatusSchema = z
16+
.enum(RouteStatusCodes)
17+
.default(RouteStatusCodes.MovedPermanently)
18+
.meta({
19+
description:
20+
'The HTTP status code for this redirect rule. When using 200, 404, and 410 status codes, `to` must refer to a path on the same Site.',
21+
});
1922

2023
export const RouteSchema = z
2124
.object({

tests/initial-site-settings.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import assert from 'node:assert';
22
import { test } from 'node:test';
33
import {
4-
InitialSiteSettingsSchema,
54
BuildConfigSchema,
5+
InitialSiteSettingsSchema,
66
SiteModeSchema,
77
} from '../src/initial-site-settings.ts';
88

tests/routing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'node:assert';
22
import { test } from 'node:test';
3-
import { RoutingSchema, RouteSchema, HeaderRuleSchema } from '../src/routing.ts';
3+
import { HeaderRuleSchema, RouteSchema, RoutingSchema } from '../src/routing.ts';
44

55
test('should accept an empty routing configuration', () => {
66
const routing = {};

0 commit comments

Comments
 (0)