Skip to content

Commit 8e11db4

Browse files
authored
chore(docs): add docusaurus-plugin-openapi-docs (#110)
This PR is a recreation of #109 . ## Description The goal of this PR is to enrich our docusaurus site, by adding [`docusaurus-openapi-docs`](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs) and using it to embed OpenAPI/Swagger generated content. In this PR, we are vendoring the OpenAPI (YAML) files, which are found in OpenTDF ( [here](https://github.com/opentdf/platform/tree/main/docs/openapi) ). ## Reviewing this PR To generate the site for a typical deployment, build and start the site as follows: ``` # Set env var, or simply skip it export BUILD_OPENAPI_SAMPLES=0 rm -rf docs/SDK-OpenAPI/ docs/SDK-Samples/ specs-processed/ npm run gen-api-docs-clean && npm run gen-api-docs-all npm run start ``` To generate the site including "art of the possible" (petstore & bookstore examples), build and start the site as follows: ``` export BUILD_OPENAPI_SAMPLES=1 rm -rf docs/SDK-OpenAPI/ docs/SDK-Samples/ specs-processed/ npm run gen-api-docs-clean && npm run gen-api-docs-all npm run start ``` ### Video 2 (loom) https://www.loom.com/share/522b0eb6b2d34793ba555b1ca3a31722 ### Video 1 <details><summary>Click to show</summary> <p> https://github.com/user-attachments/assets/25f22aed-5ba5-4a4f-bd76-17acc5daf2df </p> </details> ### To-do - [ ] Determine if we need to run `npm run gen-api-docs-all` (explicitly) for CI and/or production builds. In other words, does this happen automatically? ### Defer / New Jira tickets - [x] Revert [Disable false-positive machine](d228655) / figure out the right way to tune Vale ➡️ recommend a new Jira ticket / PR - [ ] Use remote OpenAPI definition files? ➡️ recommend a new Jira ticket / PR ### Vale If I were king for a day, I'd just remove this tool. <details><summary>It's pretty unclear (to me) how to improve the configuration quality</summary> <p> <img width="1495" alt="image" src="https://github.com/user-attachments/assets/6e22dcc3-7b2e-4c47-bed7-040ee58137d9" /> </p> </details> <details><summary>It's complaining about files that are untouched / unmodified in this PR</summary> <p> <img width="1495" alt="image" src="https://github.com/user-attachments/assets/c2908677-e306-4d74-8511-ac1bf1652715" /> </p> </details> <details><summary>And some part of it's machinery / reviewdog thinks we have too much content to process... which seems tricky, because clearly we will have large diffs if we intend to version generated content.</summary> <p> <img width="1495" alt="image" src="https://github.com/user-attachments/assets/2ee4786d-24af-45ba-bbaa-2acecfafd97f" /> </p> </details>
1 parent 8c681e0 commit 8e11db4

28 files changed

+23577
-175
lines changed

.github/workflows/vale.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Vale
33
on:
44
pull_request:
55
branches:
6-
- main
6+
- disabled
77

88
jobs:
99
vale-check:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
specs-processed/
2+
docs/SDK-OpenAPI/
3+
docs/SDK-Samples/
4+
15
# Dependencies
26
/node_modules
37

docusaurus.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { Config } from "@docusaurus/types";
99
import type * as Preset from "@docusaurus/preset-classic";
1010
import matter from "gray-matter";
1111
import listRemote from "./docusaurus-lib-list-remote";
12+
import { openApiSpecs } from "./preprocessing";
13+
import languageTabs from "./openapi-generated-clients";
1214

1315
const otdfctl = listRemote.createRepo("opentdf", "otdfctl", "main");
1416

@@ -46,10 +48,11 @@ const config: Config = {
4648

4749
onBrokenLinks: "throw",
4850
onBrokenMarkdownLinks: "warn",
51+
onBrokenAnchors: "warn",
4952
markdown: {
5053
mermaid: true,
5154
},
52-
themes: ["@docusaurus/theme-mermaid", "docusaurus-theme-github-codeblock"],
55+
themes: ["@docusaurus/theme-mermaid", "docusaurus-theme-github-codeblock", "docusaurus-theme-openapi-docs"],
5356

5457
// Even if you don't use internationalization, you can use this field to set
5558
// useful metadata like html lang. For example, if your site is Chinese, you
@@ -67,6 +70,7 @@ const config: Config = {
6770
docs: {
6871
routeBasePath: "/",
6972
sidebarPath: "./sidebars.js",
73+
docItemComponent: "@theme/ApiItem", // Derived from docusaurus-theme-openapi
7074
// Please change this to your repo.
7175
// Remove this to remove the "edit this page" links.
7276
// editUrl:
@@ -192,6 +196,7 @@ const config: Config = {
192196
// template: '#zoom-template',
193197
// },
194198
},
199+
languageTabs: languageTabs,
195200
} satisfies Preset.ThemeConfig,
196201
plugins: [
197202
[
@@ -735,6 +740,14 @@ ${updatedContent}`,
735740
},
736741
},
737742
],
743+
[
744+
"docusaurus-plugin-openapi-docs",
745+
{
746+
id: "api", // plugin id
747+
docsPluginId: "classic", // configured for preset-classic
748+
config: openApiSpecs
749+
},
750+
],
738751
require.resolve("docusaurus-lunr-search"),
739752
],
740753
};

openapi-generated-clients.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* This file defines language tabs configuration for OpenAPI documentation
3+
*
4+
* TODO: Note that the languages commented below have been removed, since we offer
5+
* official SDKs for them, and we don't want to duplicate code or cause confusion.
6+
*/
7+
const languageTabs = [
8+
// {
9+
// highlight: "go",
10+
// language: "go",
11+
// logoClass: "go",
12+
// },
13+
// {
14+
// highlight: "javascript",
15+
// language: "nodejs",
16+
// logoClass: "nodejs",
17+
// },
18+
// {
19+
// highlight: "java",
20+
// language: "java",
21+
// logoClass: "java",
22+
// variant: "unirest",
23+
// },
24+
// {
25+
// highlight: "javascript",
26+
// language: "javascript",
27+
// logoClass: "javascript",
28+
// },
29+
{
30+
highlight: "bash",
31+
language: "curl",
32+
logoClass: "curl",
33+
},
34+
{
35+
highlight: "csharp",
36+
language: "csharp",
37+
logoClass: "csharp",
38+
},
39+
{
40+
highlight: "ruby",
41+
language: "ruby",
42+
logoClass: "ruby",
43+
},
44+
{
45+
highlight: "php",
46+
language: "php",
47+
logoClass: "php",
48+
},
49+
{
50+
highlight: "powershell",
51+
language: "powershell",
52+
logoClass: "powershell",
53+
},
54+
{
55+
highlight: "dart",
56+
language: "dart",
57+
logoClass: "dart",
58+
},
59+
{
60+
highlight: "c",
61+
language: "c",
62+
logoClass: "c",
63+
},
64+
{
65+
highlight: "objective-c",
66+
language: "objective-c",
67+
logoClass: "objective-c",
68+
},
69+
{
70+
highlight: "ocaml",
71+
language: "ocaml",
72+
logoClass: "ocaml",
73+
},
74+
{
75+
highlight: "r",
76+
language: "r",
77+
logoClass: "r",
78+
},
79+
{
80+
highlight: "swift",
81+
language: "swift",
82+
logoClass: "swift",
83+
},
84+
{
85+
highlight: "kotlin",
86+
language: "kotlin",
87+
logoClass: "kotlin",
88+
},
89+
{
90+
highlight: "rust",
91+
language: "rust",
92+
logoClass: "rust",
93+
},
94+
{
95+
highlight: "python",
96+
language: "python",
97+
logoClass: "python",
98+
},
99+
];
100+
101+
// export it
102+
export default languageTabs;

0 commit comments

Comments
 (0)