docusaurus-plugin-openapi-docs 0.0.0-497 → 0.0.0-499

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 CHANGED
@@ -120,7 +120,7 @@ function pluginOpenAPIDocs(context, options) {
120
120
  : `---
121
121
  id: {{{id}}}
122
122
  title: "{{{title}}}"
123
- description: "{{{description}}}"
123
+ description: "{{{frontMatter.description}}}"
124
124
  {{^api}}
125
125
  sidebar_label: Introduction
126
126
  {{/api}}
@@ -150,7 +150,7 @@ info_path: {{{infoPath}}}
150
150
  const infoMdTemplate = `---
151
151
  id: {{{id}}}
152
152
  title: "{{{title}}}"
153
- description: "{{{description}}}"
153
+ description: "{{{frontMatter.description}}}"
154
154
  sidebar_label: {{{title}}}
155
155
  hide_title: true
156
156
  custom_edit_url: null
@@ -167,8 +167,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
167
167
  `;
168
168
  const tagMdTemplate = `---
169
169
  id: {{{id}}}
170
- title: "{{{description}}}"
171
- description: "{{{description}}}"
170
+ title: "{{{frontMatter.description}}}"
171
+ description: "{{{frontMatter.description}}}"
172
172
  custom_edit_url: null
173
173
  ---
174
174
 
@@ -60,7 +60,7 @@ async function createPostmanCollection(openapiData) {
60
60
  return await jsonToCollection(data);
61
61
  }
62
62
  function createItems(openapiData, sidebarOptions) {
63
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
63
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
64
64
  // TODO: Find a better way to handle this
65
65
  let items = [];
66
66
  const infoId = (0, kebabCase_1.default)(openapiData.info.title);
@@ -75,13 +75,20 @@ function createItems(openapiData, sidebarOptions) {
75
75
  var _a;
76
76
  const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
77
77
  const tagId = (0, kebabCase_1.default)(tag.name);
78
+ const splitDescription = description.match(/[^\r\n]+/g);
78
79
  const tagPage = {
79
80
  type: "tag",
80
81
  id: tagId,
81
82
  unversionedId: tagId,
82
83
  title: description !== null && description !== void 0 ? description : "",
83
84
  description: description !== null && description !== void 0 ? description : "",
84
- frontMatter: {},
85
+ frontMatter: {
86
+ description: splitDescription
87
+ ? splitDescription[0]
88
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
89
+ .replace(/\s+$/, "")
90
+ : "",
91
+ },
85
92
  tag: {
86
93
  ...tag,
87
94
  },
@@ -91,6 +98,11 @@ function createItems(openapiData, sidebarOptions) {
91
98
  }
92
99
  if (openapiData.info.description) {
93
100
  // Only create an info page if we have a description.
101
+ const infoDescription = (_b = openapiData.info) === null || _b === void 0 ? void 0 : _b.description;
102
+ let splitDescription;
103
+ if (infoDescription) {
104
+ splitDescription = infoDescription.match(/[^\r\n]+/g);
105
+ }
94
106
  const infoPage = {
95
107
  type: "info",
96
108
  id: infoId,
@@ -99,12 +111,18 @@ function createItems(openapiData, sidebarOptions) {
99
111
  description: openapiData.info.description
100
112
  ? openapiData.info.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
101
113
  : "",
102
- frontMatter: {},
103
- securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
114
+ frontMatter: {
115
+ description: splitDescription
116
+ ? splitDescription[0]
117
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
118
+ .replace(/\s+$/, "")
119
+ : "",
120
+ },
121
+ securitySchemes: (_c = openapiData.components) === null || _c === void 0 ? void 0 : _c.securitySchemes,
104
122
  info: {
105
123
  ...openapiData.info,
106
124
  tags: openapiData.tags,
107
- title: (_c = openapiData.info.title) !== null && _c !== void 0 ? _c : "Introduction",
125
+ title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
108
126
  logo: openapiData.info["x-logo"],
109
127
  darkLogo: openapiData.info["x-dark-logo"],
110
128
  },
@@ -114,18 +132,18 @@ function createItems(openapiData, sidebarOptions) {
114
132
  for (let [path, pathObject] of Object.entries(openapiData.paths)) {
115
133
  const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
116
134
  for (let [method, operationObject] of Object.entries({ ...rest })) {
117
- const title = (_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "Missing summary";
135
+ const title = (_f = (_e = operationObject.summary) !== null && _e !== void 0 ? _e : operationObject.operationId) !== null && _f !== void 0 ? _f : "Missing summary";
118
136
  if (operationObject.description === undefined) {
119
137
  operationObject.description =
120
- (_g = (_f = operationObject.summary) !== null && _f !== void 0 ? _f : operationObject.operationId) !== null && _g !== void 0 ? _g : "";
138
+ (_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
121
139
  }
122
140
  const baseId = operationObject.operationId
123
141
  ? (0, kebabCase_1.default)(operationObject.operationId)
124
142
  : (0, kebabCase_1.default)(operationObject.summary);
125
- const servers = (_j = (_h = operationObject.servers) !== null && _h !== void 0 ? _h : pathObject.servers) !== null && _j !== void 0 ? _j : openapiData.servers;
126
- const security = (_k = operationObject.security) !== null && _k !== void 0 ? _k : openapiData.security;
143
+ const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
144
+ const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
127
145
  // Add security schemes so we know how to handle security.
128
- const securitySchemes = (_l = openapiData.components) === null || _l === void 0 ? void 0 : _l.securitySchemes;
146
+ const securitySchemes = (_m = openapiData.components) === null || _m === void 0 ? void 0 : _m.securitySchemes;
129
147
  // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
130
148
  if (securitySchemes) {
131
149
  for (let securityScheme of Object.values(securitySchemes)) {
@@ -135,12 +153,12 @@ function createItems(openapiData, sidebarOptions) {
135
153
  }
136
154
  }
137
155
  let jsonRequestBodyExample;
138
- const body = (_o = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o["application/json"];
156
+ const body = (_p = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content) === null || _p === void 0 ? void 0 : _p["application/json"];
139
157
  if (body === null || body === void 0 ? void 0 : body.schema) {
140
158
  jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
141
159
  }
142
160
  // Handle vendor JSON media types
143
- const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
161
+ const bodyContent = (_q = operationObject.requestBody) === null || _q === void 0 ? void 0 : _q.content;
144
162
  if (bodyContent) {
145
163
  const firstBodyContentKey = Object.keys(bodyContent)[0];
146
164
  if (firstBodyContentKey.endsWith("+json")) {
@@ -162,6 +180,11 @@ function createItems(openapiData, sidebarOptions) {
162
180
  defaults.parameters = parameters;
163
181
  }
164
182
  }
183
+ const opDescription = operationObject.description;
184
+ let splitDescription;
185
+ if (opDescription) {
186
+ splitDescription = opDescription.match(/[^\r\n]+/g);
187
+ }
165
188
  const apiPage = {
166
189
  type: "api",
167
190
  id: baseId,
@@ -171,7 +194,13 @@ function createItems(openapiData, sidebarOptions) {
171
194
  description: operationObject.description
172
195
  ? operationObject.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
173
196
  : "",
174
- frontMatter: {},
197
+ frontMatter: {
198
+ description: splitDescription
199
+ ? splitDescription[0]
200
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
201
+ .replace(/\s+$/, "")
202
+ : "",
203
+ },
175
204
  api: {
176
205
  ...defaults,
177
206
  tags: operationObject.tags,
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-497",
4
+ "version": "0.0.0-499",
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": "5f73a538e1e01fe3086a42707331a1ebb97fa0a8"
71
+ "gitHead": "771789491f71b64527ed72068384c9bf502f27b4"
72
72
  }
package/src/index.ts CHANGED
@@ -159,7 +159,7 @@ export default function pluginOpenAPIDocs(
159
159
  : `---
160
160
  id: {{{id}}}
161
161
  title: "{{{title}}}"
162
- description: "{{{description}}}"
162
+ description: "{{{frontMatter.description}}}"
163
163
  {{^api}}
164
164
  sidebar_label: Introduction
165
165
  {{/api}}
@@ -190,7 +190,7 @@ info_path: {{{infoPath}}}
190
190
  const infoMdTemplate = `---
191
191
  id: {{{id}}}
192
192
  title: "{{{title}}}"
193
- description: "{{{description}}}"
193
+ description: "{{{frontMatter.description}}}"
194
194
  sidebar_label: {{{title}}}
195
195
  hide_title: true
196
196
  custom_edit_url: null
@@ -208,8 +208,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
208
208
 
209
209
  const tagMdTemplate = `---
210
210
  id: {{{id}}}
211
- title: "{{{description}}}"
212
- description: "{{{description}}}"
211
+ title: "{{{frontMatter.description}}}"
212
+ description: "{{{frontMatter.description}}}"
213
213
  custom_edit_url: null
214
214
  ---
215
215
 
@@ -98,13 +98,20 @@ function createItems(
98
98
  openapiData.tags ?? []
99
99
  );
100
100
  const tagId = kebabCase(tag.name);
101
+ const splitDescription = description.match(/[^\r\n]+/g);
101
102
  const tagPage: PartialPage<TagPageMetadata> = {
102
103
  type: "tag",
103
104
  id: tagId,
104
105
  unversionedId: tagId,
105
106
  title: description ?? "",
106
107
  description: description ?? "",
107
- frontMatter: {},
108
+ frontMatter: {
109
+ description: splitDescription
110
+ ? splitDescription[0]
111
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
112
+ .replace(/\s+$/, "")
113
+ : "",
114
+ },
108
115
  tag: {
109
116
  ...tag,
110
117
  },
@@ -115,6 +122,11 @@ function createItems(
115
122
 
116
123
  if (openapiData.info.description) {
117
124
  // Only create an info page if we have a description.
125
+ const infoDescription = openapiData.info?.description;
126
+ let splitDescription: any;
127
+ if (infoDescription) {
128
+ splitDescription = infoDescription.match(/[^\r\n]+/g);
129
+ }
118
130
  const infoPage: PartialPage<InfoPageMetadata> = {
119
131
  type: "info",
120
132
  id: infoId,
@@ -126,7 +138,13 @@ function createItems(
126
138
  "$1'"
127
139
  )
128
140
  : "",
129
- frontMatter: {},
141
+ frontMatter: {
142
+ description: splitDescription
143
+ ? splitDescription[0]
144
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
145
+ .replace(/\s+$/, "")
146
+ : "",
147
+ },
130
148
  securitySchemes: openapiData.components?.securitySchemes,
131
149
  info: {
132
150
  ...openapiData.info,
@@ -208,6 +226,12 @@ function createItems(
208
226
  }
209
227
  }
210
228
 
229
+ const opDescription = operationObject.description;
230
+ let splitDescription: any;
231
+ if (opDescription) {
232
+ splitDescription = opDescription.match(/[^\r\n]+/g);
233
+ }
234
+
211
235
  const apiPage: PartialPage<ApiPageMetadata> = {
212
236
  type: "api",
213
237
  id: baseId,
@@ -220,7 +244,13 @@ function createItems(
220
244
  "$1'"
221
245
  )
222
246
  : "",
223
- frontMatter: {},
247
+ frontMatter: {
248
+ description: splitDescription
249
+ ? splitDescription[0]
250
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
251
+ .replace(/\s+$/, "")
252
+ : "",
253
+ },
224
254
  api: {
225
255
  ...defaults,
226
256
  tags: operationObject.tags,