@@ -1587,23 +1587,33 @@ Both `sortSet` and `sortComponentsSet` are optional when you call `openapiSort`.
15871587# ## Sorting with minimal setup
15881588
15891589` ` ` js
1590- const {openapiSort} = require('openapi-format');
1591- const fs = require('fs');
1590+ const {
1591+ parseFile,
1592+ stringify,
1593+ writeFile,
1594+ openapiSort
1595+ } = require('openapi-format');
15921596
1593- const document = JSON.parse(fs.readFileSync( 'spec.json', 'utf8'));
1594- const {data} = await openapiSort(document , {sort: true});
1597+ const input = await parseFile( 'spec.json'); // local path or remote URL
1598+ const {data} = await openapiSort(input , {sort: true});
15951599
1596- fs.writeFileSync('spec.sorted.json', JSON.stringify(data, null, 2));
1600+ const output = await stringify(data, {format: 'json'});
1601+ await writeFile('spec.sorted.json', output, {format: 'json'});
15971602` ` `
15981603
15991604# ## Sorting with custom tweaks
16001605
16011606` ` ` js
16021607const {
1608+ parseFile,
1609+ stringify,
1610+ writeFile,
16031611 openapiSort,
16041612 getDefaultSortSet
16051613} = require('openapi-format');
16061614
1615+ const document = await parseFile('spec.json');
1616+
16071617const sortSet = await getDefaultSortSet();
16081618sortSet.get = ['summary', 'description', 'responses']; // override GET priority
16091619
@@ -1612,14 +1622,17 @@ const {data} = await openapiSort(document, {
16121622 sortSet,
16131623 sortComponentsSet: ['schemas', 'responses']
16141624});
1625+
1626+ const output = await stringify(data, {format: 'json'});
1627+ await writeFile('spec.sorted.json', output, {format: 'json'});
16151628` ` `
16161629
16171630# ## Mixing in other utilities
16181631
16191632` ` ` js
16201633const {openapiFilter, openapiGenerate} = require('openapi-format');
16211634
1622- let draft = /* load OpenAPI */ ;
1635+ let draft = await parseFile('spec.json') ;
16231636draft = (await openapiFilter(draft, {
16241637 filterSet: {tags: ['public']}
16251638})).data;
0 commit comments