docusaurus-plugin-openapi-docs 1.0.0 → 1.0.3

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 (58) hide show
  1. package/README.md +8 -7
  2. package/lib/index.d.ts +1 -0
  3. package/lib/index.js +80 -9
  4. package/lib/markdown/createAuthentication.d.ts +2 -0
  5. package/lib/markdown/createAuthentication.js +139 -0
  6. package/lib/markdown/createContactInfo.d.ts +2 -0
  7. package/lib/markdown/createContactInfo.js +49 -0
  8. package/lib/markdown/createLicense.d.ts +2 -0
  9. package/lib/markdown/createLicense.js +33 -0
  10. package/lib/markdown/createSchemaDetails.js +4 -1
  11. package/lib/markdown/createStatusCodes.js +1 -1
  12. package/lib/markdown/createTermsOfService.d.ts +1 -0
  13. package/lib/markdown/createTermsOfService.js +32 -0
  14. package/lib/markdown/index.d.ts +3 -2
  15. package/lib/markdown/index.js +17 -3
  16. package/lib/openapi/createExample.js +59 -49
  17. package/lib/openapi/openapi.d.ts +5 -4
  18. package/lib/openapi/openapi.js +94 -50
  19. package/lib/openapi/openapi.test.js +0 -6
  20. package/lib/openapi/types.d.ts +5 -1
  21. package/lib/openapi/utils/loadAndBundleSpec.d.ts +3 -0
  22. package/lib/openapi/utils/loadAndBundleSpec.js +44 -0
  23. package/lib/openapi/utils/types.d.ts +306 -0
  24. package/lib/{markdown/createRequestBodyTable.js → openapi/utils/types.js} +0 -6
  25. package/lib/sidebars/index.d.ts +2 -1
  26. package/lib/sidebars/index.js +87 -30
  27. package/lib/types.d.ts +14 -3
  28. package/package.json +19 -11
  29. package/src/index.ts +108 -11
  30. package/src/markdown/createAuthentication.ts +160 -0
  31. package/src/markdown/createContactInfo.ts +52 -0
  32. package/src/markdown/createLicense.ts +34 -0
  33. package/src/markdown/createSchemaDetails.ts +6 -2
  34. package/src/markdown/createStatusCodes.ts +1 -1
  35. package/src/markdown/createTermsOfService.ts +30 -0
  36. package/src/markdown/index.ts +23 -3
  37. package/src/openapi/createExample.ts +59 -50
  38. package/src/openapi/openapi.test.ts +0 -6
  39. package/src/openapi/openapi.ts +115 -53
  40. package/src/openapi/types.ts +5 -1
  41. package/src/openapi/utils/loadAndBundleSpec.ts +62 -0
  42. package/src/openapi/utils/types.ts +303 -0
  43. package/src/{markdown/createRequestBodyTable.ts → postman-collection.d.ts} +2 -9
  44. package/src/sidebars/index.ts +108 -31
  45. package/src/types.ts +15 -3
  46. package/lib/markdown/createFullWidthTable.d.ts +0 -2
  47. package/lib/markdown/createFullWidthTable.js +0 -18
  48. package/lib/markdown/createParamsTable.d.ts +0 -7
  49. package/lib/markdown/createParamsTable.js +0 -80
  50. package/lib/markdown/createRequestBodyTable.d.ts +0 -6
  51. package/lib/markdown/createSchemaTable.d.ts +0 -14
  52. package/lib/markdown/createSchemaTable.js +0 -217
  53. package/src/markdown/createFullWidthTable.ts +0 -16
  54. package/src/markdown/createParamsTable.ts +0 -102
  55. package/src/markdown/createSchemaTable.ts +0 -275
  56. package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +0 -4
  57. package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +0 -13
  58. package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +0 -13
