Skip to content

Commit 7f6675e

Browse files
committed
fixes #409 - improved summary and description rendering
1 parent 4fa451d commit 7f6675e

File tree

4 files changed

+20
-29
lines changed

4 files changed

+20
-29
lines changed

src/templates/endpoint-template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function endpointHeadTemplate(path) {
5555
: ''
5656
}
5757
<div class="only-large-screen" style="min-width:60px; flex:1"></div>
58-
<div class="m-markdown-small descr"> ${unsafeHTML(marked(path.summary || ''))} </div>
58+
<div class="descr">${path.summary || path.shotSummary} </div>
5959
</div>
6060
`;
6161
}
@@ -81,7 +81,7 @@ function endpointBodyTemplate(path) {
8181
return html`
8282
<div class='endpoint-body ${path.method} ${path.deprecated ? 'deprecated' : ''}'>
8383
<div class="summary">
84-
${path.summary && path.summary !== path.description ? html`<div class="title">${path.summary}</div>` : ''}
84+
${path.summary ? html`<div class="title">${path.summary}<div>` : path.shortSummary !== path.description ? html`<div class="title">${path.shortSummary}</div>` : ''}
8585
${path.description ? html`<div class="m-markdown"> ${unsafeHTML(marked(path.description))}</div>` : ''}
8686
${pathSecurityTemplate.call(this, path.security)}
8787
${codeSampleTabPanel}

src/templates/expanded-endpoint-template.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,13 @@ export function expandedEndpointBodyTemplate(path, tagName = '') {
3434
${this.renderStyle === 'focused' ? html`<h3 class="upper" style="font-weight:bold"> ${tagName} </h3>` : ''}
3535
${path.deprecated ? html`<div class="bold-text red-text"> DEPRECATED </div>` : ''}
3636
${html`
37-
<h2 class = "${path.deprecated ? 'gray-text' : ''}">
38-
${path.summary || html`<span class='upper ${path.deprecated ? ' method-fg gray-text' : path.method} '> ${path.method}</span> ${path.path}`}
39-
</h2>
40-
${path.summary
41-
? html`
42-
<div class='mono-font regular-font-size' style='padding: 8px 0; color:var(--fg3)'>
43-
<span class='regular-font upper method-fg ${path.deprecated ? ' gray-text' : ` bold-text ${path.method}`} '>${path.method}</span>
44-
<span class = '${path.deprecated ? 'gray-text' : ''}'> ${path.path} </span>
45-
</div>`
46-
: ''
47-
}`
37+
<h2> ${path.shortSummary || `${path.method.toUpperCase()} ${path.path}`}</h2>
38+
<div class='mono-font regular-font-size' style='padding: 8px 0; color:var(--fg3)'>
39+
<span class='regular-font upper method-fg bold-text ${path.method}'>${path.method}</span>
40+
<span>${path.path}</span>
41+
</div>`
4842
}
49-
${path.description ? html`<div class="m-markdown"> ${unsafeHTML(marked(path.description || ''))}</div>` : ''}
43+
${path.description ? html`<div class="m-markdown"> ${unsafeHTML(marked(path.description))}</div>` : ''}
5044
${pathSecurityTemplate.call(this, path.security)}
5145
${codeSampleTabPanel}
5246
<div class='expanded-req-resp-container'>

src/templates/navbar-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default function navbarTemplate() {
156156
<span style = "${p.deprecated ? 'filter:opacity(0.5)' : ''}">
157157
${this.usePathInNavBar === 'true'
158158
? html`<span class='mono-font'>${p.method.toUpperCase()} ${p.path}</span>`
159-
: p.summary
159+
: p.summary || p.shortSummary
160160
}
161161
</span>
162162
</div>`)}

src/utils/spec-parser.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ function groupByTags(openApiSpec, sortTags = false, sortEndpointsBy) {
278278
for (const path in openApiSpec.paths) {
279279
const commonParams = openApiSpec.paths[path].parameters;
280280
const commonPathProp = {
281-
summary: openApiSpec.paths[path].summary,
282-
description: openApiSpec.paths[path].description,
281+
// summary: openApiSpec.paths[path].summary,
282+
// description: openApiSpec.paths[path].description,
283283
servers: openApiSpec.paths[path].servers ? openApiSpec.paths[path].servers : [],
284284
parameters: openApiSpec.paths[path].parameters ? openApiSpec.paths[path].parameters : [],
285285
};
@@ -321,15 +321,11 @@ function groupByTags(openApiSpec, sortTags = false, sortEndpointsBy) {
321321
tags.push(tagObj);
322322
}
323323

324-
// Generate Path summary and Description if it is missing for a method
325-
let summary = (fullPath.summary || fullPath.description || `${methodName} ${path}`).trim().split('/\r?\n/')[0];
326-
if (summary.length > 100) {
327-
summary = summary.split('.')[0];
324+
// Generate a short summary which is broken
325+
let shortSummary = (fullPath.summary || fullPath.description || fullPath.path).trim();
326+
if (shortSummary.length > 100) {
327+
shortSummary = shortSummary.split('/\r?\n|[.]/')[0]; // take the first line (period or carriage return)
328328
}
329-
if (!fullPath.description) {
330-
fullPath.description = ((fullPath.summary || '-').trim());
331-
}
332-
333329
// Merge Common Parameters with This methods parameters
334330
let finalParameters = [];
335331
if (commonParams) {
@@ -351,9 +347,10 @@ function groupByTags(openApiSpec, sortTags = false, sortEndpointsBy) {
351347
show: true,
352348
expanded: false,
353349
expandedAtLeastOnce: false,
354-
summary,
350+
summary: (fullPath.summary || ''),
351+
description: (fullPath.description || ''),
352+
shortSummary,
355353
method: methodName,
356-
description: fullPath.description,
357354
path,
358355
operationId: fullPath.operationId,
359356
elementId: `${methodName}-${path.replace(invalidCharsRegEx, '-')}`,
@@ -364,8 +361,8 @@ function groupByTags(openApiSpec, sortTags = false, sortEndpointsBy) {
364361
callbacks: fullPath.callbacks,
365362
deprecated: fullPath.deprecated,
366363
security: fullPath.security,
367-
commonSummary: commonPathProp.summary,
368-
commonDescription: commonPathProp.description,
364+
// commonSummary: commonPathProp.summary,
365+
// commonDescription: commonPathProp.description,
369366
xCodeSamples: fullPath['x-codeSamples'] || fullPath['x-code-samples'] || '',
370367
});
371368
});// End of tag path create

0 commit comments

Comments
 (0)