asyncapi-viewer 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/dist/asyncapi-viewer.iife.js +22 -22
- package/dist/asyncapi-viewer.iife.js.map +1 -1
- package/dist/asyncapi-viewer.js +179 -132
- package/dist/asyncapi-viewer.js.map +1 -1
- package/dist/types/element.d.ts +33 -0
- package/dist/types/events.d.ts +99 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/load/loader.d.ts +46 -0
- package/dist/types/load/refs.d.ts +62 -0
- package/dist/types/model/avro.d.ts +14 -0
- package/dist/types/model/context.d.ts +75 -0
- package/dist/types/model/invariants.d.ts +7 -0
- package/dist/types/model/normalize.d.ts +16 -0
- package/dist/types/model/schema.d.ts +16 -0
- package/dist/types/model/types.d.ts +324 -0
- package/dist/types/model/v2.d.ts +8 -0
- package/dist/types/model/v3.d.ts +8 -0
- package/dist/types/options.d.ts +56 -0
- package/dist/types/render/details.d.ts +23 -0
- package/dist/types/render/example.d.ts +36 -0
- package/dist/types/render/format.d.ts +2 -0
- package/dist/types/render/header.d.ts +19 -0
- package/dist/types/render/info.d.ts +4 -0
- package/dist/types/render/markdown.d.ts +4 -0
- package/dist/types/render/nav.d.ts +69 -0
- package/dist/types/render/operation.d.ts +18 -0
- package/dist/types/render/sections.d.ts +17 -0
- package/dist/types/render/sidebar.d.ts +30 -0
- package/dist/types/render/tag.d.ts +7 -0
- package/dist/types/render/tree.d.ts +36 -0
- package/dist/types/styles/base.d.ts +2 -0
- package/dist/types/styles/tokens.d.ts +7 -0
- package/dist/types/theme/theme.d.ts +26 -0
- package/dist/types/util/color.d.ts +22 -0
- package/dist/types/util/example.d.ts +8 -0
- package/package.json +12 -3
- package/types/react.d.ts +28 -0
- package/types/react.js +2 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { type LoadResult } from './load/loader.js';
|
|
3
|
+
import type { Document, Problem } from './model/types.js';
|
|
4
|
+
import { type Options } from './options.js';
|
|
5
|
+
/**
|
|
6
|
+
* <asyncapi-viewer src="..."> renders an AsyncAPI document.
|
|
7
|
+
*
|
|
8
|
+
* Options are read from the element's attributes (see options.schema.json) and watched with a
|
|
9
|
+
* MutationObserver, because each option has several accepted spellings and hand-written HTML
|
|
10
|
+
* lowercases camelCase names. The theme controller reflects the resolved mode as
|
|
11
|
+
* `resolved-theme` on the host. Derived colours (badge text, text-safe accents) are computed
|
|
12
|
+
* from the resolved accent at runtime and set as private custom properties on the root.
|
|
13
|
+
* Each finished load dispatches `asyncapi-load` or `asyncapi-error` (events.ts).
|
|
14
|
+
*/
|
|
15
|
+
export declare class AsyncAPIViewerElement extends LitElement {
|
|
16
|
+
#private;
|
|
17
|
+
static styles: import("lit").CSSResult[];
|
|
18
|
+
/** The validated options, re-read whenever an attribute changes. */
|
|
19
|
+
get options(): Options;
|
|
20
|
+
/** The outcome of the last load, for tests and tooling. */
|
|
21
|
+
get loadResult(): LoadResult | undefined;
|
|
22
|
+
/** Problems collected so far (reference loading and normalisation). */
|
|
23
|
+
get problems(): readonly Problem[];
|
|
24
|
+
/** The normalised model, once loaded. */
|
|
25
|
+
get model(): Document | undefined;
|
|
26
|
+
/** The element id used as the anchor prefix; generated when the tag has none. */
|
|
27
|
+
get anchorPrefix(): string;
|
|
28
|
+
connectedCallback(): void;
|
|
29
|
+
disconnectedCallback(): void;
|
|
30
|
+
protected firstUpdated(): void;
|
|
31
|
+
protected updated(): void;
|
|
32
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the element: the events it dispatches and the attributes it accepts.
|
|
3
|
+
*
|
|
4
|
+
* Both events bubble and cross shadow roots. They fire once per `src`, after the viewer has
|
|
5
|
+
* rendered the result, so a listener can already find the rendered sections. Rebuilding the model
|
|
6
|
+
* because a label option changed does not fire them again.
|
|
7
|
+
*/
|
|
8
|
+
import type { LoadError } from './load/loader.js';
|
|
9
|
+
import type { Document, Problem } from './model/types.js';
|
|
10
|
+
import type { AsyncAPIViewerElement } from './element.js';
|
|
11
|
+
export interface AsyncAPILoadDetail {
|
|
12
|
+
/** The document URL, resolved against the page. */
|
|
13
|
+
url: string;
|
|
14
|
+
/** Exact `asyncapi` field, e.g. "3.0.0". */
|
|
15
|
+
specVersion: string;
|
|
16
|
+
specMajor: 2 | 3;
|
|
17
|
+
/** The normalised model the viewer renders. */
|
|
18
|
+
model: Document;
|
|
19
|
+
/** Reference and normalisation problems (the Problems panel); empty when there are none. */
|
|
20
|
+
problems: readonly Problem[];
|
|
21
|
+
}
|
|
22
|
+
export interface AsyncAPIErrorDetail {
|
|
23
|
+
/** The document URL, resolved against the page. */
|
|
24
|
+
url: string;
|
|
25
|
+
/** Why the document could not be shown: network, HTTP status, parse or version failure. */
|
|
26
|
+
error: LoadError;
|
|
27
|
+
}
|
|
28
|
+
/** `asyncapi-load`: the document loaded and rendered. */
|
|
29
|
+
export type AsyncAPILoadEvent = CustomEvent<AsyncAPILoadDetail>;
|
|
30
|
+
/** `asyncapi-error`: the document could not be loaded; the viewer shows the error in place. */
|
|
31
|
+
export type AsyncAPIErrorEvent = CustomEvent<AsyncAPIErrorDetail>;
|
|
32
|
+
/** Values the element reads as true or false (case-insensitive); an empty or bare attribute is true. */
|
|
33
|
+
export type BooleanAttribute = boolean | '' | 'true' | 'false' | '1' | '0' | 'yes' | 'no' | 'on' | 'off';
|
|
34
|
+
/**
|
|
35
|
+
* Every attribute of `<asyncapi-viewer>` in its kebab-case spelling, as written in HTML or JSX.
|
|
36
|
+
* Mirrors options.schema.json; a unit test keeps the two in step. Booleans are for frameworks
|
|
37
|
+
* that turn `true` into a bare attribute and `false` into none (React 19, Vue, Svelte, Lit).
|
|
38
|
+
*/
|
|
39
|
+
export interface AsyncAPIViewerAttributes {
|
|
40
|
+
/** The AsyncAPI document (JSON or YAML), as a path or URL relative to the page. Required. */
|
|
41
|
+
src?: string;
|
|
42
|
+
/** Element id; also prefixes every anchor inside the viewer. Generated when absent. */
|
|
43
|
+
id?: string;
|
|
44
|
+
/** Show the navigation column; a drawer behind a menu button on narrow containers. Default false. */
|
|
45
|
+
sidebar?: BooleanAttribute;
|
|
46
|
+
/** Show the Info section. Default true. */
|
|
47
|
+
info?: BooleanAttribute;
|
|
48
|
+
/** Show the Servers section and the server selector. Default true. */
|
|
49
|
+
servers?: BooleanAttribute;
|
|
50
|
+
/** Show the operations. Default true. */
|
|
51
|
+
operations?: BooleanAttribute;
|
|
52
|
+
/** Show the Messages section (component messages). Default true. */
|
|
53
|
+
messages?: BooleanAttribute;
|
|
54
|
+
/** Show the Schemas section (component schemas). Default true. */
|
|
55
|
+
schemas?: BooleanAttribute;
|
|
56
|
+
/** Show the load and validation problems panel. Default true. */
|
|
57
|
+
errors?: BooleanAttribute;
|
|
58
|
+
/** Show examples in the Messages section. Default false. */
|
|
59
|
+
'show-message-examples'?: BooleanAttribute;
|
|
60
|
+
/** Example panels start expanded; false starts them collapsed. Default true. */
|
|
61
|
+
'message-examples'?: BooleanAttribute;
|
|
62
|
+
/** Sidebar grouping for servers. Default byDefault. */
|
|
63
|
+
'show-servers'?: 'byDefault' | 'bySpecTags' | 'byServersTags';
|
|
64
|
+
/** Sidebar grouping for operations. Default byDefault. */
|
|
65
|
+
'show-operations'?: 'byDefault' | 'bySpecTags' | 'byOperationsTags';
|
|
66
|
+
/** AsyncAPI 3: label operations by channel address instead of title. Default false. */
|
|
67
|
+
'use-channel-address-as-identifier'?: BooleanAttribute;
|
|
68
|
+
/** Badge text for AsyncAPI 2 publish operations. Default PUB. */
|
|
69
|
+
'publish-label'?: string;
|
|
70
|
+
/** Badge text for AsyncAPI 2 subscribe operations. Default SUB. */
|
|
71
|
+
'subscribe-label'?: string;
|
|
72
|
+
/** Badge text for AsyncAPI 3 send operations. Default SEND. */
|
|
73
|
+
'send-label'?: string;
|
|
74
|
+
/** Badge text for AsyncAPI 3 receive operations. Default RECEIVE. */
|
|
75
|
+
'receive-label'?: string;
|
|
76
|
+
/** Badge text for AsyncAPI 3 send operations that carry a reply. Default REQUEST. */
|
|
77
|
+
'request-label'?: string;
|
|
78
|
+
/** Badge text for AsyncAPI 3 receive operations that carry a reply. Default REPLY. */
|
|
79
|
+
'reply-label'?: string;
|
|
80
|
+
/** JSON object; only `{"applyTraits": false}` changes anything. */
|
|
81
|
+
'parser-options'?: string;
|
|
82
|
+
/** @deprecated Accepted, warns once, does nothing. */
|
|
83
|
+
'schema-id'?: string;
|
|
84
|
+
/** auto follows the host page (Material scheme, html[data-theme], prefers-color-scheme). Default auto. */
|
|
85
|
+
theme?: 'auto' | 'light' | 'dark';
|
|
86
|
+
/** Show a light/dark toggle in the viewer header. Default false. */
|
|
87
|
+
'theme-toggle'?: BooleanAttribute;
|
|
88
|
+
/** Keep the Info, Servers, Messages and Schemas links visible while a sidebar search query is active. Default false. */
|
|
89
|
+
'search-keep-sections'?: BooleanAttribute;
|
|
90
|
+
}
|
|
91
|
+
declare global {
|
|
92
|
+
interface HTMLElementTagNameMap {
|
|
93
|
+
'asyncapi-viewer': AsyncAPIViewerElement;
|
|
94
|
+
}
|
|
95
|
+
interface HTMLElementEventMap {
|
|
96
|
+
'asyncapi-load': AsyncAPILoadEvent;
|
|
97
|
+
'asyncapi-error': AsyncAPIErrorEvent;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { AsyncAPIViewerElement } from './element.js';
|
|
2
|
+
export type * from './events.js';
|
|
3
|
+
export type * from './model/types.js';
|
|
4
|
+
export { parseOptions, DEFAULTS, OPTION_SPECS, toAttributeName } from './options.js';
|
|
5
|
+
export type { Options } from './options.js';
|
|
6
|
+
export { loadDocument, parseText, resolveUrl } from './load/loader.js';
|
|
7
|
+
export type { LoadResult, LoadError } from './load/loader.js';
|
|
8
|
+
export { RefResolver, isRef, schemaNameOf } from './load/refs.js';
|
|
9
|
+
export type { Resolved, Dereferenced, ResolveFailure } from './load/refs.js';
|
|
10
|
+
export { normalize } from './model/normalize.js';
|
|
11
|
+
export type { NormalizeInput } from './model/normalize.js';
|
|
12
|
+
export { checkDocument } from './model/invariants.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type LoadErrorKind = 'network' | 'http' | 'empty' | 'parse' | 'not-object' | 'unsupported';
|
|
2
|
+
export interface LoadError {
|
|
3
|
+
kind: LoadErrorKind;
|
|
4
|
+
/** One sentence, no URL (the URL is beside it). */
|
|
5
|
+
message: string;
|
|
6
|
+
status?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface LoadSuccess {
|
|
9
|
+
ok: true;
|
|
10
|
+
url: string;
|
|
11
|
+
/** The document exactly as served, for "Download spec". */
|
|
12
|
+
text: string;
|
|
13
|
+
format: 'json' | 'yaml';
|
|
14
|
+
/** The parsed root object. */
|
|
15
|
+
data: Record<string, unknown>;
|
|
16
|
+
/** Exact `asyncapi` field, e.g. "2.6.0". */
|
|
17
|
+
specVersion: string;
|
|
18
|
+
specMajor: 2 | 3;
|
|
19
|
+
}
|
|
20
|
+
export interface LoadFailure {
|
|
21
|
+
ok: false;
|
|
22
|
+
url: string;
|
|
23
|
+
error: LoadError;
|
|
24
|
+
}
|
|
25
|
+
export type LoadResult = LoadSuccess | LoadFailure;
|
|
26
|
+
export type FetchLike = (url: string) => Promise<{
|
|
27
|
+
ok: boolean;
|
|
28
|
+
status: number;
|
|
29
|
+
text(): Promise<string>;
|
|
30
|
+
}>;
|
|
31
|
+
/** Resolve `src` against a base (normally `document.baseURI`); returns `src` unchanged if that fails. */
|
|
32
|
+
export declare function resolveUrl(src: string, base: string): string;
|
|
33
|
+
export declare function loadDocument(url: string, fetchImpl?: FetchLike): Promise<LoadResult>;
|
|
34
|
+
/** JSON first, then YAML. Exported for tests and for future build-time validation. */
|
|
35
|
+
export declare function parseText(text: string): {
|
|
36
|
+
format: 'json' | 'yaml';
|
|
37
|
+
data: Record<string, unknown>;
|
|
38
|
+
} | {
|
|
39
|
+
error: LoadError;
|
|
40
|
+
};
|
|
41
|
+
export declare function detectVersion(data: Record<string, unknown>): {
|
|
42
|
+
specVersion: string;
|
|
43
|
+
specMajor: 2 | 3;
|
|
44
|
+
} | {
|
|
45
|
+
error: LoadError;
|
|
46
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `$ref` resolution.
|
|
3
|
+
*
|
|
4
|
+
* The normalisers are synchronous, so resolution happens in two steps: `preload()` walks the
|
|
5
|
+
* root document, fetches every external document it references (and theirs, recursively),
|
|
6
|
+
* each exactly once, and records what could not be loaded as problems. After that `resolve()`
|
|
7
|
+
* and `deref()` are synchronous lookups.
|
|
8
|
+
*
|
|
9
|
+
* A reference is `<url>#<json pointer>`. The url part is resolved against the document the
|
|
10
|
+
* reference appears in, so references inside an external file are relative to that file.
|
|
11
|
+
* Reference chains (a `$ref` pointing at another `$ref`) are followed with a cycle guard.
|
|
12
|
+
* Cycles in the schema graph itself are not an error here: the tree builder detects them by
|
|
13
|
+
* tracking resolved ids on its way down.
|
|
14
|
+
*/
|
|
15
|
+
import type { Problem } from '../model/types.js';
|
|
16
|
+
import { type FetchLike } from './loader.js';
|
|
17
|
+
export interface Resolved {
|
|
18
|
+
/** The target value with its own `$ref`s still in place. */
|
|
19
|
+
value: unknown;
|
|
20
|
+
/** Stable identity: `<absolute url>#<pointer>`. Two refs to the same target share an id. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** The document the target lives in; nested references resolve against it. */
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
/** The pointer within that document, e.g. "/components/schemas/Order". */
|
|
25
|
+
pointer: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ResolveFailure {
|
|
28
|
+
error: string;
|
|
29
|
+
}
|
|
30
|
+
/** What `deref()` returns: like `Resolved`, but inline values have no id. */
|
|
31
|
+
export interface Dereferenced {
|
|
32
|
+
value: unknown;
|
|
33
|
+
id: string | undefined;
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
pointer: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function isRef(value: unknown): value is {
|
|
38
|
+
$ref: string;
|
|
39
|
+
};
|
|
40
|
+
/** `#/components/schemas/Order` -> `Order`; undefined for anything else. */
|
|
41
|
+
export declare function schemaNameOf(id: string): string | undefined;
|
|
42
|
+
export declare class RefResolver {
|
|
43
|
+
#private;
|
|
44
|
+
readonly rootUrl: string;
|
|
45
|
+
constructor(rootUrl: string, rootDoc: Record<string, unknown>, fetchImpl?: FetchLike);
|
|
46
|
+
/** Fetch every external document reachable through `$ref`s. Returns load problems. */
|
|
47
|
+
preload(): Promise<Problem[]>;
|
|
48
|
+
/** Resolve one reference string as written at `baseUrl`. Synchronous; needs `preload()` first for external refs. */
|
|
49
|
+
resolve(ref: string, baseUrl: string): Resolved | ResolveFailure;
|
|
50
|
+
/**
|
|
51
|
+
* Follow `$ref` chains from a value until a non-reference is reached. Inline values come back
|
|
52
|
+
* unchanged with the caller's `baseUrl` and no id.
|
|
53
|
+
*/
|
|
54
|
+
deref(value: unknown, baseUrl: string): Dereferenced | ResolveFailure;
|
|
55
|
+
/** Every document loaded so far, by absolute URL (the root first). */
|
|
56
|
+
get documents(): ReadonlyMap<string, Record<string, unknown>>;
|
|
57
|
+
}
|
|
58
|
+
/** Every `$ref` string in a document with the JSON pointer of the object that holds it. */
|
|
59
|
+
export declare function collectRefs(doc: unknown): Array<[ref: string, where: string]>;
|
|
60
|
+
export declare function walkPointer(doc: unknown, pointer: string): unknown;
|
|
61
|
+
export declare function decodePointerSegment(segment: string): string;
|
|
62
|
+
export declare function encodePointerSegment(segment: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Avro schemas as SchemaNode trees, so Kafka documents get the same rows as JSON Schema.
|
|
3
|
+
*
|
|
4
|
+
* Mapping: record -> object (fields as children, `doc` as description, field `default`);
|
|
5
|
+
* a union with `null` marks the field optional and adds "null" to the types; a union of
|
|
6
|
+
* several non-null types becomes oneOf variants; array -> "[]" item; map -> "*" child;
|
|
7
|
+
* enum -> string with enum; fixed and bytes -> string · bytes; logical types become formats.
|
|
8
|
+
* Named types are registered when first seen so later references by name resolve; a
|
|
9
|
+
* reference back to an ancestor becomes a circular leaf.
|
|
10
|
+
*/
|
|
11
|
+
import type { SchemaNode } from './types.js';
|
|
12
|
+
export declare function isAvroFormat(schemaFormat: string): boolean;
|
|
13
|
+
/** Build a tree from an Avro schema; undefined when the value is not an Avro schema at all. */
|
|
14
|
+
export declare function avroToNode(schema: unknown, name: string, isRoot: boolean): SchemaNode | undefined;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared state for one normalisation run: the resolver, the problems list, the label options,
|
|
3
|
+
* anchor allocation and the small helpers every normaliser needs.
|
|
4
|
+
*/
|
|
5
|
+
import { type RefResolver } from '../load/refs.js';
|
|
6
|
+
import type { Binding, BindingScope, ExternalDocs, Problem, SectionId, SecurityRequirement, Tag } from './types.js';
|
|
7
|
+
export interface Labels {
|
|
8
|
+
publish: string;
|
|
9
|
+
subscribe: string;
|
|
10
|
+
send: string;
|
|
11
|
+
receive: string;
|
|
12
|
+
request: string;
|
|
13
|
+
reply: string;
|
|
14
|
+
}
|
|
15
|
+
export interface NormalizeOptions {
|
|
16
|
+
labels: Labels;
|
|
17
|
+
useChannelAddressAsIdentifier: boolean;
|
|
18
|
+
applyTraits: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_NORMALIZE_OPTIONS: NormalizeOptions;
|
|
21
|
+
export type Obj = Record<string, unknown>;
|
|
22
|
+
export declare function isObj(value: unknown): value is Obj;
|
|
23
|
+
export declare function str(value: unknown): string | undefined;
|
|
24
|
+
/** A dereferenced object together with where it lives, for nested references. */
|
|
25
|
+
export interface Located {
|
|
26
|
+
value: Obj;
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
/** Resolved id when the value came through a `$ref`. */
|
|
29
|
+
id: string | undefined;
|
|
30
|
+
}
|
|
31
|
+
export declare class Context {
|
|
32
|
+
#private;
|
|
33
|
+
readonly resolver: RefResolver;
|
|
34
|
+
readonly options: NormalizeOptions;
|
|
35
|
+
readonly problems: Problem[];
|
|
36
|
+
constructor(resolver: RefResolver, options: NormalizeOptions);
|
|
37
|
+
problem(severity: Problem['severity'], message: string, where: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Dereference `value` (following `$ref` chains) and require an object. Anything else is
|
|
40
|
+
* recorded as a problem at `where` and yields undefined.
|
|
41
|
+
*/
|
|
42
|
+
object(value: unknown, baseUrl: string, where: string): Located | undefined;
|
|
43
|
+
/** Iterate a map-shaped field (`servers`, `channels`, ...) dereferencing each entry. */
|
|
44
|
+
entries(map: unknown, baseUrl: string, where: string): Generator<[key: string, located: Located, where: string]>;
|
|
45
|
+
/** Iterate a list field dereferencing each entry. */
|
|
46
|
+
items(list: unknown, baseUrl: string, where: string): Generator<[located: Located, where: string]>;
|
|
47
|
+
/** A document-unique anchor for `id` within a section. */
|
|
48
|
+
anchor(section: SectionId, id: string): string;
|
|
49
|
+
tags(list: unknown, baseUrl: string, where: string): Tag[];
|
|
50
|
+
externalDocs(value: unknown, baseUrl: string, where: string): ExternalDocs | undefined;
|
|
51
|
+
/** `bindings: { kafka: { groupId: x, bindingVersion: y } }` -> one Binding per key. */
|
|
52
|
+
bindings(scope: BindingScope, value: unknown, baseUrl: string, where: string): Binding[];
|
|
53
|
+
/**
|
|
54
|
+
* Apply `traits` to an object: the object's own fields win, then earlier traits over later
|
|
55
|
+
* ones (the official parser's order). Keys a trait must not carry are dropped with a problem.
|
|
56
|
+
* Returns the object unchanged when `applyTraits` is off or there are no traits.
|
|
57
|
+
*/
|
|
58
|
+
withTraits(value: Obj, baseUrl: string, where: string, forbidden: readonly string[]): Obj;
|
|
59
|
+
/** The last pointer segment of a resolved id: `#/servers/production` -> `production`. */
|
|
60
|
+
static keyOf(id: string | undefined): string | undefined;
|
|
61
|
+
static schemaName(id: string | undefined): string | undefined;
|
|
62
|
+
}
|
|
63
|
+
/** Deep merge where `over` wins; lists and scalars are replaced, objects merged key by key. */
|
|
64
|
+
/**
|
|
65
|
+
* The facts of a security scheme object that a reader wants beside its name: where an API key
|
|
66
|
+
* goes, the HTTP scheme, the OpenID discovery URL and, for OAuth 2, every flow with its URLs and
|
|
67
|
+
* scopes. v2 flows list scopes under `scopes`, v3 under `availableScopes`; both are read.
|
|
68
|
+
*/
|
|
69
|
+
export declare function securitySchemeDetails(scheme: Obj): Pick<SecurityRequirement, 'facts' | 'openIdConnectUrl' | 'flows' | 'extensions'>;
|
|
70
|
+
export declare function mergeObjects(base: Obj, over: Obj): Obj;
|
|
71
|
+
/**
|
|
72
|
+
* Anchor slug for an id. Runs of separators collapse to one hyphen so an anchor never contains
|
|
73
|
+
* "--", the separator between element id, section and item in page anchors.
|
|
74
|
+
*/
|
|
75
|
+
export declare function slug(id: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural rules every normalised Document must satisfy, whatever produced it.
|
|
3
|
+
* Used by the fixture tests now and by the normaliser tests and the coverage gate later.
|
|
4
|
+
* Returns human-readable violations; an empty array means the document is well formed.
|
|
5
|
+
*/
|
|
6
|
+
import type { Document } from './types.js';
|
|
7
|
+
export declare function checkDocument(doc: Document): string[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point: turn a loaded document into the normalised model.
|
|
3
|
+
*/
|
|
4
|
+
import type { RefResolver } from '../load/refs.js';
|
|
5
|
+
import { type NormalizeOptions } from './context.js';
|
|
6
|
+
import type { Document, Problem } from './types.js';
|
|
7
|
+
export interface NormalizeInput {
|
|
8
|
+
resolver: RefResolver;
|
|
9
|
+
data: Record<string, unknown>;
|
|
10
|
+
specVersion: string;
|
|
11
|
+
specMajor: 2 | 3;
|
|
12
|
+
/** Problems found earlier (reference preloading) to carry into the document. */
|
|
13
|
+
problems?: Problem[];
|
|
14
|
+
options?: Partial<NormalizeOptions>;
|
|
15
|
+
}
|
|
16
|
+
export declare function normalize(input: NormalizeInput): Document;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context } from './context.js';
|
|
2
|
+
import type { Schema } from './types.js';
|
|
3
|
+
/** Formats we can render as a tree. Anything else becomes a RawSchema. */
|
|
4
|
+
export declare function isTreeFormat(schemaFormat: string): boolean;
|
|
5
|
+
export interface BuildInput {
|
|
6
|
+
/** The schema as written: a schema object, a `$ref`, a boolean, or a Multi Format Schema Object. */
|
|
7
|
+
raw: unknown;
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
where: string;
|
|
10
|
+
/** Root name: "" for payload/headers, the key for components.schemas. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Applies when `raw` is a plain schema object without its own `schemaFormat`. */
|
|
13
|
+
defaultFormat: string;
|
|
14
|
+
}
|
|
15
|
+
/** Build a payload, headers or component schema. Handles the Multi Format Schema Object. */
|
|
16
|
+
export declare function buildSchema(ctx: Context, input: BuildInput): Schema | undefined;
|