Skip to content

Commit 4efd462

Browse files
authored
Merge pull request mrin9#24 from soulsnake/SortTagsOption
Sort tags option
2 parents a702360 + f3dfb3f commit 4efd462

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

docs/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ <h2> Attributes</h2>
197197
<td>false</td>
198198
</tr>
199199

200+
<tr>
201+
<td class="mono-bold">pdf-sort-tags</td>
202+
<td class="gray"> true to sort tags in the generated PDF</td>
203+
<td>true</td>
204+
</tr>
205+
200206
<tr>
201207
<td class="mono-bold">pdf-primary-color</td>
202208
<td class="gray">Color used for headings of main sections in PDF</td>

src/rapipdf.js

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export default customElements.define('rapi-pdf', class RapiPdf extends HTMLEleme
193193
}
194194

195195
generatePdf(jsonObj){
196+
let pdfSortTags = this.getAttribute('pdf-sort-tags')==='false'?false:true;
196197
let pdfPrimaryColor = this.getAttribute('pdf-primary-color');
197198
let pdfAlternateColor = this.getAttribute('pdf-alternate-color');
198199
let pdfTitle = this.getAttribute('pdf-title')===null?'API Reference':this.getAttribute('pdf-title');
@@ -208,6 +209,7 @@ export default customElements.define('rapi-pdf', class RapiPdf extends HTMLEleme
208209

209210
let localize = this.localize;
210211
let options = {
212+
pdfSortTags,
211213
pdfPrimaryColor,
212214
pdfAlternateColor,
213215
pdfTitle,

src/utils/parse-utils.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import JsonRefs from 'json-refs';
22
import converter from 'swagger2openapi';
33

4-
export default async function ProcessSpec(specUrl) {
4+
export default async function ProcessSpec(specUrl, sortTags) {
55
let jsonParsedSpec, convertedSpec, resolvedRefSpec;
66
let convertOptions = { patch:true, warnOnly:true };
77
let resolveOptions = { resolveCirculars: false }
@@ -148,7 +148,9 @@ export default async function ProcessSpec(specUrl) {
148148
})
149149
}
150150
servers = openApiSpec.servers;
151-
tags.sort((a, b) => (a.name < b.name ? -1 : (a.name > b.name ? 1: 0)) );
151+
if (sortTags) {
152+
tags.sort((a, b) => (a.name < b.name ? -1 : (a.name > b.name ? 1: 0)) );
153+
}
152154
let parsedSpec = {
153155
"info" : openApiSpec.info,
154156
"tags" : tags,

src/utils/pdf-gen.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getInfoDef, getSecurityDef, getApiDef, getApiListDef, getMarkDownDef }
77

88
export default async function createPdf(specUrl, options){
99

10-
let parsedSpec = await ProcessSpec(specUrl);
10+
let parsedSpec = await ProcessSpec(specUrl, options.pdfSortTags);
1111

1212
let pdfStyles={
1313
title:{fontSize:32},

0 commit comments

Comments
 (0)