Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 860eb41

Browse files
committed
replace swagger-ui and docs with redoc (for both)
1 parent b6e41ec commit 860eb41

File tree

5 files changed

+24
-44
lines changed

5 files changed

+24
-44
lines changed

lib/bundle.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,27 @@ const shell = require('shelljs');
44
const path = require('path');
55
const config = require('./config');
66
const Log = require('./log');
7-
const $RefParser = require("json-schema-ref-parser");
8-
let YAML = $RefParser.YAML;
97

108
const log = new Log();
119

12-
var SWAGGER_JSON_PATH = path.join(config.branchPath, 'openapi.json');
13-
var SWAGGER_YAML_PATH = path.join(config.branchPath, 'openapi.yaml');
10+
var OPENAPI_JSON_PATH = path.join(config.branchPath, 'openapi.json');
11+
var OPENAPI_YAML_PATH = path.join(config.branchPath, 'openapi.yaml');
1412

1513
const bundleSpec = async function() {
1614
shell.mkdir('-p', 'spec');
17-
// shell.mkdir('-p', 'web_deploy');
1815

1916
var specPath = path.join(config.root, config.apiSpecPath);
2017
var baseDir = path.dirname(specPath);
21-
// shell.cp('-r', `${baseDir}/*`, 'spec');
2218
shell.cp(specPath, 'spec/openapi.yaml');
2319

2420
log.log("\nBundling API spec...");
25-
// try {
26-
// let schema = await $RefParser.bundle(specPath);
27-
// // console.log(schema);
28-
// console.log(YAML.stringify(schema.paths['/echo'].post.responses['200'].headers['X-Expires-After']));
29-
// }
30-
// catch(err) {
31-
// console.error(err);
32-
// }
3321
shell.exec(
34-
`npm run swagger bundle -- -o ${SWAGGER_JSON_PATH}`
22+
`npm run swagger bundle -- -o ${OPENAPI_JSON_PATH}`
3523
);
3624
shell.exec(
37-
`npm run swagger bundle -- --yaml -o ${SWAGGER_YAML_PATH}`
25+
`npm run swagger bundle -- --yaml -o ${OPENAPI_YAML_PATH}`
3826
);
3927
shell.rm('-rf', 'spec');
4028
};
4129

42-
// bundleSpec()
4330
module.exports.bundleSpec = bundleSpec;

lib/redoc-ui.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,20 @@ const Log = require('./log');
77

88
const log = new Log();
99

10-
var SHARED_UI_PATH = path.join(config.root, 'shared', config.redocRoot);
11-
var SWAGGER_YAML_PATH = path.join(config.branchPath, 'swagger.yaml');
12-
13-
const getAssets = function() {
14-
shell.rm('-rf', SHARED_UI_PATH);
15-
shell.mkdir('-p', SHARED_UI_PATH);
16-
};
10+
var OPENAPI_YAML_PATH = path.join(config.branchPath, 'openapi.yaml');
1711

1812
const setupUI = function() {
19-
getAssets()
20-
var uiPath = path.join(config.branchPath, config.redocRoot);
13+
var uiPath = path.join(config.branchPath, config.docsRoot);
2114
shell.mkdir('-p', uiPath);
2215
var indexPath = path.join(uiPath, 'index.html');
23-
log.log(`Generating ReDoc UI index at '${indexPath}'`);
16+
log.log(`Generating OpenAPI docs index at '${indexPath}'`);
2417
shell.exec(
25-
`npm run redoc -- ${SWAGGER_YAML_PATH} --output ${indexPath}`
18+
`npm run redoc -- ${OPENAPI_YAML_PATH} --output ${indexPath}`
2619
);
2720
log.preview({
28-
'title': 'ReDoc UI folder contents',
21+
'title': 'OpenAPI docs folder contents',
2922
'text': shell.ls(uiPath).stdout
3023
});
3124
};
3225

33-
// setupUI()
34-
module.exports.getAssets = getAssets;
3526
module.exports.setupUI = setupUI;

lib/tasks.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const Logger = require('./log');
33
const Config = require('./config');
44
const { fetchPages } = require('./gh-pages');
55
const { bundleSpec } = require('./bundle');
6-
// TODO: switch to setupUI exported from redoc-ui
7-
const { setupUI } = require('./swagger-ui');
6+
const { setupUI } = require('./redoc-ui');
87

98
const runTasks = function(opts, di) {
109
let container = {};
@@ -18,7 +17,7 @@ const runTasks = function(opts, di) {
1817

1918
console.log(container.config);
2019
log.obtrusive(`Preparing docs for API spec at '${container.config.apiSpecPath}' (${container.config.branch})`);
21-
fetchPages();
20+
// fetchPages();
2221
bundleSpec();
2322
setupUI();
2423

34.8 KB
Loading

test/test-spec/combined/openapi.yaml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ info:
1010
name: Apache 2.0
1111
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
1212
x-logo:
13-
url: 'https://apis.guru/openapi-template/logo.png'
13+
url: 'https://www.openapis.org/wp-content/uploads/sites/3/2018/02/OpenAPI_Logo_Pantone-1.png'
1414
description: >
1515
This is an **example** API to demonstrate features of OpenAPI specification
1616
@@ -59,23 +59,26 @@ tags:
5959
description: Example echo operations
6060
- name: User
6161
description: Operations about user
62-
- name: Motivation
62+
- name: Example Chapter
6363
description: |
64-
# Section 1
64+
# Overview
65+
66+
Here is an example of additional context that can be added with markdown.
67+
68+
## Basic syntax
69+
70+
You can use standard markdown tables and formatting
6571
6672
| Tables | Are | Cool |
6773
|----------|:-------------:|------:|
6874
| col 1 is | left-aligned | $1600 |
6975
| col 2 is | centered | $12 |
7076
| col 3 is | right-aligned | $1 |
7177
78+
## Images
7279
73-
<img style='float: right;' width='300' src='figure1.png'/>
74-
Data sharing requires portable data, consistent with the FAIR data
75-
principles (findable, accessible, interoperable, reusable). Today’s
76-
researchers and clinicians are surrounded by potentially useful data,
77-
but often need bespoke tools and processes to work with each dataset.
78-
And today’s data publishers don’t have a reliable way to make their data useful to all (and only) the people they choose."
80+
<img style='float: right;' width='250' src='../../../test/test-shared/OpenAPI_Logo_Pantone-1.png'/>
81+
This is a block of text arranged next to an image (hosted in this repo).
7982
8083
servers:
8184
- url: 'http://example.com/api/v1'
@@ -87,7 +90,7 @@ x-tagGroups:
8790
- User
8891
- name: Appendix
8992
tags:
90-
- Motivation
93+
- Example Chapter
9194
paths:
9295
/echo:
9396
post:

0 commit comments

Comments
 (0)