docusaurus-plugin-openapi-docs 1.0.6 → 1.1.2

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 (47) hide show
  1. package/README.md +1 -2
  2. package/lib/markdown/createSchemaDetails.js +325 -132
  3. package/lib/markdown/index.js +1 -0
  4. package/lib/markdown/schema.js +25 -9
  5. package/lib/markdown/utils.d.ts +1 -1
  6. package/lib/markdown/utils.js +4 -1
  7. package/lib/openapi/openapi.d.ts +3 -3
  8. package/lib/openapi/openapi.js +30 -26
  9. package/lib/openapi/types.d.ts +2 -1
  10. package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
  11. package/lib/openapi/utils/{loadAndBundleSpec.js → loadAndResolveSpec.js} +61 -28
  12. package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
  13. package/lib/openapi/utils/services/OpenAPIParser.js +342 -0
  14. package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
  15. package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
  16. package/lib/openapi/utils/types/index.d.ts +2 -0
  17. package/lib/openapi/utils/types/index.js +23 -0
  18. package/lib/openapi/utils/types/open-api.d.ts +305 -0
  19. package/lib/openapi/utils/types/open-api.js +8 -0
  20. package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
  21. package/lib/openapi/utils/utils/JsonPointer.js +95 -0
  22. package/lib/openapi/utils/utils/helpers.d.ts +43 -0
  23. package/lib/openapi/utils/utils/helpers.js +230 -0
  24. package/lib/openapi/utils/utils/index.d.ts +3 -0
  25. package/lib/openapi/utils/utils/index.js +25 -0
  26. package/lib/openapi/utils/utils/openapi.d.ts +40 -0
  27. package/lib/openapi/utils/utils/openapi.js +605 -0
  28. package/lib/sidebars/index.js +5 -3
  29. package/package.json +15 -11
  30. package/src/markdown/createSchemaDetails.ts +405 -159
  31. package/src/markdown/index.ts +1 -0
  32. package/src/markdown/schema.ts +28 -8
  33. package/src/markdown/utils.ts +5 -2
  34. package/src/openapi/openapi.ts +42 -38
  35. package/src/openapi/types.ts +2 -1
  36. package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
  37. package/src/openapi/utils/services/OpenAPIParser.ts +433 -0
  38. package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
  39. package/src/openapi/utils/types/index.ts +10 -0
  40. package/src/openapi/utils/types/open-api.ts +303 -0
  41. package/src/openapi/utils/utils/JsonPointer.ts +99 -0
  42. package/src/openapi/utils/utils/helpers.ts +239 -0
  43. package/src/openapi/utils/utils/index.ts +11 -0
  44. package/src/openapi/utils/utils/openapi.ts +771 -0
  45. package/src/sidebars/index.ts +7 -4
  46. package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
  47. package/src/openapi/utils/loadAndBundleSpec.ts +0 -93
@@ -67,7 +67,6 @@ function groupByTags(
67
67
  const basePath = docPath
68
68
  ? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
69
69
  : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
70
-
71
70
  function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
72
71
  const sidebar_label = item.frontMatter.sidebar_label;
73
72
  const title = item.title;
@@ -94,7 +93,7 @@ function groupByTags(
94
93
  const id = infoItem.id;
95
94
  rootIntroDoc = {
96
95
  type: "doc" as const,
97
- id: `${basePath}/${id}`,
96
+ id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
98
97
  };
99
98
  }
100
99
 
@@ -117,7 +116,10 @@ function groupByTags(
117
116
  if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
118
117
  linkConfig = {
119
118
  type: "doc",
120
- id: `${basePath}/${taggedInfoObject.id}`,
119
+ id:
120
+ basePath === "" || undefined
121
+ ? `${taggedInfoObject.id}`
122
+ : `${basePath}/${taggedInfoObject.id}`,
121
123
  } as SidebarItemCategoryLinkConfig;
122
124
  }
123
125
 
@@ -126,7 +128,8 @@ function groupByTags(
126
128
  const tagId = kebabCase(tagObject.name);
127
129
  linkConfig = {
128
130
  type: "doc",
129
- id: `${basePath}/${tagId}`,
131
+ id:
132
+ basePath === "" || undefined ? `${tagId}` : `${basePath}/${tagId}`,
130
133
  } as SidebarItemCategoryLinkConfig;
131
134
  }
132
135
 
@@ -1,3 +0,0 @@
1
- import { OpenAPISpec } from "./types";
2
- export declare function loadAndBundleSpec(specUrlOrObject: object | string, parseJsonRefs: boolean | undefined): Promise<OpenAPISpec>;
3
- export declare function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec>;
@@ -1,93 +0,0 @@
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
- // @ts-nocheck
9
-
10
- import $RefParser from "@apidevtools/json-schema-ref-parser";
11
- import type { Source, Document } from "@redocly/openapi-core";
12
- import { bundle } from "@redocly/openapi-core/lib/bundle";
13
- import type { ResolvedConfig } from "@redocly/openapi-core/lib/config";
14
- import { Config } from "@redocly/openapi-core/lib/config/config";
15
- import chalk from "chalk";
16
- import { convertObj } from "swagger2openapi";
17
-
18
- import { OpenAPISpec } from "./types";
19
-
20
- async function resolveJsonRefs(specUrlOrObject: object | string) {
21
- try {
22
- let schema = await $RefParser.dereference(specUrlOrObject, {
23
- continueOnError: true,
24
- resolve: {
25
- http: {
26
- timeout: 15000, // 15 sec timeout
27
- },
28
- },
29
- dereference: {
30
- circular: "ignore",
31
- },
32
- });
33
- return schema;
34
- } catch (err) {
35
- console.error(chalk.yellow(err.errors[0]?.message ?? err));
36
- return;
37
- }
38
- }
39
-
40
- export async function loadAndBundleSpec(
41
- specUrlOrObject: object | string,
42
- parseJsonRefs: boolean | undefined
43
- ): Promise<OpenAPISpec> {
44
- const config = new Config({} as ResolvedConfig);
45
- const bundleOpts = {
46
- config,
47
- base: process.cwd(),
48
- };
49
-
50
- if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
51
- bundleOpts["doc"] = {
52
- source: { absoluteRef: "" } as Source,
53
- parsed: specUrlOrObject,
54
- } as Document;
55
- } else {
56
- bundleOpts["ref"] = specUrlOrObject;
57
- }
58
-
59
- // Force dereference ?
60
- // bundleOpts["dereference"] = true;
61
-
62
- const {
63
- bundle: { parsed },
64
- } = await bundle(bundleOpts);
65
- if (parseJsonRefs) {
66
- const resolved = resolveJsonRefs(parsed);
67
- return typeof resolved === Object
68
- ? resolved.swagger !== undefined
69
- ? convertSwagger2OpenAPI(resolved)
70
- : resolved
71
- : parsed;
72
- }
73
- return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
74
- }
75
-
76
- export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
77
- console.warn(
78
- "[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0"
79
- );
80
- return new Promise<OpenAPISpec>((resolve, reject) =>
81
- convertObj(
82
- spec,
83
- { patch: true, warnOnly: true, text: "{}", anchors: true },
84
- (err, res) => {
85
- // TODO: log any warnings
86
- if (err) {
87
- return reject(err);
88
- }
89
- resolve(res && (res.openapi as any));
90
- }
91
- )
92
- );
93
- }