docusaurus-plugin-openapi-docs 0.0.0-361 → 0.0.0-366
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.js +5 -0
- 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 +17 -16
- 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 +10 -8
- package/src/index.ts +5 -0
- 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 +9 -6
- 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-366",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -28,20 +28,21 @@
|
|
|
28
28
|
"watch": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
32
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
31
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.21",
|
|
32
|
+
"@docusaurus/types": "2.0.0-beta.21",
|
|
33
33
|
"@types/fs-extra": "^9.0.13",
|
|
34
34
|
"@types/json-schema": "^7.0.9",
|
|
35
35
|
"@types/lodash": "^4.14.176",
|
|
36
36
|
"utility-types": "^3.10.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@docusaurus/mdx-loader": "2.0.0-beta.
|
|
40
|
-
"@docusaurus/plugin-content-docs": "2.0.0-beta.
|
|
41
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
42
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
39
|
+
"@docusaurus/mdx-loader": "2.0.0-beta.21",
|
|
40
|
+
"@docusaurus/plugin-content-docs": "2.0.0-beta.21",
|
|
41
|
+
"@docusaurus/utils": "2.0.0-beta.21",
|
|
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": "b05ab424dc11297ef08a42bace80791998f70082"
|
|
64
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -103,6 +103,9 @@ api: {{{json}}}
|
|
|
103
103
|
{{#api.method}}
|
|
104
104
|
sidebar_class_name: "{{{api.method}}} api-method"
|
|
105
105
|
{{/api.method}}
|
|
106
|
+
{{#infoPath}}
|
|
107
|
+
info_path: {{{infoPath}}}
|
|
108
|
+
{{/infoPath}}
|
|
106
109
|
---
|
|
107
110
|
|
|
108
111
|
{{{markdown}}}
|
|
@@ -154,7 +157,9 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
154
157
|
item.markdown = markdown;
|
|
155
158
|
if (item.type === "api") {
|
|
156
159
|
item.json = JSON.stringify(item.api);
|
|
160
|
+
if (item.infoId) item.infoPath = `${outputDir}/${item.infoId}`;
|
|
157
161
|
}
|
|
162
|
+
|
|
158
163
|
const view = render(mdTemplate, item);
|
|
159
164
|
const utils = render(infoMdTemplate, item);
|
|
160
165
|
// 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
|
});
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -13,7 +13,6 @@ import sdk from "@paloaltonetworks/postman-collection";
|
|
|
13
13
|
import Collection from "@paloaltonetworks/postman-collection";
|
|
14
14
|
import chalk from "chalk";
|
|
15
15
|
import fs from "fs-extra";
|
|
16
|
-
import yaml from "js-yaml";
|
|
17
16
|
import JsonRefs from "json-refs";
|
|
18
17
|
import { kebabCase } from "lodash";
|
|
19
18
|
|
|
@@ -26,6 +25,7 @@ import {
|
|
|
26
25
|
} from "../types";
|
|
27
26
|
import { sampleFromSchema } from "./createExample";
|
|
28
27
|
import { OpenApiObject, OpenApiObjectWithRef, TagObject } from "./types";
|
|
28
|
+
import { loadAndBundleSpec } from "./utils/loadAndBundleSpec";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Finds any reference objects in the OpenAPI definition and resolves them to a finalized value.
|
|
@@ -87,6 +87,7 @@ function createItems(
|
|
|
87
87
|
): ApiMetadata[] {
|
|
88
88
|
// TODO: Find a better way to handle this
|
|
89
89
|
let items: PartialPage<ApiMetadata>[] = [];
|
|
90
|
+
const infoId = kebabCase(openapiData.info.title);
|
|
90
91
|
|
|
91
92
|
if (sidebarOptions?.categoryLinkSource === "tag") {
|
|
92
93
|
// Only create an tag pages if categoryLinkSource set to tag.
|
|
@@ -119,7 +120,6 @@ function createItems(
|
|
|
119
120
|
|
|
120
121
|
if (openapiData.info.description) {
|
|
121
122
|
// Only create an info page if we have a description.
|
|
122
|
-
const infoId = kebabCase(openapiData.info.title);
|
|
123
123
|
const infoPage: PartialPage<InfoPageMetadata> = {
|
|
124
124
|
type: "info",
|
|
125
125
|
id: infoId,
|
|
@@ -128,6 +128,7 @@ function createItems(
|
|
|
128
128
|
description: openapiData.info.description,
|
|
129
129
|
slug: "/" + infoId,
|
|
130
130
|
frontMatter: {},
|
|
131
|
+
securitySchemes: openapiData.components?.securitySchemes,
|
|
131
132
|
info: {
|
|
132
133
|
...openapiData.info,
|
|
133
134
|
tags: openapiData.tags?.map((tagName) =>
|
|
@@ -183,6 +184,7 @@ function createItems(
|
|
|
183
184
|
const apiPage: PartialPage<ApiPageMetadata> = {
|
|
184
185
|
type: "api",
|
|
185
186
|
id: baseId,
|
|
187
|
+
infoId: infoId ?? "",
|
|
186
188
|
unversionedId: baseId,
|
|
187
189
|
title: title,
|
|
188
190
|
description: description ?? "",
|
|
@@ -258,14 +260,16 @@ export async function readOpenapiFiles(
|
|
|
258
260
|
const allFiles = await Globby(["**/*.{json,yaml,yml}"], {
|
|
259
261
|
cwd: openapiPath,
|
|
260
262
|
ignore: GlobExcludeDefault,
|
|
263
|
+
deep: 1,
|
|
261
264
|
});
|
|
262
265
|
const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
|
|
263
266
|
return Promise.all(
|
|
264
267
|
sources.map(async (source) => {
|
|
265
268
|
// TODO: make a function for this
|
|
266
269
|
const fullPath = path.join(openapiPath, source);
|
|
267
|
-
const
|
|
268
|
-
|
|
270
|
+
const data = (await loadAndBundleSpec(
|
|
271
|
+
fullPath
|
|
272
|
+
)) as OpenApiObjectWithRef;
|
|
269
273
|
return {
|
|
270
274
|
source: fullPath, // This will be aliased in process.
|
|
271
275
|
sourceDirName: path.dirname(source),
|
|
@@ -274,8 +278,7 @@ export async function readOpenapiFiles(
|
|
|
274
278
|
})
|
|
275
279
|
);
|
|
276
280
|
}
|
|
277
|
-
const
|
|
278
|
-
const data = yaml.load(openapiString) as OpenApiObjectWithRef;
|
|
281
|
+
const data = (await loadAndBundleSpec(openapiPath)) as OpenApiObjectWithRef;
|
|
279
282
|
return [
|
|
280
283
|
{
|
|
281
284
|
source: openapiPath, // This will be aliased in process.
|