docusaurus-plugin-openapi-docs 0.0.0-362 → 0.0.0-367
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/lib/index.d.ts +1 -0
- package/lib/index.js +13 -1
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +139 -0
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +5 -1
- package/lib/openapi/openapi.js +38 -34
- package/lib/openapi/openapi.test.js +0 -6
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +3 -0
- package/lib/openapi/utils/loadAndBundleSpec.js +44 -0
- package/lib/openapi/utils/types.d.ts +306 -0
- package/lib/openapi/utils/types.js +8 -0
- package/lib/types.d.ts +5 -0
- package/package.json +4 -2
- package/src/index.ts +12 -1
- package/src/markdown/createAuthentication.ts +160 -0
- package/src/markdown/index.ts +10 -1
- package/src/openapi/openapi.test.ts +0 -6
- package/src/openapi/openapi.ts +37 -31
- package/src/openapi/utils/loadAndBundleSpec.ts +62 -0
- package/src/openapi/utils/types.ts +303 -0
- package/src/types.ts +5 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +0 -4
- package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +0 -13
- package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +0 -13
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
2
|
+
export interface OpenAPISpec {
|
|
3
|
+
openapi: string;
|
|
4
|
+
info: OpenAPIInfo;
|
|
5
|
+
servers?: OpenAPIServer[];
|
|
6
|
+
paths: OpenAPIPaths;
|
|
7
|
+
components?: OpenAPIComponents;
|
|
8
|
+
security?: OpenAPISecurityRequirement[];
|
|
9
|
+
tags?: OpenAPITag[];
|
|
10
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
11
|
+
"x-webhooks"?: OpenAPIPaths;
|
|
12
|
+
webhooks?: OpenAPIPaths;
|
|
13
|
+
}
|
|
14
|
+
export interface OpenAPIInfo {
|
|
15
|
+
title: string;
|
|
16
|
+
version: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
summary?: string;
|
|
19
|
+
termsOfService?: string;
|
|
20
|
+
contact?: OpenAPIContact;
|
|
21
|
+
license?: OpenAPILicense;
|
|
22
|
+
}
|
|
23
|
+
export interface OpenAPIServer {
|
|
24
|
+
url: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
variables?: {
|
|
27
|
+
[name: string]: OpenAPIServerVariable;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface OpenAPIServerVariable {
|
|
31
|
+
enum?: string[];
|
|
32
|
+
default: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface OpenAPIPaths {
|
|
36
|
+
[path: string]: OpenAPIPath;
|
|
37
|
+
}
|
|
38
|
+
export interface OpenAPIRef {
|
|
39
|
+
$ref: string;
|
|
40
|
+
}
|
|
41
|
+
export declare type Referenced<T> = OpenAPIRef | T;
|
|
42
|
+
export interface OpenAPIPath {
|
|
43
|
+
summary?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
get?: OpenAPIOperation;
|
|
46
|
+
put?: OpenAPIOperation;
|
|
47
|
+
post?: OpenAPIOperation;
|
|
48
|
+
delete?: OpenAPIOperation;
|
|
49
|
+
options?: OpenAPIOperation;
|
|
50
|
+
head?: OpenAPIOperation;
|
|
51
|
+
patch?: OpenAPIOperation;
|
|
52
|
+
trace?: OpenAPIOperation;
|
|
53
|
+
servers?: OpenAPIServer[];
|
|
54
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
55
|
+
$ref?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface OpenAPIXCodeSample {
|
|
58
|
+
lang: string;
|
|
59
|
+
label?: string;
|
|
60
|
+
source: string;
|
|
61
|
+
}
|
|
62
|
+
export interface OpenAPIOperation {
|
|
63
|
+
tags?: string[];
|
|
64
|
+
summary?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
67
|
+
operationId?: string;
|
|
68
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
69
|
+
requestBody?: Referenced<OpenAPIRequestBody>;
|
|
70
|
+
responses: OpenAPIResponses;
|
|
71
|
+
callbacks?: {
|
|
72
|
+
[name: string]: Referenced<OpenAPICallback>;
|
|
73
|
+
};
|
|
74
|
+
deprecated?: boolean;
|
|
75
|
+
security?: OpenAPISecurityRequirement[];
|
|
76
|
+
servers?: OpenAPIServer[];
|
|
77
|
+
"x-codeSamples"?: OpenAPIXCodeSample[];
|
|
78
|
+
"x-code-samples"?: OpenAPIXCodeSample[];
|
|
79
|
+
}
|
|
80
|
+
export interface OpenAPIParameter {
|
|
81
|
+
name: string;
|
|
82
|
+
in?: OpenAPIParameterLocation;
|
|
83
|
+
description?: string;
|
|
84
|
+
required?: boolean;
|
|
85
|
+
deprecated?: boolean;
|
|
86
|
+
allowEmptyValue?: boolean;
|
|
87
|
+
style?: OpenAPIParameterStyle;
|
|
88
|
+
explode?: boolean;
|
|
89
|
+
allowReserved?: boolean;
|
|
90
|
+
schema?: Referenced<OpenAPISchema>;
|
|
91
|
+
example?: any;
|
|
92
|
+
examples?: {
|
|
93
|
+
[media: string]: Referenced<OpenAPIExample>;
|
|
94
|
+
};
|
|
95
|
+
content?: {
|
|
96
|
+
[media: string]: OpenAPIMediaType;
|
|
97
|
+
};
|
|
98
|
+
encoding?: Record<string, OpenAPIEncoding>;
|
|
99
|
+
const?: any;
|
|
100
|
+
}
|
|
101
|
+
export interface OpenAPIExample {
|
|
102
|
+
value: any;
|
|
103
|
+
summary?: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
externalValue?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface OpenAPISchema {
|
|
108
|
+
$ref?: string;
|
|
109
|
+
type?: string | string[];
|
|
110
|
+
properties?: {
|
|
111
|
+
[name: string]: OpenAPISchema;
|
|
112
|
+
};
|
|
113
|
+
patternProperties?: {
|
|
114
|
+
[name: string]: OpenAPISchema;
|
|
115
|
+
};
|
|
116
|
+
additionalProperties?: boolean | OpenAPISchema;
|
|
117
|
+
unevaluatedProperties?: boolean | OpenAPISchema;
|
|
118
|
+
description?: string;
|
|
119
|
+
default?: any;
|
|
120
|
+
items?: OpenAPISchema | OpenAPISchema[] | boolean;
|
|
121
|
+
required?: string[];
|
|
122
|
+
readOnly?: boolean;
|
|
123
|
+
writeOnly?: boolean;
|
|
124
|
+
deprecated?: boolean;
|
|
125
|
+
format?: string;
|
|
126
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
127
|
+
discriminator?: OpenAPIDiscriminator;
|
|
128
|
+
nullable?: boolean;
|
|
129
|
+
oneOf?: OpenAPISchema[];
|
|
130
|
+
anyOf?: OpenAPISchema[];
|
|
131
|
+
allOf?: OpenAPISchema[];
|
|
132
|
+
not?: OpenAPISchema;
|
|
133
|
+
title?: string;
|
|
134
|
+
multipleOf?: number;
|
|
135
|
+
maximum?: number;
|
|
136
|
+
exclusiveMaximum?: boolean | number;
|
|
137
|
+
minimum?: number;
|
|
138
|
+
exclusiveMinimum?: boolean | number;
|
|
139
|
+
maxLength?: number;
|
|
140
|
+
minLength?: number;
|
|
141
|
+
pattern?: string;
|
|
142
|
+
maxItems?: number;
|
|
143
|
+
minItems?: number;
|
|
144
|
+
uniqueItems?: boolean;
|
|
145
|
+
maxProperties?: number;
|
|
146
|
+
minProperties?: number;
|
|
147
|
+
enum?: any[];
|
|
148
|
+
example?: any;
|
|
149
|
+
if?: OpenAPISchema;
|
|
150
|
+
else?: OpenAPISchema;
|
|
151
|
+
then?: OpenAPISchema;
|
|
152
|
+
examples?: any[];
|
|
153
|
+
const?: string;
|
|
154
|
+
contentEncoding?: string;
|
|
155
|
+
contentMediaType?: string;
|
|
156
|
+
prefixItems?: OpenAPISchema[];
|
|
157
|
+
additionalItems?: OpenAPISchema | boolean;
|
|
158
|
+
}
|
|
159
|
+
export interface OpenAPIDiscriminator {
|
|
160
|
+
propertyName: string;
|
|
161
|
+
mapping?: {
|
|
162
|
+
[name: string]: string;
|
|
163
|
+
};
|
|
164
|
+
"x-explicitMappingOnly"?: boolean;
|
|
165
|
+
}
|
|
166
|
+
export interface OpenAPIMediaType {
|
|
167
|
+
schema?: Referenced<OpenAPISchema>;
|
|
168
|
+
example?: any;
|
|
169
|
+
examples?: {
|
|
170
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
171
|
+
};
|
|
172
|
+
encoding?: {
|
|
173
|
+
[field: string]: OpenAPIEncoding;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export interface OpenAPIEncoding {
|
|
177
|
+
contentType: string;
|
|
178
|
+
headers?: {
|
|
179
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
180
|
+
};
|
|
181
|
+
style: OpenAPIParameterStyle;
|
|
182
|
+
explode: boolean;
|
|
183
|
+
allowReserved: boolean;
|
|
184
|
+
}
|
|
185
|
+
export declare type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
|
|
186
|
+
export declare type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
|
|
187
|
+
export interface OpenAPIRequestBody {
|
|
188
|
+
description?: string;
|
|
189
|
+
required?: boolean;
|
|
190
|
+
content: {
|
|
191
|
+
[mime: string]: OpenAPIMediaType;
|
|
192
|
+
};
|
|
193
|
+
"x-examples"?: {
|
|
194
|
+
[mime: string]: {
|
|
195
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
"x-example"?: {
|
|
199
|
+
[mime: string]: any;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export interface OpenAPIResponses {
|
|
203
|
+
[code: string]: Referenced<OpenAPIResponse>;
|
|
204
|
+
}
|
|
205
|
+
export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description" | "x-examples" | "x-example"> {
|
|
206
|
+
headers?: {
|
|
207
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
208
|
+
};
|
|
209
|
+
links?: {
|
|
210
|
+
[name: string]: Referenced<OpenAPILink>;
|
|
211
|
+
};
|
|
212
|
+
content?: {
|
|
213
|
+
[mime: string]: OpenAPIMediaType;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export interface OpenAPILink {
|
|
217
|
+
$ref?: string;
|
|
218
|
+
}
|
|
219
|
+
export declare type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
|
|
220
|
+
export interface OpenAPICallback {
|
|
221
|
+
[name: string]: OpenAPIPath;
|
|
222
|
+
}
|
|
223
|
+
export interface OpenAPIComponents {
|
|
224
|
+
schemas?: {
|
|
225
|
+
[name: string]: Referenced<OpenAPISchema>;
|
|
226
|
+
};
|
|
227
|
+
responses?: {
|
|
228
|
+
[name: string]: Referenced<OpenAPIResponse>;
|
|
229
|
+
};
|
|
230
|
+
parameters?: {
|
|
231
|
+
[name: string]: Referenced<OpenAPIParameter>;
|
|
232
|
+
};
|
|
233
|
+
examples?: {
|
|
234
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
235
|
+
};
|
|
236
|
+
requestBodies?: {
|
|
237
|
+
[name: string]: Referenced<OpenAPIRequestBody>;
|
|
238
|
+
};
|
|
239
|
+
headers?: {
|
|
240
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
241
|
+
};
|
|
242
|
+
securitySchemes?: {
|
|
243
|
+
[name: string]: Referenced<OpenAPISecurityScheme>;
|
|
244
|
+
};
|
|
245
|
+
links?: {
|
|
246
|
+
[name: string]: Referenced<OpenAPILink>;
|
|
247
|
+
};
|
|
248
|
+
callbacks?: {
|
|
249
|
+
[name: string]: Referenced<OpenAPICallback>;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export interface OpenAPISecurityRequirement {
|
|
253
|
+
[name: string]: string[];
|
|
254
|
+
}
|
|
255
|
+
export interface OpenAPISecurityScheme {
|
|
256
|
+
type: "apiKey" | "http" | "oauth2" | "openIdConnect";
|
|
257
|
+
description?: string;
|
|
258
|
+
name?: string;
|
|
259
|
+
in?: "query" | "header" | "cookie";
|
|
260
|
+
scheme?: string;
|
|
261
|
+
bearerFormat: string;
|
|
262
|
+
flows: {
|
|
263
|
+
implicit?: {
|
|
264
|
+
refreshUrl?: string;
|
|
265
|
+
scopes: Record<string, string>;
|
|
266
|
+
authorizationUrl: string;
|
|
267
|
+
};
|
|
268
|
+
password?: {
|
|
269
|
+
refreshUrl?: string;
|
|
270
|
+
scopes: Record<string, string>;
|
|
271
|
+
tokenUrl: string;
|
|
272
|
+
};
|
|
273
|
+
clientCredentials?: {
|
|
274
|
+
refreshUrl?: string;
|
|
275
|
+
scopes: Record<string, string>;
|
|
276
|
+
tokenUrl: string;
|
|
277
|
+
};
|
|
278
|
+
authorizationCode?: {
|
|
279
|
+
refreshUrl?: string;
|
|
280
|
+
scopes: Record<string, string>;
|
|
281
|
+
tokenUrl: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
openIdConnectUrl?: string;
|
|
285
|
+
}
|
|
286
|
+
export interface OpenAPITag {
|
|
287
|
+
name: string;
|
|
288
|
+
description?: string;
|
|
289
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
290
|
+
"x-displayName"?: string;
|
|
291
|
+
}
|
|
292
|
+
export interface OpenAPIExternalDocumentation {
|
|
293
|
+
description?: string;
|
|
294
|
+
url: string;
|
|
295
|
+
}
|
|
296
|
+
export interface OpenAPIContact {
|
|
297
|
+
name?: string;
|
|
298
|
+
url?: string;
|
|
299
|
+
email?: string;
|
|
300
|
+
}
|
|
301
|
+
export interface OpenAPILicense {
|
|
302
|
+
name: string;
|
|
303
|
+
url?: string;
|
|
304
|
+
identifier?: string;
|
|
305
|
+
}
|
|
306
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/types.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface ApiMetadataBase {
|
|
|
23
23
|
next?: ApiNavLink;
|
|
24
24
|
id: string;
|
|
25
25
|
unversionedId: string;
|
|
26
|
+
infoId?: string;
|
|
27
|
+
infoPath?: string;
|
|
26
28
|
title: string;
|
|
27
29
|
description: string;
|
|
28
30
|
source: string;
|
|
@@ -52,6 +54,9 @@ export interface InfoPageMetadata extends ApiMetadataBase {
|
|
|
52
54
|
type: "info";
|
|
53
55
|
info: ApiInfo;
|
|
54
56
|
markdown?: string;
|
|
57
|
+
securitySchemes?: {
|
|
58
|
+
[key: string]: SecuritySchemeObject;
|
|
59
|
+
};
|
|
55
60
|
}
|
|
56
61
|
export interface TagPageMetadata extends ApiMetadataBase {
|
|
57
62
|
type: "tag";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-plugin-openapi-docs",
|
|
3
3
|
"description": "OpenAPI plugin for Docusaurus.",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-367",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"@docusaurus/utils-validation": "2.0.0-beta.21",
|
|
43
43
|
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
|
|
44
44
|
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
45
|
+
"@redocly/openapi-core": "^1.0.0-beta.100",
|
|
45
46
|
"@types/js-yaml": "^4.0.5",
|
|
46
47
|
"@types/mustache": "^4.1.2",
|
|
47
48
|
"chalk": "^4.1.2",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"json-schema-merge-allof": "^0.8.1",
|
|
53
54
|
"lodash": "^4.17.20",
|
|
54
55
|
"mustache": "^4.2.0",
|
|
56
|
+
"swagger2openapi": "^7.0.8",
|
|
55
57
|
"webpack": "^5.61.0"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
@@ -60,5 +62,5 @@
|
|
|
60
62
|
"engines": {
|
|
61
63
|
"node": ">=14"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "02139672e58cc0393522758aa32d072c201cad36"
|
|
64
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,10 @@ import { readOpenapiFiles, processOpenapiFiles } from "./openapi";
|
|
|
18
18
|
import generateSidebarSlice from "./sidebars";
|
|
19
19
|
import type { PluginOptions, LoadedContent, APIOptions } from "./types";
|
|
20
20
|
|
|
21
|
+
export function isURL(str: string): boolean {
|
|
22
|
+
return /^(https?:)\/\//m.test(str);
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
export default function pluginOpenAPI(
|
|
22
26
|
context: LoadContext,
|
|
23
27
|
options: PluginOptions
|
|
@@ -28,7 +32,9 @@ export default function pluginOpenAPI(
|
|
|
28
32
|
async function generateApiDocs(options: APIOptions) {
|
|
29
33
|
let { specPath, outputDir, template, sidebarOptions } = options;
|
|
30
34
|
|
|
31
|
-
const contentPath =
|
|
35
|
+
const contentPath = isURL(specPath)
|
|
36
|
+
? specPath
|
|
37
|
+
: path.resolve(siteDir, specPath);
|
|
32
38
|
|
|
33
39
|
try {
|
|
34
40
|
const openapiFiles = await readOpenapiFiles(contentPath, {});
|
|
@@ -103,6 +109,9 @@ api: {{{json}}}
|
|
|
103
109
|
{{#api.method}}
|
|
104
110
|
sidebar_class_name: "{{{api.method}}} api-method"
|
|
105
111
|
{{/api.method}}
|
|
112
|
+
{{#infoPath}}
|
|
113
|
+
info_path: {{{infoPath}}}
|
|
114
|
+
{{/infoPath}}
|
|
106
115
|
---
|
|
107
116
|
|
|
108
117
|
{{{markdown}}}
|
|
@@ -154,7 +163,9 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
154
163
|
item.markdown = markdown;
|
|
155
164
|
if (item.type === "api") {
|
|
156
165
|
item.json = JSON.stringify(item.api);
|
|
166
|
+
if (item.infoId) item.infoPath = `${outputDir}/${item.infoId}`;
|
|
157
167
|
}
|
|
168
|
+
|
|
158
169
|
const view = render(mdTemplate, item);
|
|
159
170
|
const utils = render(infoMdTemplate, item);
|
|
160
171
|
// eslint-disable-next-line testing-library/render-result-naming-convention
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { OAuthFlowObject, SecuritySchemeObject } from "../openapi/types";
|
|
9
|
+
import { createDescription } from "./createDescription";
|
|
10
|
+
import { create, guard } from "./utils";
|
|
11
|
+
|
|
12
|
+
export function createAuthentication(securitySchemes: SecuritySchemeObject) {
|
|
13
|
+
if (!securitySchemes || !Object.keys(securitySchemes).length) return "";
|
|
14
|
+
|
|
15
|
+
const createAuthenticationTable = (securityScheme: any) => {
|
|
16
|
+
const { bearerFormat, flows, name, scheme, type } = securityScheme;
|
|
17
|
+
|
|
18
|
+
const createSecuritySchemeTypeRow = () =>
|
|
19
|
+
create("tr", {
|
|
20
|
+
children: [
|
|
21
|
+
create("th", { children: "Security Scheme Type:" }),
|
|
22
|
+
create("td", { children: type }),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const createOAuthFlowRows = () => {
|
|
27
|
+
const flowRows = Object.entries(flows).map(([flowType, flowObj]) => {
|
|
28
|
+
const { authorizationUrl, tokenUrl, refreshUrl, scopes } =
|
|
29
|
+
flowObj as OAuthFlowObject;
|
|
30
|
+
|
|
31
|
+
return create("tr", {
|
|
32
|
+
children: [
|
|
33
|
+
create("th", { children: `${flowType} OAuth Flow:` }),
|
|
34
|
+
create("td", {
|
|
35
|
+
children: [
|
|
36
|
+
guard(tokenUrl, () =>
|
|
37
|
+
create("p", { children: `Token URL: ${tokenUrl}` })
|
|
38
|
+
),
|
|
39
|
+
guard(authorizationUrl, () =>
|
|
40
|
+
create("p", {
|
|
41
|
+
children: `Authorization URL: ${authorizationUrl}`,
|
|
42
|
+
})
|
|
43
|
+
),
|
|
44
|
+
guard(refreshUrl, () =>
|
|
45
|
+
create("p", { children: `Refresh URL: ${refreshUrl}` })
|
|
46
|
+
),
|
|
47
|
+
create("span", { children: "Scopes:" }),
|
|
48
|
+
create("ul", {
|
|
49
|
+
children: Object.entries(scopes).map(([scope, description]) =>
|
|
50
|
+
create("li", { children: `${scope}: ${description}` })
|
|
51
|
+
),
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return flowRows.join("");
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
switch (type) {
|
|
63
|
+
case "apiKey":
|
|
64
|
+
return create("div", {
|
|
65
|
+
children: [
|
|
66
|
+
create("table", {
|
|
67
|
+
children: create("tbody", {
|
|
68
|
+
children: [
|
|
69
|
+
createSecuritySchemeTypeRow(),
|
|
70
|
+
create("tr", {
|
|
71
|
+
children: [
|
|
72
|
+
create("th", { children: "Header parameter name:" }),
|
|
73
|
+
create("td", { children: name }),
|
|
74
|
+
],
|
|
75
|
+
}),
|
|
76
|
+
],
|
|
77
|
+
}),
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
case "http":
|
|
82
|
+
return create("div", {
|
|
83
|
+
children: [
|
|
84
|
+
create("table", {
|
|
85
|
+
children: create("tbody", {
|
|
86
|
+
children: [
|
|
87
|
+
createSecuritySchemeTypeRow(),
|
|
88
|
+
create("tr", {
|
|
89
|
+
children: [
|
|
90
|
+
create("th", { children: "HTTP Authorization Scheme:" }),
|
|
91
|
+
create("td", { children: scheme }),
|
|
92
|
+
],
|
|
93
|
+
}),
|
|
94
|
+
create("tr", {
|
|
95
|
+
children: [
|
|
96
|
+
create("th", { children: "Bearer format:" }),
|
|
97
|
+
create("td", { children: bearerFormat }),
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
case "oauth2":
|
|
106
|
+
return create("div", {
|
|
107
|
+
children: [
|
|
108
|
+
create("table", {
|
|
109
|
+
children: create("tbody", {
|
|
110
|
+
children: [
|
|
111
|
+
createSecuritySchemeTypeRow(),
|
|
112
|
+
createOAuthFlowRows(),
|
|
113
|
+
],
|
|
114
|
+
}),
|
|
115
|
+
}),
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
default:
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const formatTabLabel = (str: string) => {
|
|
124
|
+
const formattedLabel = str
|
|
125
|
+
.replace(/(_|-)/g, " ")
|
|
126
|
+
.trim()
|
|
127
|
+
.replace(/\w\S*/g, (str) => str.charAt(0).toUpperCase() + str.substr(1))
|
|
128
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
129
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1 $2");
|
|
130
|
+
|
|
131
|
+
const isOAuth = formattedLabel.toLowerCase().includes("oauth2");
|
|
132
|
+
const isApiKey = formattedLabel.toLowerCase().includes("api");
|
|
133
|
+
|
|
134
|
+
return isOAuth ? "OAuth 2.0" : isApiKey ? "API Key" : formattedLabel;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return create("div", {
|
|
138
|
+
children: [
|
|
139
|
+
create("h2", {
|
|
140
|
+
children: "Authentication",
|
|
141
|
+
id: "authentication",
|
|
142
|
+
style: { marginBottom: "1rem" },
|
|
143
|
+
}),
|
|
144
|
+
create("Tabs", {
|
|
145
|
+
children: Object.entries(securitySchemes).map(
|
|
146
|
+
([schemeType, schemeObj]) =>
|
|
147
|
+
create("TabItem", {
|
|
148
|
+
label: formatTabLabel(schemeType),
|
|
149
|
+
value: `${schemeType}`,
|
|
150
|
+
children: [
|
|
151
|
+
createDescription(schemeObj.description),
|
|
152
|
+
createAuthenticationTable(schemeObj),
|
|
153
|
+
],
|
|
154
|
+
})
|
|
155
|
+
),
|
|
156
|
+
}),
|
|
157
|
+
],
|
|
158
|
+
style: { marginBottom: "2rem" },
|
|
159
|
+
});
|
|
160
|
+
}
|
package/src/markdown/index.ts
CHANGED
|
@@ -7,8 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
import { escape } from "lodash";
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ContactObject,
|
|
12
|
+
LicenseObject,
|
|
13
|
+
SecuritySchemeObject,
|
|
14
|
+
} from "../openapi/types";
|
|
11
15
|
import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
|
|
16
|
+
import { createAuthentication } from "./createAuthentication";
|
|
12
17
|
import { createContactInfo } from "./createContactInfo";
|
|
13
18
|
import { createDeprecationNotice } from "./createDeprecationNotice";
|
|
14
19
|
import { createDescription } from "./createDescription";
|
|
@@ -50,11 +55,15 @@ export function createApiPageMD({
|
|
|
50
55
|
|
|
51
56
|
export function createInfoPageMD({
|
|
52
57
|
info: { title, version, description, contact, license, termsOfService },
|
|
58
|
+
securitySchemes,
|
|
53
59
|
}: InfoPageMetadata) {
|
|
54
60
|
return render([
|
|
61
|
+
`import Tabs from "@theme/Tabs";\n`,
|
|
62
|
+
`import TabItem from "@theme/TabItem";\n`,
|
|
55
63
|
createVersionBadge(version),
|
|
56
64
|
`# ${escape(title)}\n\n`,
|
|
57
65
|
createDescription(description),
|
|
66
|
+
createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
|
|
58
67
|
createContactInfo(contact as ContactObject),
|
|
59
68
|
createTermsOfService(termsOfService),
|
|
60
69
|
createLicense(license as LicenseObject),
|
|
@@ -26,12 +26,6 @@ describe("openapi", () => {
|
|
|
26
26
|
const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
|
|
27
27
|
expect(yaml).toBeTruthy();
|
|
28
28
|
expect(yaml?.sourceDirName).toBe(".");
|
|
29
|
-
const froyo = results.find((x) => x.source.endsWith("froyo.yaml"));
|
|
30
|
-
expect(froyo).toBeTruthy();
|
|
31
|
-
expect(froyo?.sourceDirName).toBe("yogurtstore");
|
|
32
|
-
const nested = results.find((x) => x.source.endsWith("nested.yaml"));
|
|
33
|
-
expect(nested).toBeTruthy();
|
|
34
|
-
expect(nested?.sourceDirName).toBe("yogurtstore/nested");
|
|
35
29
|
});
|
|
36
30
|
});
|
|
37
31
|
});
|