docusaurus-theme-openapi-docs 4.0.0 → 4.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.
Files changed (39) hide show
  1. package/lib/markdown/utils.d.ts +5 -4
  2. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +1 -1
  3. package/lib/theme/ApiExplorer/CodeSnippets/index.js +2 -112
  4. package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +1 -0
  5. package/lib/theme/ApiExplorer/CodeSnippets/languages.js +30 -6
  6. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +146 -2
  7. package/lib/theme/ApiExplorer/CodeTabs/index.js +34 -8
  8. package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -1
  9. package/lib/theme/ApiExplorer/MethodEndpoint/index.js +5 -2
  10. package/lib/theme/ApiExplorer/ParamOptions/index.js +1 -0
  11. package/lib/theme/ApiExplorer/Request/_Request.scss +5 -0
  12. package/lib/theme/ApiExplorer/index.js +6 -0
  13. package/lib/theme/ApiItem/Layout/index.d.ts +3 -0
  14. package/lib/theme/ApiItem/Layout/index.js +117 -0
  15. package/lib/theme/ApiItem/Layout/styles.module.css +17 -0
  16. package/lib/theme/ApiItem/index.js +1 -1
  17. package/lib/theme/ParamsItem/index.d.ts +2 -1
  18. package/lib/theme/ParamsItem/index.js +74 -17
  19. package/lib/theme/SchemaItem/index.d.ts +1 -1
  20. package/lib/theme/SchemaItem/index.js +106 -20
  21. package/package.json +6 -5
  22. package/src/markdown/utils.ts +7 -6
  23. package/src/plugin-content-docs.d.ts +2 -0
  24. package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +2 -0
  25. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +6 -112
  26. package/src/theme/ApiExplorer/CodeSnippets/languages.ts +26 -5
  27. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +146 -2
  28. package/src/theme/ApiExplorer/CodeTabs/index.tsx +40 -9
  29. package/src/theme/ApiExplorer/MethodEndpoint/index.tsx +7 -3
  30. package/src/theme/ApiExplorer/ParamOptions/index.tsx +1 -0
  31. package/src/theme/ApiExplorer/Request/_Request.scss +5 -0
  32. package/src/theme/ApiExplorer/index.tsx +2 -0
  33. package/src/theme/ApiItem/Layout/index.tsx +82 -0
  34. package/src/theme/ApiItem/Layout/styles.module.css +17 -0
  35. package/src/theme/ApiItem/index.tsx +1 -1
  36. package/src/theme/ParamsItem/index.tsx +75 -15
  37. package/src/theme/SchemaItem/index.tsx +106 -17
  38. package/src/theme-classic.d.ts +0 -2
  39. package/src/theme-openapi.d.ts +4 -0
@@ -11,6 +11,7 @@ import CodeBlock from "@theme/CodeBlock";
11
11
  import clsx from "clsx";
12
12
  import ReactMarkdown from "react-markdown";
13
13
  import rehypeRaw from "rehype-raw";
14
+ import remarkGfm from "remark-gfm";
14
15
 
15
16
  import { createDescription } from "../../markdown/createDescription";
16
17
  import { guard } from "../../markdown/utils";
@@ -27,23 +28,54 @@ export interface Props {
27
28
  discriminator: boolean;
28
29
  }
29
30
 
