@dogsbay/format-openapi 0.2.0-beta.14 → 0.2.0-beta.141

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/dist/cli.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import type { FormatPlugin } from "@dogsbay/types";
2
2
  export declare const plugin: FormatPlugin;
3
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js CHANGED
@@ -10,7 +10,9 @@ export const plugin = {
10
10
  return parseOpenApiSpec(source, {
11
11
  hrefPrefix: typeof opts.hrefPrefix === "string" ? opts.hrefPrefix : undefined,
12
12
  section: typeof opts.section === "string" ? opts.section : undefined,
13
+ reservedSlugs: Array.isArray(opts.reservedSlugs)
14
+ ? opts.reservedSlugs.filter((s) => typeof s === "string")
15
+ : undefined,
13
16
  });
14
17
  },
15
18
  };
16
- //# sourceMappingURL=cli.js.map
@@ -13,4 +13,3 @@ import type { CodeSample } from "./types.js";
13
13
  * use `x-code-samples` (kebab). Honour both.
14
14
  */
15
15
  export declare function resolveCodeSamples(operation: any, method: string, path: string, baseUrl: string): CodeSample[];
16
- //# sourceMappingURL=code-samples.d.ts.map
@@ -39,6 +39,16 @@ function readVendorSamples(operation) {
39
39
  sample.label = entry.label;
40
40
  samples.push(sample);
41
41
  }
42
+ // A `label` only disambiguates when it VARIES across samples (e.g. "Sync" vs
43
+ // "Async" for two Python samples). Speakeasy sets every sample's label to the
44
+ // SDK method name (e.g. "banPartner"), which is identical across languages and
45
+ // makes every tab read the same — drop it so the tab falls back to the
46
+ // language name (Python, Go, …), the API-docs convention.
47
+ const distinctLabels = new Set(samples.map((s) => s.label));
48
+ if (samples.length > 1 && distinctLabels.size === 1) {
49
+ for (const s of samples)
50
+ delete s.label;
51
+ }
42
52
  return samples;
43
53
  }
44
54
  function generateCodeSamples(method, path, baseUrl) {
@@ -65,4 +75,3 @@ function generateCodeSamples(method, path, baseUrl) {
65
75
  },
66
76
  ];
67
77
  }
