docusaurus-plugin-openapi-docs 0.0.0-beta.691 → 0.0.0-beta.719
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 +2 -0
- package/lib/index.js +75 -19
- package/lib/markdown/createAuthentication.js +4 -3
- package/lib/markdown/createCallbacks.d.ts +6 -0
- package/lib/markdown/createCallbacks.js +78 -0
- package/lib/markdown/createDeprecationNotice.js +6 -3
- package/lib/markdown/createDescription.js +1 -9
- package/lib/markdown/createHeading.js +4 -5
- package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
- package/lib/markdown/createRequestHeader.d.ts +1 -1
- package/lib/markdown/createRequestHeader.js +10 -1
- package/lib/markdown/createSchema.d.ts +1 -1
- package/lib/markdown/createSchema.js +23 -9
- package/lib/markdown/createSchema.test.js +2 -2
- package/lib/markdown/createStatusCodes.d.ts +3 -1
- package/lib/markdown/createStatusCodes.js +8 -6
- package/lib/markdown/createVersionBadge.js +1 -1
- package/lib/markdown/index.d.ts +3 -2
- package/lib/markdown/index.js +31 -6
- package/lib/markdown/schema.js +3 -0
- package/lib/markdown/utils.d.ts +9 -3
- package/lib/markdown/utils.js +29 -4
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +60 -7
- package/lib/openapi/openapi.test.js +2 -0
- package/lib/openapi/types.d.ts +18 -13
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +1 -1
- package/lib/openapi/utils/services/OpenAPIParser.js +2 -1
- package/lib/openapi/utils/services/RedocNormalizedOptions.js +49 -49
- package/lib/openapi/utils/types/index.d.ts +1 -1
- package/lib/openapi/utils/types/open-api.d.ts +4 -4
- package/lib/openapi/utils/types.d.ts +5 -5
- package/lib/openapi/utils/utils/openapi.js +1 -1
- package/lib/options.js +2 -1
- package/lib/sidebars/index.d.ts +2 -2
- package/lib/sidebars/index.js +49 -9
- package/lib/types.d.ts +16 -3
- package/package.json +11 -9
- package/src/index.ts +134 -21
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +4 -28
- package/src/markdown/createAuthentication.ts +11 -6
- package/src/markdown/createCallbacks.ts +101 -0
- package/src/markdown/createContactInfo.ts +1 -1
- package/src/markdown/createDeprecationNotice.ts +2 -2
- package/src/markdown/createDescription.ts +2 -10
- package/src/markdown/createHeading.ts +10 -7
- package/src/markdown/createLicense.ts +1 -1
- package/src/markdown/createLogo.ts +1 -1
- package/src/markdown/createParamsDetails.ts +1 -1
- package/src/markdown/createRequestBodyDetails.ts +2 -2
- package/src/markdown/createRequestHeader.ts +15 -1
- package/src/markdown/createRequestSchema.ts +1 -1
- package/src/markdown/createResponseSchema.ts +1 -1
- package/src/markdown/createSchema.test.ts +6 -4
- package/src/markdown/createSchema.ts +32 -19
- package/src/markdown/createStatusCodes.ts +11 -7
- package/src/markdown/createVersionBadge.ts +8 -4
- package/src/markdown/index.ts +45 -14
- package/src/markdown/schema.ts +4 -0
- package/src/markdown/utils.ts +37 -4
- package/src/openapi/__fixtures__/examples/openapi.yaml +29 -0
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
- package/src/openapi/openapi.test.ts +3 -0
- package/src/openapi/openapi.ts +77 -9
- package/src/openapi/types.ts +6 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
- package/src/openapi/utils/services/OpenAPIParser.ts +3 -3
- package/src/openapi/utils/utils/openapi.ts +8 -8
- package/src/options.ts +2 -1
- package/src/sidebars/index.ts +70 -15
- package/src/types.ts +21 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { guard, Props, render } from "./utils";
|
|
8
|
+
import { clean, guard, Props, render } from "./utils";
|
|
9
9
|
|
|
10
10
|
function createAdmonition({ children }: Props) {
|
|
11
11
|
return `:::caution deprecated\n\n${render(children)}\n\n:::`;
|
|
@@ -23,7 +23,7 @@ export function createDeprecationNotice({
|
|
|
23
23
|
return guard(deprecated, () =>
|
|
24
24
|
createAdmonition({
|
|
25
25
|
children:
|
|
26
|
-
description ??
|
|
26
|
+
clean(description) ??
|
|
27
27
|
"This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
|
|
28
28
|
})
|
|
29
29
|
);
|
|
@@ -5,16 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { clean } from "./utils";
|
|
9
9
|
|
|
10
10
|
export function createDescription(description: string | undefined) {
|
|
11
|
-
|
|
12
|
-
return "";
|
|
13
|
-
}
|
|
14
|
-
return `\n\n${description
|
|
15
|
-
.replace(lessThan, "<")
|
|
16
|
-
.replace(greaterThan, ">")
|
|
17
|
-
.replace(codeFence, function (match) {
|
|
18
|
-
return match.replace(/\\>/g, ">");
|
|
19
|
-
})}\n\n`;
|
|
11
|
+
return `\n\n${clean(description)}\n\n`;
|
|
20
12
|
}
|
|
@@ -5,16 +5,19 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { clean, create } from "./utils";
|
|
9
9
|
|
|
10
10
|
export function createHeading(heading: string) {
|
|
11
11
|
return [
|
|
12
|
-
create(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
create(
|
|
13
|
+
"Heading",
|
|
14
|
+
{
|
|
15
|
+
children: clean(heading),
|
|
16
|
+
as: "h1",
|
|
17
|
+
className: "openapi__heading",
|
|
18
|
+
},
|
|
19
|
+
{ inline: true }
|
|
20
|
+
),
|
|
18
21
|
`\n\n`,
|
|
19
22
|
];
|
|
20
23
|
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { LicenseObject } from "../openapi/types";
|
|
9
8
|
import { create, guard } from "./utils";
|
|
9
|
+
import { LicenseObject } from "../openapi/types";
|
|
10
10
|
|
|
11
11
|
export function createLicense(license: LicenseObject) {
|
|
12
12
|
if (!license || !Object.keys(license).length) return "";
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { LogoObject } from "../openapi/types";
|
|
9
8
|
import { create, guard } from "./utils";
|
|
9
|
+
import { LogoObject } from "../openapi/types";
|
|
10
10
|
|
|
11
11
|
export function createLogo(
|
|
12
12
|
logo: LogoObject | undefined,
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { ApiItem } from "../types";
|
|
9
8
|
import { createDetails } from "./createDetails";
|
|
10
9
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
11
10
|
import { create } from "./utils";
|
|
11
|
+
import { ApiItem } from "../types";
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
14
|
parameters: ApiItem["parameters"];
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { MediaTypeObject } from "../openapi/types";
|
|
9
8
|
import { createRequestSchema } from "./createRequestSchema";
|
|
9
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
title: string;
|
|
@@ -19,6 +19,6 @@ interface Props {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function createRequestBodyDetails({ title, body }: Props)
|
|
22
|
+
export function createRequestBodyDetails({ title, body }: Props) {
|
|
23
23
|
return createRequestSchema({ title, body });
|
|
24
24
|
}
|
|
@@ -5,6 +5,20 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
import { create } from "./utils";
|
|
9
|
+
|
|
8
10
|
export function createRequestHeader(header: string) {
|
|
9
|
-
return
|
|
11
|
+
return [
|
|
12
|
+
create(
|
|
13
|
+
"Heading",
|
|
14
|
+
{
|
|
15
|
+
children: header,
|
|
16
|
+
id: header.replace(" ", "-").toLowerCase(),
|
|
17
|
+
as: "h2",
|
|
18
|
+
className: "openapi-tabs__heading",
|
|
19
|
+
},
|
|
20
|
+
{ inline: true }
|
|
21
|
+
),
|
|
22
|
+
`\n\n`,
|
|
23
|
+
];
|
|
10
24
|
}
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { MediaTypeObject } from "../openapi/types";
|
|
9
8
|
import { createDescription } from "./createDescription";
|
|
10
9
|
import { createDetails } from "./createDetails";
|
|
11
10
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
12
11
|
import { createNodes } from "./createSchema";
|
|
13
12
|
import { create, guard } from "./utils";
|
|
13
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
14
14
|
|
|
15
15
|
interface Props {
|
|
16
16
|
style?: any;
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { MediaTypeObject } from "../openapi/types";
|
|
9
8
|
import { createDescription } from "./createDescription";
|
|
10
9
|
import { createDetails } from "./createDetails";
|
|
11
10
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
@@ -16,6 +15,7 @@ import {
|
|
|
16
15
|
createResponseExamples,
|
|
17
16
|
} from "./createStatusCodes";
|
|
18
17
|
import { create, guard } from "./utils";
|
|
18
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
19
19
|
|
|
20
20
|
interface Props {
|
|
21
21
|
style?: any;
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import * as prettier from "prettier";
|
|
9
9
|
|
|
10
|
-
import { SchemaObject } from "../openapi/types";
|
|
11
10
|
import { createNodes } from "./createSchema";
|
|
11
|
+
import { SchemaObject } from "../openapi/types";
|
|
12
12
|
|
|
13
13
|
describe("createNodes", () => {
|
|
14
|
-
it("should create readable MODs for oneOf primitive properties", () => {
|
|
14
|
+
it("should create readable MODs for oneOf primitive properties", async () => {
|
|
15
15
|
const schema: SchemaObject = {
|
|
16
16
|
type: "object",
|
|
17
17
|
properties: {
|
|
@@ -48,8 +48,10 @@ describe("createNodes", () => {
|
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
50
|
expect(
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
await Promise.all(
|
|
52
|
+
createNodes(schema, "request").map(
|
|
53
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
54
|
+
)
|
|
53
55
|
)
|
|
54
56
|
).toMatchSnapshot();
|
|
55
57
|
});
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
import clsx from "clsx";
|
|
9
9
|
|
|
10
|
-
import { SchemaObject } from "../openapi/types";
|
|
11
10
|
import {
|
|
12
11
|
createClosingArrayBracket,
|
|
13
12
|
createOpeningArrayBracket,
|
|
@@ -17,6 +16,7 @@ import { createDetails } from "./createDetails";
|
|
|
17
16
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
18
17
|
import { getQualifierMessage, getSchemaName } from "./schema";
|
|
19
18
|
import { create, guard } from "./utils";
|
|
19
|
+
import { SchemaObject } from "../openapi/types";
|
|
20
20
|
|
|
21
21
|
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
22
22
|
|
|
@@ -44,7 +44,7 @@ export function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
44
44
|
ignoreAdditionalProperties: true,
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
const
|
|
47
|
+
const mergedRequired = allOf.reduce((acc, cur) => {
|
|
48
48
|
if (Array.isArray(cur.required)) {
|
|
49
49
|
const next = [...acc, ...cur.required];
|
|
50
50
|
return next;
|
|
@@ -52,7 +52,7 @@ export function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
52
52
|
return acc;
|
|
53
53
|
}, [] as any);
|
|
54
54
|
|
|
55
|
-
return { mergedSchemas,
|
|
55
|
+
return { mergedSchemas, mergedRequired };
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -260,9 +260,8 @@ function createItems(schema: SchemaObject) {
|
|
|
260
260
|
// TODO: figure out if and how we should pass merged required array
|
|
261
261
|
const {
|
|
262
262
|
mergedSchemas,
|
|
263
|
-
}: { mergedSchemas: SchemaObject;
|
|
264
|
-
schema.items?.allOf
|
|
265
|
-
);
|
|
263
|
+
}: { mergedSchemas: SchemaObject; mergedRequired: string[] | boolean } =
|
|
264
|
+
mergeAllOf(schema.items?.allOf);
|
|
266
265
|
|
|
267
266
|
// Handles combo anyOf/oneOf + properties
|
|
268
267
|
if (
|
|
@@ -596,7 +595,6 @@ function createEdges({
|
|
|
596
595
|
discriminator,
|
|
597
596
|
}: EdgeProps): any {
|
|
598
597
|
const schemaName = getSchemaName(schema);
|
|
599
|
-
|
|
600
598
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
601
599
|
return createPropertyDiscriminator(
|
|
602
600
|
name,
|
|
@@ -618,13 +616,10 @@ function createEdges({
|
|
|
618
616
|
}
|
|
619
617
|
|
|
620
618
|
if (schema.allOf !== undefined) {
|
|
621
|
-
const {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}: { mergedSchemas: SchemaObject; required: string[] | boolean } =
|
|
625
|
-
mergeAllOf(schema.allOf);
|
|
619
|
+
const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
620
|
+
schema.allOf
|
|
621
|
+
);
|
|
626
622
|
const mergedSchemaName = getSchemaName(mergedSchemas);
|
|
627
|
-
|
|
628
623
|
if (
|
|
629
624
|
mergedSchemas.oneOf !== undefined ||
|
|
630
625
|
mergedSchemas.anyOf !== undefined
|
|
@@ -685,8 +680,8 @@ function createEdges({
|
|
|
685
680
|
collapsible: false,
|
|
686
681
|
name,
|
|
687
682
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
688
|
-
schemaName:
|
|
689
|
-
qualifierMessage: getQualifierMessage(
|
|
683
|
+
schemaName: mergedSchemaName,
|
|
684
|
+
qualifierMessage: getQualifierMessage(mergedSchemas),
|
|
690
685
|
schema: mergedSchemas,
|
|
691
686
|
});
|
|
692
687
|
}
|
|
@@ -817,9 +812,18 @@ export function createNodes(
|
|
|
817
812
|
style: {
|
|
818
813
|
marginTop: ".5rem",
|
|
819
814
|
marginBottom: ".5rem",
|
|
820
|
-
marginLeft: "1rem",
|
|
821
815
|
},
|
|
822
|
-
children:
|
|
816
|
+
children: [
|
|
817
|
+
createDescription(schema.type),
|
|
818
|
+
guard(getQualifierMessage(schema), (message) =>
|
|
819
|
+
create("div", {
|
|
820
|
+
style: {
|
|
821
|
+
paddingTop: "1rem",
|
|
822
|
+
},
|
|
823
|
+
children: createDescription(message),
|
|
824
|
+
})
|
|
825
|
+
),
|
|
826
|
+
],
|
|
823
827
|
});
|
|
824
828
|
}
|
|
825
829
|
|
|
@@ -829,9 +833,18 @@ export function createNodes(
|
|
|
829
833
|
style: {
|
|
830
834
|
marginTop: ".5rem",
|
|
831
835
|
marginBottom: ".5rem",
|
|
832
|
-
marginLeft: "1rem",
|
|
833
836
|
},
|
|
834
|
-
children: [
|
|
837
|
+
children: [
|
|
838
|
+
createDescription(schema),
|
|
839
|
+
guard(getQualifierMessage(schema), (message) =>
|
|
840
|
+
create("div", {
|
|
841
|
+
style: {
|
|
842
|
+
paddingTop: "1rem",
|
|
843
|
+
},
|
|
844
|
+
children: createDescription(message),
|
|
845
|
+
})
|
|
846
|
+
),
|
|
847
|
+
],
|
|
835
848
|
});
|
|
836
849
|
}
|
|
837
850
|
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
import format from "xml-formatter";
|
|
9
9
|
|
|
10
|
-
import { sampleResponseFromSchema } from "../openapi/createResponseExample";
|
|
11
|
-
import { ApiItem } from "../types";
|
|
12
10
|
import { createDescription } from "./createDescription";
|
|
13
11
|
import { createDetails } from "./createDetails";
|
|
14
12
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
15
13
|
import { createResponseSchema } from "./createResponseSchema";
|
|
16
14
|
import { create } from "./utils";
|
|
17
15
|
import { guard } from "./utils";
|
|
16
|
+
import { sampleResponseFromSchema } from "../openapi/createResponseExample";
|
|
17
|
+
import { ApiItem } from "../types";
|
|
18
18
|
|
|
19
19
|
export default function json2xml(o: any, tab: any) {
|
|
20
20
|
var toXml = function (v: any, name: string, ind: any) {
|
|
@@ -54,6 +54,8 @@ export default function json2xml(o: any, tab: any) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
interface Props {
|
|
57
|
+
id?: string;
|
|
58
|
+
label?: string;
|
|
57
59
|
responses: ApiItem["responses"];
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -125,7 +127,7 @@ export function createResponseExamples(
|
|
|
125
127
|
value: `${exampleName}`,
|
|
126
128
|
children: [
|
|
127
129
|
guard(exampleValue.summary, (summary) => [
|
|
128
|
-
create("
|
|
130
|
+
create("Markdown", {
|
|
129
131
|
children: ` ${summary}`,
|
|
130
132
|
}),
|
|
131
133
|
]),
|
|
@@ -141,7 +143,7 @@ export function createResponseExamples(
|
|
|
141
143
|
value: `${exampleName}`,
|
|
142
144
|
children: [
|
|
143
145
|
guard(exampleValue.summary, (summary) => [
|
|
144
|
-
create("
|
|
146
|
+
create("Markdown", {
|
|
145
147
|
children: ` ${summary}`,
|
|
146
148
|
}),
|
|
147
149
|
]),
|
|
@@ -169,7 +171,7 @@ export function createResponseExample(responseExample: any, mimeType: string) {
|
|
|
169
171
|
value: `Example`,
|
|
170
172
|
children: [
|
|
171
173
|
guard(responseExample.summary, (summary) => [
|
|
172
|
-
create("
|
|
174
|
+
create("Markdown", {
|
|
173
175
|
children: ` ${summary}`,
|
|
174
176
|
}),
|
|
175
177
|
]),
|
|
@@ -185,7 +187,7 @@ export function createResponseExample(responseExample: any, mimeType: string) {
|
|
|
185
187
|
value: `Example`,
|
|
186
188
|
children: [
|
|
187
189
|
guard(responseExample.summary, (summary) => [
|
|
188
|
-
create("
|
|
190
|
+
create("Markdown", {
|
|
189
191
|
children: ` ${summary}`,
|
|
190
192
|
}),
|
|
191
193
|
]),
|
|
@@ -254,7 +256,7 @@ export function createExampleFromSchema(schema: any, mimeType: string) {
|
|
|
254
256
|
return undefined;
|
|
255
257
|
}
|
|
256
258
|
|
|
257
|
-
export function createStatusCodes({ responses }: Props) {
|
|
259
|
+
export function createStatusCodes({ label, id, responses }: Props) {
|
|
258
260
|
if (responses === undefined) {
|
|
259
261
|
return undefined;
|
|
260
262
|
}
|
|
@@ -269,6 +271,8 @@ export function createStatusCodes({ responses }: Props) {
|
|
|
269
271
|
create("div", {
|
|
270
272
|
children: [
|
|
271
273
|
create("ApiTabs", {
|
|
274
|
+
label,
|
|
275
|
+
id,
|
|
272
276
|
children: codes.map((code) => {
|
|
273
277
|
const responseHeaders: any = responses[code].headers;
|
|
274
278
|
return create("TabItem", {
|
|
@@ -9,10 +9,14 @@ import { create, guard } from "./utils";
|
|
|
9
9
|
|
|
10
10
|
export function createVersionBadge(version: string | undefined) {
|
|
11
11
|
return guard(version, (version) => [
|
|
12
|
-
create(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
create(
|
|
13
|
+
"span",
|
|
14
|
+
{
|
|
15
|
+
className: "theme-doc-version-badge badge badge--secondary",
|
|
16
|
+
children: `Version: ${escape(version)}`,
|
|
17
|
+
},
|
|
18
|
+
{ inline: true }
|
|
19
|
+
),
|
|
16
20
|
`\n\n`,
|
|
17
21
|
]);
|
|
18
22
|
}
|
package/src/markdown/index.ts
CHANGED
|
@@ -5,15 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
ContactObject,
|
|
10
|
-
LicenseObject,
|
|
11
|
-
MediaTypeObject,
|
|
12
|
-
SecuritySchemeObject,
|
|
13
|
-
} from "../openapi/types";
|
|
14
|
-
import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
|
|
15
8
|
import { createAuthentication } from "./createAuthentication";
|
|
16
9
|
import { createAuthorization } from "./createAuthorization";
|
|
10
|
+
import { createCallbacks } from "./createCallbacks";
|
|
17
11
|
import { createContactInfo } from "./createContactInfo";
|
|
18
12
|
import { createDeprecationNotice } from "./createDeprecationNotice";
|
|
19
13
|
import { createDescription } from "./createDescription";
|
|
@@ -25,13 +19,26 @@ import { createMethodEndpoint } from "./createMethodEndpoint";
|
|
|
25
19
|
import { createParamsDetails } from "./createParamsDetails";
|
|
26
20
|
import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
27
21
|
import { createRequestHeader } from "./createRequestHeader";
|
|
22
|
+
import { createNodes } from "./createSchema";
|
|
28
23
|
import { createStatusCodes } from "./createStatusCodes";
|
|
29
24
|
import { createTermsOfService } from "./createTermsOfService";
|
|
30
25
|
import { createVendorExtensions } from "./createVendorExtensions";
|
|
31
26
|
import { createVersionBadge } from "./createVersionBadge";
|
|
32
|
-
import { greaterThan, lessThan, render } from "./utils";
|
|
27
|
+
import { create, greaterThan, lessThan, render } from "./utils";
|
|
28
|
+
import {
|
|
29
|
+
ContactObject,
|
|
30
|
+
LicenseObject,
|
|
31
|
+
MediaTypeObject,
|
|
32
|
+
SecuritySchemeObject,
|
|
33
|
+
} from "../openapi/types";
|
|
34
|
+
import {
|
|
35
|
+
ApiPageMetadata,
|
|
36
|
+
InfoPageMetadata,
|
|
37
|
+
SchemaPageMetadata,
|
|
38
|
+
TagPageMetadata,
|
|
39
|
+
} from "../types";
|
|
33
40
|
|
|
34
|
-
interface
|
|
41
|
+
interface RequestBodyProps {
|
|
35
42
|
title: string;
|
|
36
43
|
body: {
|
|
37
44
|
content?: {
|
|
@@ -54,6 +61,7 @@ export function createApiPageMD({
|
|
|
54
61
|
parameters,
|
|
55
62
|
requestBody,
|
|
56
63
|
responses,
|
|
64
|
+
callbacks,
|
|
57
65
|
},
|
|
58
66
|
infoPath,
|
|
59
67
|
frontMatter,
|
|
@@ -68,14 +76,19 @@ export function createApiPageMD({
|
|
|
68
76
|
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
69
77
|
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
70
78
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
79
|
+
`import Markdown from "@theme/Markdown";\n`,
|
|
80
|
+
`import Heading from "@theme/Heading";\n`,
|
|
81
|
+
`import OperationTabs from "@theme/OperationTabs";\n`,
|
|
71
82
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
72
|
-
createHeading(title
|
|
83
|
+
createHeading(title),
|
|
73
84
|
createMethodEndpoint(method, path),
|
|
74
85
|
infoPath && createAuthorization(infoPath),
|
|
75
|
-
frontMatter.show_extensions
|
|
86
|
+
frontMatter.show_extensions
|
|
87
|
+
? createVendorExtensions(extensions)
|
|
88
|
+
: undefined,
|
|
76
89
|
createDeprecationNotice({ deprecated, description: deprecatedDescription }),
|
|
77
90
|
createDescription(description),
|
|
78
|
-
createRequestHeader("Request"),
|
|
91
|
+
requestBody || parameters ? createRequestHeader("Request") : undefined,
|
|
79
92
|
createParamsDetails({ parameters, type: "path" }),
|
|
80
93
|
createParamsDetails({ parameters, type: "query" }),
|
|
81
94
|
createParamsDetails({ parameters, type: "header" }),
|
|
@@ -83,8 +96,9 @@ export function createApiPageMD({
|
|
|
83
96
|
createRequestBodyDetails({
|
|
84
97
|
title: "Body",
|
|
85
98
|
body: requestBody,
|
|
86
|
-
} as
|
|
99
|
+
} as RequestBodyProps),
|
|
87
100
|
createStatusCodes({ responses }),
|
|
101
|
+
createCallbacks({ callbacks }),
|
|
88
102
|
]);
|
|
89
103
|
}
|
|
90
104
|
|
|
@@ -104,13 +118,14 @@ export function createInfoPageMD({
|
|
|
104
118
|
}: InfoPageMetadata) {
|
|
105
119
|
return render([
|
|
106
120
|
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
121
|
+
`import Heading from "@theme/Heading";\n`,
|
|
107
122
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
108
123
|
`import TabItem from "@theme/TabItem";\n`,
|
|
109
124
|
`import Export from "@theme/ApiExplorer/Export";\n\n`,
|
|
110
125
|
|
|
111
126
|
createVersionBadge(version),
|
|
112
127
|
createDownload(downloadUrl),
|
|
113
|
-
createHeading(title
|
|
128
|
+
createHeading(title),
|
|
114
129
|
createLogo(logo, darkLogo),
|
|
115
130
|
createDescription(description),
|
|
116
131
|
createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
|
|
@@ -123,3 +138,19 @@ export function createInfoPageMD({
|
|
|
123
138
|
export function createTagPageMD({ tag: { description } }: TagPageMetadata) {
|
|
124
139
|
return render([createDescription(description)]);
|
|
125
140
|
}
|
|
141
|
+
|
|
142
|
+
export function createSchemaPageMD({ schema }: SchemaPageMetadata) {
|
|
143
|
+
const { title = "", description } = schema;
|
|
144
|
+
return render([
|
|
145
|
+
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
146
|
+
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
147
|
+
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
148
|
+
`import Heading from "@theme/Heading";\n`,
|
|
149
|
+
`import TabItem from "@theme/TabItem";\n\n`,
|
|
150
|
+
createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
|
|
151
|
+
createDescription(description),
|
|
152
|
+
create("ul", {
|
|
153
|
+
children: createNodes(schema, "response"),
|
|
154
|
+
}),
|
|
155
|
+
]);
|
|
156
|
+
}
|
package/src/markdown/schema.ts
CHANGED
package/src/markdown/utils.ts
CHANGED
|
@@ -9,16 +9,27 @@ export type Children = string | undefined | (string | string[] | undefined)[];
|
|
|
9
9
|
|
|
10
10
|
export type Props = Record<string, any> & { children?: Children };
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export type Options = { inline?: boolean };
|
|
13
|
+
|
|
14
|
+
export function create(
|
|
15
|
+
tag: string,
|
|
16
|
+
props: Props,
|
|
17
|
+
options: Options = {}
|
|
18
|
+
): string {
|
|
13
19
|
const { children, ...rest } = props;
|
|
14
20
|
|
|
15
21
|
let propString = "";
|
|
16
22
|
for (const [key, value] of Object.entries(rest)) {
|
|
17
23
|
propString += `\n ${key}={${JSON.stringify(value)}}`;
|
|
18
24
|
}
|
|
19
|
-
propString += propString ? "\n" : "";
|
|
20
|
-
|
|
21
25
|
let indentedChildren = render(children).replace(/^/gm, " ");
|
|
26
|
+
|
|
27
|
+
if (options.inline) {
|
|
28
|
+
propString += `\n children={${JSON.stringify(children)}}`;
|
|
29
|
+
indentedChildren = "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
propString += propString ? "\n" : "";
|
|
22
33
|
indentedChildren += indentedChildren ? "\n" : "";
|
|
23
34
|
return `<${tag}${propString}>\n${indentedChildren}</${tag}>`;
|
|
24
35
|
}
|
|
@@ -27,7 +38,7 @@ export function guard<T>(
|
|
|
27
38
|
value: T | undefined,
|
|
28
39
|
cb: (value: T) => Children
|
|
29
40
|
): string {
|
|
30
|
-
if (!!value) {
|
|
41
|
+
if (!!value || value === 0) {
|
|
31
42
|
const children = cb(value);
|
|
32
43
|
return render(children);
|
|
33
44
|
}
|
|
@@ -50,3 +61,25 @@ export const lessThan =
|
|
|
50
61
|
export const greaterThan =
|
|
51
62
|
/(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|bold|a|li|ol|ul|img|svg|div|center|\/|\s|"|'))>/gu;
|
|
52
63
|
export const codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
64
|
+
export const curlyBrackets = /([{|}])/g;
|
|
65
|
+
export const codeBlock = /(^```.*[\s\S]*?```$|`[^`].+?`)/gm;
|
|
66
|
+
|
|
67
|
+
export function clean(value: string | undefined): string {
|
|
68
|
+
if (!value) {
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let sections = value.split(codeBlock);
|
|
73
|
+
for (let sectionIndex in sections) {
|
|
74
|
+
if (!sections[sectionIndex].startsWith("`")) {
|
|
75
|
+
sections[sectionIndex] = sections[sectionIndex]
|
|
76
|
+
.replace(lessThan, "<")
|
|
77
|
+
.replace(greaterThan, ">")
|
|
78
|
+
.replace(codeFence, function (match) {
|
|
79
|
+
return match.replace(/\\>/g, ">");
|
|
80
|
+
})
|
|
81
|
+
.replace(curlyBrackets, "\\$1");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return sections.join("");
|
|
85
|
+
}
|
|
@@ -11,3 +11,32 @@ paths:
|
|
|
11
11
|
responses:
|
|
12
12
|
200:
|
|
13
13
|
description: OK
|
|
14
|
+
|
|
15
|
+
tags:
|
|
16
|
+
- name: tag1
|
|
17
|
+
description: Everything about your Pets
|
|
18
|
+
x-displayName: Tag 1
|
|
19
|
+
- name: tag2
|
|
20
|
+
description: Tag 2 description
|
|
21
|
+
x-displayName: Tag 2
|
|
22
|
+
- name: tag3
|
|
23
|
+
description: Tag 3 description
|
|
24
|
+
x-displayName: Tag 3
|
|
25
|
+
- name: tag4
|
|
26
|
+
description: Tag 4 description
|
|
27
|
+
x-displayName: Tag 4
|
|
28
|
+
|
|
29
|
+
x-tagGroups:
|
|
30
|
+
- name: Tag 1 & 2
|
|
31
|
+
tags:
|
|
32
|
+
- tag1
|
|
33
|
+
- tag2
|
|
34
|
+
- name: Trinity
|
|
35
|
+
tags:
|
|
36
|
+
- tag1
|
|
37
|
+
- tag2
|
|
38
|
+
- tag3
|
|
39
|
+
- name: Last Two
|
|
40
|
+
tags:
|
|
41
|
+
- tag3
|
|
42
|
+
- tag4
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
import chalk from "chalk";
|
|
9
9
|
import merge from "lodash/merge";
|
|
10
10
|
|
|
11
|
-
import { mergeAllOf } from "../markdown/createSchema";
|
|
12
11
|
import { SchemaObject } from "./types";
|
|
12
|
+
import { mergeAllOf } from "../markdown/createSchema";
|
|
13
13
|
|
|
14
14
|
interface OASTypeToTypeMap {
|
|
15
15
|
string: string;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
import chalk from "chalk";
|
|
9
9
|
import merge from "lodash/merge";
|
|
10
10
|
|
|
11
|
-
import { mergeAllOf } from "../markdown/createSchema";
|
|
12
11
|
import { SchemaObject } from "./types";
|
|
12
|
+
import { mergeAllOf } from "../markdown/createSchema";
|
|
13
13
|
|
|
14
14
|
interface OASTypeToTypeMap {
|
|
15
15
|
string: string;
|