@@ -5,8 +5,12 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.sampleFromSchema = void 0;
13
+ const chalk_1 = __importDefault(require("chalk"));
10
14
  const primitives = {
11
15
  string: {
12
16
  default: () => "string",
@@ -31,64 +35,70 @@ const primitives = {
31
35
  array: {},
32
36
  };
33
37
  const sampleFromSchema = (schema = {}) => {
34
- let { type, example, allOf, properties, items } = schema;
35
- if (example !== undefined) {
36
- return example;
37
- }
38
- if (allOf) {
39
- // TODO: We are just assuming it will always be an object for now
40
- let obj = {
41
- type: "object",
42
- properties: {},
43
- required: [], // NOTE: We shouldn't need to worry about required
44
- };
45
- for (let item of allOf) {
46
- if (item.properties) {
47
- obj.properties = {
48
- ...obj.properties,
49
- ...item.properties,
50
- };
51
- }
52
- }
53
- return (0, exports.sampleFromSchema)(obj);
54
- }
55
- if (!type) {
56
- if (properties) {
57
- type = "object";
38
+ try {
39
+ let { type, example, allOf, properties, items } = schema;
40
+ if (example !== undefined) {
41
+ return example;
58
42
  }
59
- else if (items) {
60
- type = "array";
43
+ if (allOf) {
44
+ // TODO: We are just assuming it will always be an object for now
45
+ let obj = {
46
+ type: "object",
47
+ properties: {},
48
+ required: [], // NOTE: We shouldn't need to worry about required
49
+ };
50
+ for (let item of allOf) {
51
+ if (item.properties) {
52
+ obj.properties = {
53
+ ...obj.properties,
54
+ ...item.properties,
55
+ };
56
+ }
57
+ }
58
+ return (0, exports.sampleFromSchema)(obj);
61
59
  }
62
- else {
63
- return;
60
+ if (!type) {
61
+ if (properties) {
62
+ type = "object";
63
+ }
64
+ else if (items) {
65
+ type = "array";
66
+ }
67
+ else {
68
+ return;
69
+ }
64
70
  }
65
- }
66
- if (type === "object") {
67
- let obj = {};
68
- for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
69
- if (prop.deprecated) {
70
- continue;
71
+ if (type === "object") {
72
+ let obj = {};
73
+ for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
74
+ if (prop.deprecated) {
75
+ continue;
76
+ }
77
+ obj[name] = (0, exports.sampleFromSchema)(prop);
71
78
  }
72
- obj[name] = (0, exports.sampleFromSchema)(prop);
79
+ return obj;
73
80
  }
74
- return obj;
75
- }
76
- if (type === "array") {
77
- if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
78
- return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleFromSchema)(item));
81
+ if (type === "array") {
82
+ if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
83
+ return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleFromSchema)(item));
84
+ }
85
+ if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
86
+ return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleFromSchema)(item));
87
+ }
88
+ return [(0, exports.sampleFromSchema)(items)];
79
89
  }
80
- if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
81
- return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleFromSchema)(item));
90
+ if (schema.enum) {
91
+ if (schema.default) {
92
+ return schema.default;
93
+ }
94
+ return normalizeArray(schema.enum)[0];
82
95
  }
83
- return [(0, exports.sampleFromSchema)(items)];
96
+ return primitive(schema);
84
97
  }
85
- if (schema.enum) {
86
- if (schema.default) {
87
- return schema.default;
88
- }
89
- return normalizeArray(schema.enum)[0];
98
+ catch (err) {
99
+ console.error(chalk_1.default.yellow("WARNING: failed to create example from schema object:", err));
100
+ return;
90
101
  }
91
- return primitive(schema);
92
102
  };
93
103
  exports.sampleFromSchema = sampleFromSchema;