68
- //# sourceMappingURL=code-samples.js.map
package/dist/core.d.ts ADDED
@@ -0,0 +1,111 @@
1
+ import type { ExportPage, Heading, NavItem, TreeNode } from "@dogsbay/types";
2
+ export { findSpec, specCandidates, type SpecLookup } from "./spec-path.js";
3
+ export interface ParseOpenApiOptions {
4
+ /** When the importer wants nav hrefs to start with this prefix. */
5
+ hrefPrefix?: string;
6
+ /** Sub-path within the namespace for emitted pages, e.g. "api". */
7
+ section?: string;
8
+ /**
9
+ * First URL segments the site already uses for something else: the
10
+ * source's own `/<name>/` prefix, the base path, taxonomy indexes. A tag
11
+ * (or untagged operation) with one of these slugs is renamed (`api-2`),
12
+ * because a site-root link to `/api/list-things` on a source published
13
+ * under `/api/` reads as already prefixed and is never rewritten.
14
+ */
15
+ reservedSlugs?: readonly string[];
16
+ }
17
+ /**
18
+ * A dereferenced spec (`prepareSpec`) as a page per operation, a page per tag
19
+ * and an info page, with their nav: for a spec that IS the source.
20
+ */
21
+ export declare function specToPages(spec: any, options?: ParseOpenApiOptions): {
22
+ pages: ExportPage[];
23
+ nav: NavItem[];
24
+ };
25
+ /**
26
+ * Spec text → object. JSON is read natively; YAML needs a parser passed in
27
+ * (`yaml`'s `parse`, js-yaml's `load`), so a host that has one does not
28
+ * bundle a second.
29
+ */
30
+ export declare function parseSpecText(text: string, parseYaml?: (text: string) => unknown): unknown;
31
+ /**
32
+ * A parsed spec → the dereferenced OpenAPI 3 document every function here
33
+ * reads. Swagger 2.0 is upgraded to OpenAPI 3 first: everything below reads
34
+ * the 3.x shape (`requestBody`, response `content`, `servers`), so a 2.0
35
+ * spec parsed without the upgrade lost every body parameter and response
36
+ * schema while still producing plausible-looking pages. Canonical's Anbox
37
+ * Cloud API specs are 2.0.
38
+ */
39
+ export declare function prepareSpec(parsed: unknown, label?: string): Promise<any>;
40
+ /**
41
+ * Prepared specs by path, each parsed and dereferenced once however many
42
+ * pages embed it. `read` returns the file's text; failures are cached too,
43
+ * so a broken spec is reported per page without being parsed again.
44
+ */
45
+ export declare function createSpecCache(read: (path: string) => string | Promise<string>, parseYaml?: (text: string) => unknown): {
46
+ get(path: string): Promise<any>;
47
+ readonly size: number;
48
+ };
49
+ /** What a value over its bound is shown as. */
50
+ export declare const VALUE_TOO_LARGE = "(not shown: too large)";
51
+ /**
52
+ * The summary and description, with a sentence the generator broke in two
53
+ * put back together. drf-yasg makes the summary from a docstring's first
54
+ * LINE and the description from the rest, so a sentence that wraps reads
55
+ * "…retrieve the list of" + a paragraph "activity streams.". A summary with
56
+ * no closing punctuation, followed by a description that starts in lower
57
+ * case, takes the description's first paragraph when that ends the
58
+ * sentence and the summary is long enough to be a wrapped line. Only plain text is moved:
59
+ * the summary is shown as text, so Markdown in the continuation would show
60
+ * its syntax.
61
+ */
62
+ export declare function summaryAndDescription(summary: string | undefined, description: string | undefined): {
63
+ summary?: string;
64
+ description?: string;
65
+ };
66
+ export interface OpenApiEmbedOptions {
67
+ level?: number;
68
+ /** Ids the page already uses: the embed's headings get others. */
69
+ usedIds?: Iterable<string>;
70
+ /**
71
+ * One operation instead of the whole spec: `:::openapi{spec path method}`,
72
+ * what GitBook's `{% openapi src path method %}` block shows. The tree is
73
+ * that operation's endpoint node alone; no such operation throws.
74
+ */
75
+ operation?: {
76
+ path: string;
77
+ method: string;
78
+ };
79
+ }
80
+ /**
81
+ * The operation a `:::openapi` directive selects from its props, or why it
82
+ * cannot: `path` and `method` come together or not at all.
83
+ */
84
+ export declare function directiveOperation(props: Record<string, unknown> | undefined): {
85
+ operation?: {
86
+ path: string;
87
+ method: string;
88
+ };
89
+ } | {
90
+ error: string;
91
+ };
92
+ export interface OpenApiEmbed {
93
+ /** Version line, description, then one section per tag of endpoint nodes. */
94
+ tree: TreeNode[];
95
+ /** One entry per tag section, for the page's table of contents. */
96
+ headings: Heading[];
97
+ operations: number;
98
+ }
99
+ /**
100
+ * A whole spec as the BODY of one page: what Swagger UI or Redoc show when a
101
+ * page embeds them. The info version and description, then a section per tag
102
+ * (declared order, then first use; untagged operations last, under "Other"),
103
+ * each holding its operations as `endpoint` nodes in document order.
104
+ *
105
+ * `spec` is a dereferenced spec (`prepareSpec`), and is not modified: the
106
+ * nodes are copies, so one parsed spec serves every page that embeds it.
107
+ *
108
+ * `specToPages` is the other shape — a page per operation — for a spec
109
+ * that IS the source. This one is for a spec a prose page points at.
110
+ */
111
+ export declare function embedSpec(spec: any, options?: OpenApiEmbedOptions): OpenApiEmbed;