Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions templates/modern/schemas/ApiPage.schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/**
* This file is used to generate the API page JSON schema. To generate the schema:
* 1. run `npx typescript-json-schema ApiPage.schema.d.ts ApiPage --required --strictNullChecks --out ApiPage.schema.json`
* 2. manually mark properties as markdown
*/

/** Define the markdown content type */
type markdown = string;

/** Represents an inline composed of text or links */
type Inline = string | (string | { text: string; url?: string })[];

/** Represents a markdown block */
type Markdown = {
/** Markdown content */
markdown: markdown;
};

/** Represents a heading */
type Heading =
| { /** Heading title */ h1: string; /** URL fragment */ id?: string }
| { /** Heading title */ h2: string; /** URL fragment */ id?: string }
| { /** Heading title */ h3: string; /** URL fragment */ id?: string }
| { /** Heading title */ h4: string; /** URL fragment */ id?: string }
| { /** Heading title */ h5: string; /** URL fragment */ id?: string }
| { /** Heading title */ h6: string; /** URL fragment */ id?: string };
Comment on lines +22 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "URL fragment" mean it is expected to match the fragment definition in https://www.rfc-editor.org/rfc/rfc3986#section-3.5? I.e. does not include #, and can contain pct-encoded.

Copy link
Contributor Author

@yufeih yufeih Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, renderers are not expected to change this id to match rfc3986, renders MAY encode the id to produce valid HTML.


/** Represents an API heading */
type Api = (
| { /** API name */ api1: string }
| { /** API name */ api2: string }
| { /** API name */ api3: string }
| { /** API name */ api4: string }
) & {
/** API URL fragment */
id?: string;

/** Is this API deprecated, or the deprecation reason */
deprecated?: boolean | string;

/** API source URL */
src?: string;

/** Opaque metadata about the API as HTML data-* attributes */
metadata?: { [key: string]: string };
Comment on lines +47 to +48

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear whether the "data-" prefix is part of the key here, or added during the conversion to HTML.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data- is added to key, will adjust the comment to clarify.

};

/** Represents a sheet of facts */
type Facts = {
facts: {
name: string;
value: Inline;
}[];
};

/** Represents a list of content */
type List = {
list: Inline[];
};

/** Represents a single inheritance chain from base type to derived type */
type Inheritance = {
inheritance: Inline[];
};

/** Represents a code block */
type Code = {
/** Code text */
code: string;

/** Code [langauge identifier](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Code [langauge identifier](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) */
/** Code [language identifier](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) */

languageId?: string;
};

/** Represents a set of parameters */
type Params = {
parameters: {
/** Parameter name */
name?: string;

/** Parameter type */
type?: Inline;

/** Parameter default value */
default?: string;

/** Parameter description in markdown format */
description?: markdown;

/** Is this parameter deprecated, or the deprecation reason */
deprecated?: boolean | string;

/** Is this parameter optional? */
optional?: boolean;
}[];
};

/** Represents block level elements */
type Block =
| Heading
| Api
| Markdown
| Facts
| Params
| List
| Inheritance
| Code;

/** Represents a general API page */
type ApiPage = {
/** Page title */
title: string;

/** Opaque metadata about the page as HTML <meta> tags */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Willl this documentation be parsed as Markdown? If so, <meta> should be quoted or escaped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, properties using markdown formats are explicitly typed as markdown, such as parameters.description.

Copy link

@KalleOlaviNiemitalo KalleOlaviNiemitalo Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the documentation of the property, not the value of the property.

 /** Opaque metadata about the page as HTML `<meta>` tags  */

because you used Markdown syntax for hyperlinks in the documentation of other properties.

metadata?: { [key: string]: string | string[] };

/** Default code [language identifier](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) */
languageId?: string;

/** Page body */
body: Block[];
};
Loading