docusaurus-plugin-openapi-docs 0.0.0-569 → 0.0.0-570

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.
@@ -13,7 +13,7 @@ function createAuthentication(securitySchemes) {
13
13
  if (!securitySchemes || !Object.keys(securitySchemes).length)
14
14
  return "";
15
15
  const createAuthenticationTable = (securityScheme) => {
16
- const { bearerFormat, flows, name, scheme, type } = securityScheme;
16
+ const { bearerFormat, flows, name, scheme, type, openIdConnectUrl } = securityScheme;
17
17
  const createSecuritySchemeTypeRow = () => (0, utils_1.create)("tr", {
18
18
  children: [
19
19
  (0, utils_1.create)("th", { children: "Security Scheme Type:" }),
@@ -25,7 +25,7 @@ function createAuthentication(securitySchemes) {
25
25
  const { authorizationUrl, tokenUrl, refreshUrl, scopes } = flowObj;
26
26
  return (0, utils_1.create)("tr", {
27
27
  children: [
28
- (0, utils_1.create)("th", { children: `${flowType} OAuth Flow:` }),
28
+ (0, utils_1.create)("th", { children: `OAuth Flow (${flowType}):` }),
29
29
  (0, utils_1.create)("td", {
30
30
  children: [
31
31
  (0, utils_1.guard)(tokenUrl, () => (0, utils_1.create)("p", { children: `Token URL: ${tokenUrl}` })),
@@ -76,12 +76,12 @@ function createAuthentication(securitySchemes) {
76
76
  (0, utils_1.create)("td", { children: scheme }),
77
77
  ],
78
78
  }),
79
- (0, utils_1.create)("tr", {
79
+ (0, utils_1.guard)(bearerFormat, () => (0, utils_1.create)("tr", {
80
80
  children: [
81
81
  (0, utils_1.create)("th", { children: "Bearer format:" }),
82
82
  (0, utils_1.create)("td", { children: bearerFormat }),
83
83
  ],
84
- }),
84
+ })),
85
85
  ],
86
86
  }),
87
87
  }),
@@ -100,20 +100,51 @@ function createAuthentication(securitySchemes) {
100
100
  }),
101
101
  ],
102
102
  });
103
+ case "openIdConnect":
104
+ return (0, utils_1.create)("div", {
105
+ children: [
106
+ (0, utils_1.create)("table", {
107
+ children: (0, utils_1.create)("tbody", {
108
+ children: [
109
+ createSecuritySchemeTypeRow(),
110
+ (0, utils_1.guard)(openIdConnectUrl, () => (0, utils_1.create)("tr", {
111
+ children: [
112
+ (0, utils_1.create)("th", { children: "OpenID Connect URL:" }),
113
+ (0, utils_1.create)("td", { children: openIdConnectUrl }),
114
+ ],
115
+ })),
116
+ ],
117
+ }),
118
+ }),
119
+ ],
120
+ });
103
121
  default:
104
122
  return "";
105
123
  }
106
124
  };