30
- export default function SchemaItem({
31
- children: collapsibleSchemaContent,
32
- collapsible,
33
- name,
34
- qualifierMessage,
35
- required,
36
- schemaName,
37
- schema,
38
- }: Props) {
31
+ const transformEnumDescriptions = (
32
+ enumDescriptions?: Record<string, string>
33
+ ) => {
34
+ if (enumDescriptions) {
35
+ return Object.entries(enumDescriptions);
36
+ }
37
+
38
+ return [];
39
+ };
40
+
41
+ const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
42
+ if (enumDescriptions?.length) {
43
+ return `| Enum Value | Description |
44
+ | ---- | ----- |
45
+ ${enumDescriptions
46
+ .map((desc) => {
47
+ return `| ${desc[0]} | ${desc[1]} | `.replaceAll("\n", "<br/>");
48
+ })
49
+ .join("\n")}
50
+ `;
51
+ }
52
+
53
+ return "";
54
+ };
55
+
56
+ export default function SchemaItem(props: Props) {
57
+ const {
58
+ children: collapsibleSchemaContent,
59
+ collapsible,
60
+ name,
61
+ qualifierMessage,
62
+ required,
63
+ schemaName,
64
+ schema,
65
+ } = props;
39
66
  let deprecated;
40
67
  let schemaDescription;
41
- let defaultValue;
68
+ let defaultValue: string | undefined;
69
+ let example: string | undefined;
42
70
  let nullable;
71
+ let enumDescriptions: [string, string][] = [];
72
+
43
73
  if (schema) {
44
74
  deprecated = schema.deprecated;
45
75
  schemaDescription = schema.description;
76
+ enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
46
77
  defaultValue = schema.default;
78
+ example = schema.example;
47
79
  nullable = schema.nullable;
48
80
  }
49
81
 
@@ -60,6 +92,19 @@ export default function SchemaItem({
60
92
  <span className="openapi-schema__nullable">nullable</span>
61
93
  ));
62
94
 
95
+ const renderEnumDescriptions = guard(
96
+ getEnumDescriptionMarkdown(enumDescriptions),
97
+ (value) => {
98
+ return (
99
+ <ReactMarkdown
100
+ remarkPlugins={[remarkGfm]}
101
+ rehypePlugins={[rehypeRaw]}
102
+ children={value}
103
+ />
104
+ );
105
+ }
106
+ );
107
+
63
108
  const renderSchemaDescription = guard(schemaDescription, (description) => (
64
109
  <div>
65
110
  <ReactMarkdown
@@ -90,11 +135,53 @@ export default function SchemaItem({
90
135
  </div>
91
136
  ));
92
137
 
93
- const renderDefaultValue = guard(defaultValue, (value) => (
94
- <div className="">
95
- <ReactMarkdown children={`**Default value:** \`${value}\``} />
96
- </div>
97
- ));
138
+ function renderDefaultValue() {
139
+ if (defaultValue !== undefined) {
140
+ if (typeof defaultValue === "string") {
141
+ return (
142
+ <div>
143
+ <strong>Default value: </strong>
144
+ <span>
145
+ <code>{defaultValue}</code>
146
+ </span>
147
+ </div>
148
+ );
149
+ }
150
+ return (
151
+ <div>
152
+ <strong>Default value: </strong>
153
+ <span>
154
+ <code>{JSON.stringify(defaultValue)}</code>
155
+ </span>
156
+ </div>
157
+ );
158
+ }
159
+ return undefined;
160
+ }
161
+
162
+ function renderExample() {
163
+ if (example !== undefined) {
164
+ if (typeof example === "string") {
165
+ return (
166
+ <div>
167
+ <strong>Example: </strong>
168
+ <span>
169
+ <code>{example}</code>
170
+ </span>
171
+ </div>
172
+ );
173
+ }
174
+ return (
175
+ <div>
176
+ <strong>Example: </strong>
177
+ <span>
178
+ <code>{JSON.stringify(example)}</code>
179
+ </span>
180
+ </div>
181
+ );
182
+ }
183
+ return undefined;
184
+ }
98
185
 
99
186
  const schemaContent = (
100
187
  <div>
@@ -114,9 +201,11 @@ export default function SchemaItem({
114
201
  {renderRequired}
115
202
  {renderDeprecated}
116
203
  </span>
117
- {renderQualifierMessage}
118
- {renderDefaultValue}
119
204
  {renderSchemaDescription}
205
+ {renderEnumDescriptions}
206
+ {renderQualifierMessage}
207
+ {renderDefaultValue()}
208
+ {renderExample()}
120
209
  {collapsibleSchemaContent ?? collapsibleSchemaContent}
121
210
  </div>
122
211
  );
@@ -27,8 +27,6 @@ declare module "@docusaurus/theme-common/internal" {
27
27
  export interface LineProps extends ILineProps {}
28
28
  export interface CodeBlockProps extends ICodeBlockProps {}
29
29
 
30
- export function useDoc();
31
-
32
30
  export function usePrismTheme(): PrismTheme;
33
31
 
34
32
  export function sanitizeTabsChildren(children: TabProps["children"]);
@@ -54,6 +54,10 @@ declare module "@theme/ApiItem/hooks" {
54
54
  }
55
55
 
56
56
  declare module "@theme/ApiItem/Layout" {
57
+ export interface Props {
58
+ readonly children: JSX.Element;
59
+ }
60
+
57
61
  export default function Layout(props: any): JSX.Element;
58
62
  }
59
63