Skip to content

Commit f2b3f10

Browse files
yufeihp-kostov
authored andcommitted
feat: Generic API page schema (dotnet#9267)
1 parent 2d243e8 commit f2b3f10

File tree

2 files changed

+621
-0
lines changed

2 files changed

+621
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
/**
5+
* This file is used to generate the API page JSON schema. To generate the schema:
6+
* 1. run `npx typescript-json-schema ApiPage.schema.d.ts ApiPage --required --strictNullChecks --out ApiPage.schema.json`
7+
* 2. manually mark properties as markdown
8+
*/
9+
10+
/** Define the markdown content type */
11+
type markdown = string;
12+
13+
/** Represents an inline composed of text or links */
14+
type Inline = string | (string | { text: string; url?: string })[];
15+
16+
/** Represents a markdown block */
17+
type Markdown = {
18+
/** Markdown content */
19+
markdown: markdown;
20+
};
21+
22+
/** Represents a heading */
23+
type Heading =
24+
| { /** Heading title */ h1: string; /** URL fragment */ id?: string }
25+
| { /** Heading title */ h2: string; /** URL fragment */ id?: string }
26+
| { /** Heading title */ h3: string; /** URL fragment */ id?: string }
27+
| { /** Heading title */ h4: string; /** URL fragment */ id?: string }
28+
| { /** Heading title */ h5: string; /** URL fragment */ id?: string }
29+
| { /** Heading title */ h6: string; /** URL fragment */ id?: string };
30+
31+
/** Represents an API heading */
32+
type Api = (
33+
| { /** API name */ api1: string }
34+
| { /** API name */ api2: string }
35+
| { /** API name */ api3: string }
36+
| { /** API name */ api4: string }
37+
) & {
38+
/** API URL fragment */
39+
id?: string;
40+
41+
/** Is this API deprecated, or the deprecation reason */
42+
deprecated?: boolean | string;
43+
44+
/** API source URL */
45+
src?: string;
46+
47+
/** Opaque metadata about the API as HTML data-* attributes */
48+
metadata?: { [key: string]: string };
49+
};
50+
51+
/** Represents a sheet of facts */
52+
type Facts = {
53+
facts: {
54+
name: string;
55+
value: Inline;
56+
}[];
57+
};
58+
59+
/** Represents a list of content */
60+
type List = {
61+
list: Inline[];
62+
};
63+
64+
/** Represents a single inheritance chain from base type to derived type */
65+
type Inheritance = {
66+
inheritance: Inline[];
67+
};
68+
69+
/** Represents a code block */
70+
type Code = {
71+
/** Code text */
72+
code: string;
73+
74+
/** Code [langauge identifier](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) */
75+
languageId?: string;
76+
};
77+
78+
/** Represents a set of parameters */
79+
type Params = {
80+
parameters: {
81+
/** Parameter name */
82+
name?: string;
83+
84+
/** Parameter type */
85+
type?: Inline;
86+
87+
/** Parameter default value */
88+
default?: string;
89+
90+
/** Parameter description in markdown format */
91+
description?: markdown;
92+
93+
/** Is this parameter deprecated, or the deprecation reason */
94+
deprecated?: boolean | string;
95+
96+
/** Is this parameter optional? */
97+
optional?: boolean;
98+
}[];
99+
};
100+
101+
/** Represents block level elements */
102+
type Block =
103+
| Heading
104+
| Api
105+
| Markdown
106+
| Facts
107+
| Params
108+
| List
109+
| Inheritance
110+
| Code;
111+
112+
/** Represents a general API page */
113+
type ApiPage = {
114+
/** Page title */
115+
title: string;
116+
117+
/** Opaque metadata about the page as HTML <meta> tags */
118+
metadata?: { [key: string]: string | string[] };
119+
120+
/** Default code [language identifier](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) */
121+
languageId?: string;
122+
123+
/** Page body */
124+
body: Block[];
125+
};

0 commit comments

Comments
 (0)