94
104
  function primitive(schema = {}) {
@@ -1,11 +1,12 @@
1
- import { ApiMetadata } from "../types";
2
- import { OpenApiObjectWithRef } from "./types";
1
+ import { ApiMetadata, SidebarOptions } from "../types";
2
+ import { OpenApiObjectWithRef, TagObject } from "./types";
3
3
  interface OpenApiFiles {
4
4
  source: string;
5
5
  sourceDirName: string;
6
6
  data: OpenApiObjectWithRef;
7
7
  }
8
8
  export declare function readOpenapiFiles(openapiPath: string, _options: {}): Promise<OpenApiFiles[]>;
9
- export declare function processOpenapiFiles(files: OpenApiFiles[]): Promise<ApiMetadata[]>;
10
- export declare function processOpenapiFile(openapiDataWithRefs: OpenApiObjectWithRef): Promise<ApiMetadata[]>;
9
+ export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
10
+ export declare function processOpenapiFile(openapiDataWithRefs: OpenApiObjectWithRef, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
11
+ export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
11
12
  export {};
@@ -9,18 +9,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.processOpenapiFile = exports.processOpenapiFiles = exports.readOpenapiFiles = void 0;
12
+ exports.getTagDisplayName = exports.processOpenapiFile = exports.processOpenapiFiles = exports.readOpenapiFiles = void 0;
13
13
  const path_1 = __importDefault(require("path"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const openapi_to_postmanv2_1 = __importDefault(require("@paloaltonetworks/openapi-to-postmanv2"));
16
- // @ts-ignore
17
16
  const postman_collection_1 = __importDefault(require("@paloaltonetworks/postman-collection"));
18
17
  const chalk_1 = __importDefault(require("chalk"));
19
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
20
- const js_yaml_1 = __importDefault(require("js-yaml"));
21
19
  const json_refs_1 = __importDefault(require("json-refs"));
22
20
  const lodash_1 = require("lodash");
21
+ const index_1 = require("../index");
23
22
  const createExample_1 = require("./createExample");
23
+ const loadAndBundleSpec_1 = require("./utils/loadAndBundleSpec");
24
24
  /**
25
25
  * Finds any reference objects in the OpenAPI definition and resolves them to a finalized value.
26
26
  */
@@ -64,23 +64,52 @@ async function createPostmanCollection(openapiData) {
64
64
  }
65
65
  return await jsonToCollection(data);
66
66
  }
67
- function createItems(openapiData) {
68
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
67
+ function createItems(openapiData, sidebarOptions) {
68
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
69
69
  // TODO: Find a better way to handle this
70
70
  let items = [];
71
- // Only create an info page if we have a description.
71
+ const infoId = (0, lodash_1.kebabCase)(openapiData.info.title);
72
+ if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
73
+ // Only create an tag pages if categoryLinkSource set to tag.
74
+ const tags = (_a = openapiData.tags) !== null && _a !== void 0 ? _a : [];
75
+ // eslint-disable-next-line array-callback-return
76
+ tags
77
+ .filter((tag) => { var _a; return !((_a = tag.description) === null || _a === void 0 ? void 0 : _a.includes("SchemaDefinition")); })
78
+ // eslint-disable-next-line array-callback-return
79
+ .map((tag) => {
80
+ var _a;
81
+ const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
82
+ const tagId = (0, lodash_1.kebabCase)(tag.name);
83
+ const tagPage = {
84
+ type: "tag",
85
+ id: tagId,
86
+ unversionedId: tagId,
87
+ title: description !== null && description !== void 0 ? description : "",
88
+ description: description !== null && description !== void 0 ? description : "",
89
+ slug: "/" + tagId,
90
+ frontMatter: {},
91
+ tag: {
92
+ ...tag,
93
+ },
94
+ };
95
+ items.push(tagPage);
96
+ });
97
+ }
72
98
  if (openapiData.info.description) {
99
+ // Only create an info page if we have a description.
73
100
  const infoPage = {
74
101
  type: "info",
75
- id: "introduction",
76
- unversionedId: "introduction",
77
- title: "Introduction",
102
+ id: infoId,
103
+ unversionedId: infoId,
104
+ title: openapiData.info.title,
78
105
  description: openapiData.info.description,
79
- slug: "/introduction",
106
+ slug: "/" + infoId,
80
107
  frontMatter: {},
108
+ securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
81
109
  info: {
82
110
  ...openapiData.info,
83
- title: (_a = openapiData.info.title) !== null && _a !== void 0 ? _a : "Introduction",
111
+ tags: (_c = openapiData.tags) === null || _c === void 0 ? void 0 : _c.map((tagName) => { var _a; return getTagDisplayName(tagName.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
112
+ title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
84
113
  },
85
114
  };
86
115
  items.push(infoPage);
@@ -88,16 +117,16 @@ function createItems(openapiData) {
88
117
  for (let [path, pathObject] of Object.entries(openapiData.paths)) {
89
118
  const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
90
119
  for (let [method, operationObject] of Object.entries({ ...rest })) {
91
- const title = (_c = (_b = operationObject.summary) !== null && _b !== void 0 ? _b : operationObject.operationId) !== null && _c !== void 0 ? _c : "Missing summary";
120
+ const title = (_f = (_e = operationObject.summary) !== null && _e !== void 0 ? _e : operationObject.operationId) !== null && _f !== void 0 ? _f : "Missing summary";
92
121
  if (operationObject.description === undefined) {
93
122
  operationObject.description =
94
- (_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "";
123
+ (_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
95
124
  }
96
125
  const baseId = (0, lodash_1.kebabCase)(title);
97
- const servers = (_g = (_f = operationObject.servers) !== null && _f !== void 0 ? _f : pathObject.servers) !== null && _g !== void 0 ? _g : openapiData.servers;
98
- const security = (_h = operationObject.security) !== null && _h !== void 0 ? _h : openapiData.security;
126
+ const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
127
+ const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
99
128
  // Add security schemes so we know how to handle security.
100
- const securitySchemes = (_j = openapiData.components) === null || _j === void 0 ? void 0 : _j.securitySchemes;
129
+ const securitySchemes = (_m = openapiData.components) === null || _m === void 0 ? void 0 : _m.securitySchemes;
101
130
  // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
102
131
  if (securitySchemes) {
103
132
  for (let securityScheme of Object.values(securitySchemes)) {
@@ -107,7 +136,7 @@ function createItems(openapiData) {
107
136
  }
108
137
  }
109
138
  let jsonRequestBodyExample;
110
- const body = (_l = (_k = operationObject.requestBody) === null || _k === void 0 ? void 0 : _k.content) === null || _l === void 0 ? void 0 : _l["application/json"];
139
+ const body = (_p = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content) === null || _p === void 0 ? void 0 : _p["application/json"];
111
140
  if (body === null || body === void 0 ? void 0 : body.schema) {
112
141
  jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
113
142
  }
@@ -116,6 +145,7 @@ function createItems(openapiData) {
116
145
  const apiPage = {
117
146
  type: "api",
118
147
  id: baseId,
148
+ infoId: infoId !== null && infoId !== void 0 ? infoId : "",
119
149
  unversionedId: baseId,
120
150
  title: title,
121
151
  description: description !== null && description !== void 0 ? description : "",
@@ -123,7 +153,7 @@ function createItems(openapiData) {
123
153
  frontMatter: {},
124
154
  api: {
125
155
  ...defaults,
126
- tags: (_m = operationObject.tags) === null || _m === void 0 ? void 0 : _m.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
156
+ tags: (_q = operationObject.tags) === null || _q === void 0 ? void 0 : _q.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
127
157
  method,
128
158
  path,
129
159
  servers,
@@ -142,14 +172,13 @@ function createItems(openapiData) {
142
172
  * Attach Postman Request objects to the corresponding ApiItems.
143
173
  */
144
174
  function bindCollectionToApiItems(items, postmanCollection) {
145
- // @ts-ignore
146
175
  postmanCollection.forEachItem((item) => {
147
176
  const method = item.request.method.toLowerCase();
148
177
  const path = item.request.url
149
178
  .getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
150
179
  .replace(/:([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
151
180
  const apiItem = items.find((item) => {
152
- if (item.type === "info") {
181
+ if (item.type === "info" || item.type === "tag") {
153
182
  return false;
154
183
  }
155
184
  return item.api.path === path && item.api.method === method;
@@ -160,29 +189,30 @@ function bindCollectionToApiItems(items, postmanCollection) {
160
189
  });
161
190
  }
162
191
  async function readOpenapiFiles(openapiPath, _options) {
163
- const stat = await fs_extra_1.default.lstat(openapiPath);
164
- if (stat.isDirectory()) {
165
- console.warn(chalk_1.default.yellow("WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."));
166
- // TODO: Add config for inlcude/ignore
167
- const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
168
- cwd: openapiPath,
169
- ignore: utils_1.GlobExcludeDefault,
170
- });
171
- const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
172
- return Promise.all(sources.map(async (source) => {
173
- // TODO: make a function for this
174
- const fullPath = path_1.default.join(openapiPath, source);
175
- const openapiString = await fs_extra_1.default.readFile(fullPath, "utf-8");
176
- const data = js_yaml_1.default.load(openapiString);
177
- return {
178
- source: fullPath,
179
- sourceDirName: path_1.default.dirname(source),
180
- data,
181
- };
182
- }));
192
+ if (!(0, index_1.isURL)(openapiPath)) {
193
+ const stat = await fs_extra_1.default.lstat(openapiPath);
194
+ if (stat.isDirectory()) {
195
+ console.warn(chalk_1.default.yellow("WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."));
196
+ // TODO: Add config for inlcude/ignore
197
+ const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
198
+ cwd: openapiPath,
199
+ ignore: utils_1.GlobExcludeDefault,
200
+ deep: 1,
201
+ });
202
+ const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
203
+ return Promise.all(sources.map(async (source) => {
204
+ // TODO: make a function for this
205
+ const fullPath = path_1.default.join(openapiPath, source);
206
+ const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(fullPath));
207
+ return {
208
+ source: fullPath,
209
+ sourceDirName: path_1.default.dirname(source),
210
+ data,
211
+ };
212
+ }));
213
+ }
183
214
  }
184
- const openapiString = await fs_extra_1.default.readFile(openapiPath, "utf-8");
185
- const data = js_yaml_1.default.load(openapiString);
215
+ const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(openapiPath));
186
216
  return [
187
217
  {
188
218
  source: openapiPath,
@@ -192,24 +222,37 @@ async function readOpenapiFiles(openapiPath, _options) {
192
222
  ];
193
223
  }
194
224
  exports.readOpenapiFiles = readOpenapiFiles;
195
- async function processOpenapiFiles(files) {
225
+ async function processOpenapiFiles(files, sidebarOptions) {
196
226
  const promises = files.map(async (file) => {
197
- const items = await processOpenapiFile(file.data);
198
- return items.map((item) => ({
227
+ const processedFile = await processOpenapiFile(file.data, sidebarOptions);
228
+ const itemsObjectsArray = processedFile[0].map((item) => ({
199
229
  ...item,
200
230
  }));
231
+ const tags = processedFile[1];
232
+ return [itemsObjectsArray, tags];
201
233
  });
202
234
  const metadata = await Promise.all(promises);
203
- const items = metadata.flat();
204
- return items;
235
+ const items = metadata
236
+ .map(function (x) {
237
+ return x[0];
238
+ })
239
+ .flat();
240
+ const tags = metadata.map(function (x) {
241
+ return x[1];
242
+ });
243
+ return [items, tags];
205
244
  }
206
245
  exports.processOpenapiFiles = processOpenapiFiles;
207
- async function processOpenapiFile(openapiDataWithRefs) {
246
+ async function processOpenapiFile(openapiDataWithRefs, sidebarOptions) {
208
247
  const openapiData = await resolveRefs(openapiDataWithRefs);
209
248
  const postmanCollection = await createPostmanCollection(openapiData);
210
- const items = createItems(openapiData);
249
+ const items = createItems(openapiData, sidebarOptions);
211
250
  bindCollectionToApiItems(items, postmanCollection);
212
- return items;
251
+ let tags = [];
252
+ if (openapiData.tags !== undefined) {
253
+ tags = openapiData.tags;
254
+ }
255
+ return [items, tags];
213
256
  }
214
257
  exports.processOpenapiFile = processOpenapiFile;
215
258
  // order for picking items as a display name of tags
@@ -231,3 +274,4 @@ function getTagDisplayName(tagName, tags) {
231
274
  // always default to the tagName
232
275
  return tagName;
233
276
  }
277
+ exports.getTagDisplayName = getTagDisplayName;
@@ -22,12 +22,6 @@ describe("openapi", () => {
22
22
  const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
23
23
  expect(yaml).toBeTruthy();
24
24
  expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
25
- const froyo = results.find((x) => x.source.endsWith("froyo.yaml"));
26
- expect(froyo).toBeTruthy();
27
- expect(froyo === null || froyo === void 0 ? void 0 : froyo.sourceDirName).toBe("yogurtstore");
28
- const nested = results.find((x) => x.source.endsWith("nested.yaml"));
29
- expect(nested).toBeTruthy();
30
- expect(nested === null || nested === void 0 ? void 0 : nested.sourceDirName).toBe("yogurtstore/nested");
31
25
  });
32
26
  });
33
27
  });
@@ -29,6 +29,7 @@ export interface InfoObject {
29
29
  contact?: ContactObject;
30
30
  license?: LicenseObject;
31
31
  version: string;
32
+ tags?: String[];
32
33
  }
33
34
  export interface ContactObject {
34
35
  name?: string;
@@ -151,6 +152,7 @@ export interface ParameterObject {
151
152
  example?: any;
152
153
  examples?: Map<ExampleObject>;
153
154
  content?: Map<MediaTypeObject>;
155
+ param?: Object;
154
156
  }
155
157
  export interface ParameterObjectWithRef {
156
158
  name: string;
@@ -236,7 +238,7 @@ export interface LinkObject {
236
238
  export declare type HeaderObject = Omit<ParameterObject, "name" | "in">;
237
239
  export declare type HeaderObjectWithRef = Omit<ParameterObjectWithRef, "name" | "in">;
238
240
  export interface TagObject {
239
- name: string;
241
+ name?: string;
240
242
  description?: string;
241
243
  externalDocs?: ExternalDocumentationObject;
242
244
  "x-displayName"?: string;
@@ -304,6 +306,8 @@ export interface HttpSecuritySchemeObject {
304
306
  description?: string;
305
307
  scheme: string;
306
308
  bearerFormat?: string;
309
+ name?: string;
310
+ in?: string;
307
311
  }
308
312
  export interface Oauth2SecuritySchemeObject {
309
313
  type: "oauth2";
@@ -0,0 +1,3 @@
1
+ import { OpenAPISpec } from "./types";
2
+ export declare function loadAndBundleSpec(specUrlOrObject: object | string): Promise<OpenAPISpec>;
3
+ export declare function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec>;
@@ -0,0 +1,44 @@
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 });
9
+ exports.convertSwagger2OpenAPI = exports.loadAndBundleSpec = void 0;
10
+ const bundle_1 = require("@redocly/openapi-core/lib/bundle");
11
+ const config_1 = require("@redocly/openapi-core/lib/config/config");
12
+ const swagger2openapi_1 = require("swagger2openapi");
13
+ async function loadAndBundleSpec(specUrlOrObject) {
14
+ const config = new config_1.Config({});
15
+ const bundleOpts = {
16
+ config,
17
+ base: process.cwd(),
18
+ };
19
+ if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
20
+ bundleOpts["doc"] = {
21
+ source: { absoluteRef: "" },
22
+ parsed: specUrlOrObject,
23
+ };
24
+ }
25
+ else {
26
+ bundleOpts["ref"] = specUrlOrObject;
27
+ }
28
+ // Force dereference ?
29
+ // bundleOpts["dereference"] = true;
30
+ const { bundle: { parsed }, } = await (0, bundle_1.bundle)(bundleOpts);
31
+ return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
32
+ }
33
+ exports.loadAndBundleSpec = loadAndBundleSpec;
34
+ function convertSwagger2OpenAPI(spec) {
35
+ console.warn("[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0");
36
+ return new Promise((resolve, reject) => (0, swagger2openapi_1.convertObj)(spec, { patch: true, warnOnly: true, text: "{}", anchors: true }, (err, res) => {
37
+ // TODO: log any warnings
38
+ if (err) {
39
+ return reject(err);
40
+ }
41
+ resolve(res && res.openapi);
42
+ }));
43
+ }
44
+ exports.convertSwagger2OpenAPI = convertSwagger2OpenAPI;