107
- const formatTabLabel = (str) => {
108
- const formattedLabel = str
125
+ const formatTabLabel = (key, type, scheme) => {
126
+ const formattedLabel = key
109
127
  .replace(/(_|-)/g, " ")
110
128
  .trim()
111
129
  .replace(/\w\S*/g, (str) => str.charAt(0).toUpperCase() + str.substr(1))
112
130
  .replace(/([a-z])([A-Z])/g, "$1 $2")
113
131
  .replace(/([A-Z])([A-Z][a-z])/g, "$1 $2");
114
- const isOAuth = formattedLabel.toLowerCase().includes("oauth2");
115
- const isApiKey = formattedLabel.toLowerCase().includes("api");
116
- return isOAuth ? "OAuth 2.0" : isApiKey ? "API Key" : formattedLabel;
132
+ const isOAuth = type === "oauth2";
133
+ const isApiKey = type === "apiKey";
134
+ const isHttpBasic = type === "http" && scheme === "basic";
135
+ const isHttpBearer = type === "http" && scheme === "bearer";
136
+ const isOpenId = type === "openIdConnect";
137
+ if (isOAuth)
138
+ return `OAuth 2.0: ${key}`;
139
+ if (isApiKey)
140
+ return `API Key: ${key}`;
141
+ if (isHttpBasic)
142
+ return "HTTP: Basic Auth";
143
+ if (isHttpBearer)
144
+ return "HTTP: Bearer Auth";
145
+ if (isOpenId)
146
+ return `OpenID Connect: ${key}`;
147
+ return formattedLabel;
117
148
  };
118
149
  return (0, utils_1.create)("div", {
119
150
  children: [
@@ -122,10 +153,11 @@ function createAuthentication(securitySchemes) {
122
153
  id: "authentication",
123
154
  style: { marginBottom: "1rem" },
124
155
  }),
125
- (0, utils_1.create)("Tabs", {
126
- children: Object.entries(securitySchemes).map(([schemeType, schemeObj]) => (0, utils_1.create)("TabItem", {
127
- label: formatTabLabel(schemeType),
128
- value: `${schemeType}`,
156
+ (0, utils_1.create)("SchemaTabs", {
157
+ className: "openapi-tabs__security-schemes",
158
+ children: Object.entries(securitySchemes).map(([schemeKey, schemeObj]) => (0, utils_1.create)("TabItem", {
159
+ label: formatTabLabel(schemeKey, schemeObj.type, schemeObj.scheme),
160
+ value: `${schemeKey}`,
129
161
  children: [
130
162
  (0, createDescription_1.createDescription)(schemeObj.description),
131
163
  createAuthenticationTable(schemeObj),
@@ -48,7 +48,7 @@ exports.createApiPageMD = createApiPageMD;
48
48
  function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, downloadUrl, }) {
49
49
  return (0, utils_1.render)([
50
50
  `import ApiLogo from "@theme/ApiLogo";\n`,
51
- `import Tabs from "@theme/Tabs";\n`,
51
+ `import SchemaTabs from "@theme/SchemaTabs";\n`,
52
52
  `import TabItem from "@theme/TabItem";\n`,
53
53
  `import Export from "@theme/ApiDemoPanel/Export";\n\n`,
54
54
  (0, createVersionBadge_1.createVersionBadge)(version),
@@ -66,7 +66,7 @@ function createItems(openapiData, options, sidebarOptions) {
66
66
  let items = [];
67
67
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
68
68
  const infoId = (0, kebabCase_1.default)(infoIdSpaces);
69
- if (openapiData.info.description) {
69
+ if (openapiData.info.description || openapiData.info.title) {
70
70
  // Only create an info page if we have a description.
71
71
  const infoDescription = (_a = openapiData.info) === null || _a === void 0 ? void 0 : _a.description;
72
72
  let splitDescription;
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-569",
4
+ "version": "0.0.0-570",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -68,5 +68,5 @@
68
68
  "engines": {
69
69
  "node": ">=14"
70
70
  },
71
- "gitHead": "4b50df749f384af595fab65cf8fa687ad612d84e"
71
+ "gitHead": "4d31250d34849be84d2b57115c8ee8de0e98d509"
72
72
  }
@@ -13,7 +13,8 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
13
13
  if (!securitySchemes || !Object.keys(securitySchemes).length) return "";
14
14
 
15
15
  const createAuthenticationTable = (securityScheme: any) => {
16
- const { bearerFormat, flows, name, scheme, type } = securityScheme;
16
+ const { bearerFormat, flows, name, scheme, type, openIdConnectUrl } =
17
+ securityScheme;
17
18
 
18
19
  const createSecuritySchemeTypeRow = () =>
19
20
  create("tr", {
@@ -30,7 +31,7 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
30
31
 
31
32
  return create("tr", {
32
33
  children: [
33
- create("th", { children: `${flowType} OAuth Flow:` }),
34
+ create("th", { children: `OAuth Flow (${flowType}):` }),
34
35
  create("td", {
35
36
  children: [
36
37
  guard(tokenUrl, () =>
@@ -91,12 +92,14 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
91
92
  create("td", { children: scheme }),
92
93
  ],
93
94
  }),
94
- create("tr", {
95
- children: [
96
- create("th", { children: "Bearer format:" }),
97
- create("td", { children: bearerFormat }),
98
- ],
99
- }),
95
+ guard(bearerFormat, () =>
96
+ create("tr", {
97
+ children: [
98
+ create("th", { children: "Bearer format:" }),
99
+ create("td", { children: bearerFormat }),
100
+ ],
101
+ })
102
+ ),
100
103
  ],
101
104
  }),
102
105
  }),
@@ -115,23 +118,51 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
115
118
  }),
116
119
  ],
117
120
  });
121
+ case "openIdConnect":
122
+ return create("div", {
123
+ children: [
124
+ create("table", {
125
+ children: create("tbody", {
126
+ children: [
127
+ createSecuritySchemeTypeRow(),
128
+ guard(openIdConnectUrl, () =>
129
+ create("tr", {
130
+ children: [
131
+ create("th", { children: "OpenID Connect URL:" }),
132
+ create("td", { children: openIdConnectUrl }),
133
+ ],
134
+ })
135
+ ),
136
+ ],
137
+ }),
138
+ }),
139
+ ],
140
+ });
118
141
  default:
119
142
  return "";
120
143
  }
121
144
  };
122
145
 
123
- const formatTabLabel = (str: string) => {
124
- const formattedLabel = str
146
+ const formatTabLabel = (key: string, type: string, scheme: string) => {
147
+ const formattedLabel = key
125
148
  .replace(/(_|-)/g, " ")
126
149
  .trim()
127
150
  .replace(/\w\S*/g, (str) => str.charAt(0).toUpperCase() + str.substr(1))
128
151
  .replace(/([a-z])([A-Z])/g, "$1 $2")
129
152
  .replace(/([A-Z])([A-Z][a-z])/g, "$1 $2");
153
+ const isOAuth = type === "oauth2";
154
+ const isApiKey = type === "apiKey";
155
+ const isHttpBasic = type === "http" && scheme === "basic";
156
+ const isHttpBearer = type === "http" && scheme === "bearer";
157
+ const isOpenId = type === "openIdConnect";
130
158
 
131
- const isOAuth = formattedLabel.toLowerCase().includes("oauth2");
132
- const isApiKey = formattedLabel.toLowerCase().includes("api");
159
+ if (isOAuth) return `OAuth 2.0: ${key}`;
160
+ if (isApiKey) return `API Key: ${key}`;
161
+ if (isHttpBasic) return "HTTP: Basic Auth";
162
+ if (isHttpBearer) return "HTTP: Bearer Auth";
163
+ if (isOpenId) return `OpenID Connect: ${key}`;
133
164
 
134
- return isOAuth ? "OAuth 2.0" : isApiKey ? "API Key" : formattedLabel;
165
+ return formattedLabel;
135
166
  };
136
167
 
137
168
  return create("div", {
@@ -141,12 +172,17 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
141
172
  id: "authentication",
142
173
  style: { marginBottom: "1rem" },
143
174
  }),
144
- create("Tabs", {
175
+ create("SchemaTabs", {
176
+ className: "openapi-tabs__security-schemes",
145
177
  children: Object.entries(securitySchemes).map(
146
- ([schemeType, schemeObj]) =>
178
+ ([schemeKey, schemeObj]) =>
147
179
  create("TabItem", {
148
- label: formatTabLabel(schemeType),
149
- value: `${schemeType}`,
180
+ label: formatTabLabel(
181
+ schemeKey,
182
+ schemeObj.type,
183
+ schemeObj.scheme
184
+ ),
185
+ value: `${schemeKey}`,
150
186
  children: [
151
187
  createDescription(schemeObj.description),
152
188
  createAuthenticationTable(schemeObj),
@@ -88,7 +88,7 @@ export function createInfoPageMD({
88
88
  }: InfoPageMetadata) {
89
89
  return render([
90
90
  `import ApiLogo from "@theme/ApiLogo";\n`,
91
- `import Tabs from "@theme/Tabs";\n`,
91
+ `import SchemaTabs from "@theme/SchemaTabs";\n`,
92
92
  `import TabItem from "@theme/TabItem";\n`,
93
93
  `import Export from "@theme/ApiDemoPanel/Export";\n\n`,
94
94
 
@@ -88,7 +88,7 @@ function createItems(
88
88
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
89
89
  const infoId = kebabCase(infoIdSpaces);
90
90
 
91
- if (openapiData.info.description) {
91
+ if (openapiData.info.description || openapiData.info.title) {
92
92
  // Only create an info page if we have a description.
93
93
  const infoDescription = openapiData.info?.description;
94
94
  let splitDescription: any;