docusaurus-plugin-openapi-docs 0.0.0-366 → 0.0.0-370

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 CHANGED
@@ -103,7 +103,7 @@ Here is an example of properly configuring your `docusaurus.config.js` file for
103
103
 
104
104
  | Name | Type | Default | Description |
105
105
  | ---------------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------- |
106
- | `specPath` | `string` | `null` | Designated path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
106
+ | `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
107
107
  | `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
108
108
  | `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
109
109
  | `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { LoadContext, Plugin } from "@docusaurus/types";
2
2
  import type { PluginOptions, LoadedContent } from "./types";
3
+ export declare function isURL(str: string): boolean;
3
4
  export default function pluginOpenAPI(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ 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.isURL = void 0;
12
13
  const fs_1 = __importDefault(require("fs"));
13
14
  const path_1 = __importDefault(require("path"));
14
15
  const utils_1 = require("@docusaurus/utils");
@@ -17,12 +18,18 @@ const mustache_1 = require("mustache");
17
18
  const markdown_1 = require("./markdown");
18
19
  const openapi_1 = require("./openapi");
19
20
  const sidebars_1 = __importDefault(require("./sidebars"));
21
+ function isURL(str) {
22
+ return /^(https?:)\/\//m.test(str);
23
+ }
24
+ exports.isURL = isURL;
20
25
  function pluginOpenAPI(context, options) {
21
26
  let { config } = options;
22
27
  let { siteDir } = context;
23
28
  async function generateApiDocs(options) {
24
29
  let { specPath, outputDir, template, sidebarOptions } = options;
25
- const contentPath = path_1.default.resolve(siteDir, specPath);
30
+ const contentPath = isURL(specPath)
31
+ ? specPath
32
+ : path_1.default.resolve(siteDir, specPath);
26
33
  try {
27
34
  const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath, {});
28
35
  const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, sidebarOptions);
@@ -18,6 +18,7 @@ const chalk_1 = __importDefault(require("chalk"));
18
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
19
19
  const json_refs_1 = __importDefault(require("json-refs"));
20
20
  const lodash_1 = require("lodash");
21
+ const index_1 = require("../index");
21
22
  const createExample_1 = require("./createExample");
22
23
  const loadAndBundleSpec_1 = require("./utils/loadAndBundleSpec");
23
24
  /**
@@ -188,26 +189,28 @@ function bindCollectionToApiItems(items, postmanCollection) {
188
189
  });
189
190
  }
190
191
  async function readOpenapiFiles(openapiPath, _options) {
191
- const stat = await fs_extra_1.default.lstat(openapiPath);
192
- if (stat.isDirectory()) {
193
- console.warn(chalk_1.default.yellow("WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."));
194
- // TODO: Add config for inlcude/ignore
195
- const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
196
- cwd: openapiPath,
197
- ignore: utils_1.GlobExcludeDefault,
198
- deep: 1,
199
- });
200
- const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
201
- return Promise.all(sources.map(async (source) => {
202
- // TODO: make a function for this
203
- const fullPath = path_1.default.join(openapiPath, source);
204
- const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(fullPath));
205
- return {
206
- source: fullPath,
207
- sourceDirName: path_1.default.dirname(source),
208
- data,
209
- };
210
- }));
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
+ }
211
214
  }
212
215
  const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(openapiPath));
213
216
  return [
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-366",
4
+ "version": "0.0.0-370",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=14"
64
64
  },
65
- "gitHead": "b05ab424dc11297ef08a42bace80791998f70082"
65
+ "gitHead": "7e897ad05419c341a0b7fb42eb17d4c2e77b43e7"
66
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 = path.resolve(siteDir, specPath);
35
+ const contentPath = isURL(specPath)
36
+ ? specPath
37
+ : path.resolve(siteDir, specPath);
32
38
 
33
39
  try {
34
40
  const openapiFiles = await readOpenapiFiles(contentPath, {});
@@ -16,6 +16,7 @@ import fs from "fs-extra";
16
16
  import JsonRefs from "json-refs";
17
17
  import { kebabCase } from "lodash";
18
18
 
19
+ import { isURL } from "../index";
19
20
  import {
20
21
  ApiMetadata,
21
22
  ApiPageMetadata,
@@ -248,35 +249,37 @@ export async function readOpenapiFiles(
248
249
  openapiPath: string,
249
250
  _options: {}
250
251
  ): Promise<OpenApiFiles[]> {
251
- const stat = await fs.lstat(openapiPath);
252
- if (stat.isDirectory()) {
253
- console.warn(
254
- chalk.yellow(
255
- "WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."
256
- )
257
- );
258
-
259
- // TODO: Add config for inlcude/ignore
260
- const allFiles = await Globby(["**/*.{json,yaml,yml}"], {
261
- cwd: openapiPath,
262
- ignore: GlobExcludeDefault,
263
- deep: 1,
264
- });
265
- const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
266
- return Promise.all(
267
- sources.map(async (source) => {
268
- // TODO: make a function for this
269
- const fullPath = path.join(openapiPath, source);
270
- const data = (await loadAndBundleSpec(
271
- fullPath
272
- )) as OpenApiObjectWithRef;
273
- return {
274
- source: fullPath, // This will be aliased in process.
275
- sourceDirName: path.dirname(source),
276
- data,
277
- };
278
- })
279
- );
252
+ if (!isURL(openapiPath)) {
253
+ const stat = await fs.lstat(openapiPath);
254
+ if (stat.isDirectory()) {
255
+ console.warn(
256
+ chalk.yellow(
257
+ "WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."
258
+ )
259
+ );
260
+
261
+ // TODO: Add config for inlcude/ignore
262
+ const allFiles = await Globby(["**/*.{json,yaml,yml}"], {
263
+ cwd: openapiPath,
264
+ ignore: GlobExcludeDefault,
265
+ deep: 1,
266
+ });
267
+ const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
268
+ return Promise.all(
269
+ sources.map(async (source) => {
270
+ // TODO: make a function for this
271
+ const fullPath = path.join(openapiPath, source);
272
+ const data = (await loadAndBundleSpec(
273
+ fullPath
274
+ )) as OpenApiObjectWithRef;
275
+ return {
276
+ source: fullPath, // This will be aliased in process.
277
+ sourceDirName: path.dirname(source),
278
+ data,
279
+ };
280
+ })
281
+ );
282
+ }
280
283
  }
281
284
  const data = (await loadAndBundleSpec(openapiPath)) as OpenApiObjectWithRef;
282
285
  return [