Skip to content

Commit

Permalink
[hotfix]Fixed website rest api select version error (apache#7192)
Browse files Browse the repository at this point in the history
### Motivation

Rest API version selection error -> http://pulsar.apache.org/admin-rest-api/?version=2.5.2


### Modifications

* Fixed route path
* Fixed URL 
* Add API version

### Verifying this change

Local test pass
  • Loading branch information
tuteng authored Jun 8, 2020
1 parent ee0ba4c commit 7d4c23b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
53 changes: 38 additions & 15 deletions site2/website/static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

window.addEventListener('load', function () {
let restApiVersions = null;
var url = "../../../swagger/restApiVersions.json";
var url = "../../../../swagger/restApiVersions.json";
var request = new XMLHttpRequest();
request.open("get", url, false);
request.send(null);
Expand Down Expand Up @@ -46,17 +46,41 @@ window.addEventListener('load', function () {
version = 'master'
}

let adminApiVersion = ''
if (restApiVersions[version][0]['fileName'].indexOf('swagger') == 0) {
adminApiVersion = restApiVersions[version][0]['version']
} else {
adminApiVersion = restApiVersions[version][1]['version']
}
let functionApiVersion = ''
if (restApiVersions[version][0]['fileName'].indexOf('swaggerfunctions') >= 0) {
functionApiVersion = restApiVersions[version][0]['version']
} else {
functionApiVersion = restApiVersions[version][1]['version']
}
let sourceApiVersion = ''
if (restApiVersions[version][0]['fileName'].indexOf('swaggersource') >= 0) {
sourceApiVersion = restApiVersions[version][0]['version']
} else {
sourceApiVersion = restApiVersions[version][1]['version']
}
let sinkApiVersion = ''
if (restApiVersions[version][0]['fileName'].indexOf('swaggersink') >= 0) {
sinkApiVersion = restApiVersions[version][0]['version']
} else {
sinkApiVersion = restApiVersions[version][1]['version']
}
// setup rest api menu items in nav bar
const restapis = document.querySelector("a[href='#restapis']").parentNode;
const restapisMenu =
'<li>' +
'<a id="restapis-menu" href="#">REST APIs <span style="font-size: 0.75em">&nbsp;▼</span></a>' +
'<a id="restapis-menu" href="#restapis">REST APIs <span style="font-size: 0.75em">&nbsp;▼</span></a>' +
'<div id="restapis-dropdown" class="hide">' +
'<ul id="restapis-dropdown-items">' +
'<li><a href="/admin-rest-api?version=' + version + '&apiversion=">Admin REST API </a></li>' +
'<li><a href="/functions-rest-api?version=' + version + '&apiversion=">Functions </a></li>' +
'<li><a href="/source-rest-api?version=' + version + '&apiversion=">Sources </a></li>' +
'<li><a href="/sink-rest-api?version=' + version + '&apiversion=">Sinks </a></li>' +
'<li><a href="/admin-rest-api?version=' + version + '&apiversion=' + adminApiVersion + '">Admin REST API </a></li>' +
'<li><a href="/functions-rest-api?version=' + version + '&apiversion=' + functionApiVersion + '">Functions </a></li>' +
'<li><a href="/source-rest-api?version=' + version + '&apiversion=' + sourceApiVersion + '">Sources </a></li>' +
'<li><a href="/sink-rest-api?version=' + version + '&apiversion=' + sinkApiVersion + '">Sinks </a></li>' +
'</ul>' +
'</div>' +
'</li>';
Expand Down Expand Up @@ -154,27 +178,26 @@ window.addEventListener('load', function () {
let hasSink = ele.fileName.find(h => h == 'swaggersink');
let hasSource = ele.fileName.find(h => h == 'swaggersource');

if ( pathName === '/admin-rest-api' && hasRestApi ) {
if ( pathName.indexOf('/admin-rest-api') >= 0 && hasRestApi ) {
apiVersionList.push(ele);
}
if ( pathName === '/functions-rest-api' && hasFunctions ) {
if ( pathName.indexOf('/functions-rest-api') >= 0 && hasFunctions ) {
apiVersionList.push(ele);
}
if ( pathName === '/sink-rest-api' && hasSink ) {
if ( pathName.indexOf('/sink-rest-api') >= 0 && hasSink ) {
apiVersionList.push(ele);
}
if ( pathName === '/source-rest-api' && hasSource ) {
if ( pathName.indexOf('/source-rest-api') >= 0 && hasSource ) {
apiVersionList.push(ele);
}
});


const wrapperDiv = document.querySelectorAll('.wrapper')[1];

if (pathName === '/admin-rest-api'
|| pathName === '/functions-rest-api'
|| pathName === '/source-rest-api'
|| pathName === '/sink-rest-api') {
if (pathName.indexOf('/admin-rest-api') >= 0
|| pathName.indexOf('/functions-rest-api') >= 0
|| pathName.indexOf('/source-rest-api') >= 0
|| pathName.indexOf('/sink-rest-api') >= 0) {
wrapperDiv.innerHTML = `<select name="apiVersion" class="version_select" id="version_select">
${apiVersionList.map(v => `<option value="${v.version}">${v.version}</option>`).join("")}
</select>`;
Expand Down
9 changes: 0 additions & 9 deletions site2/website/static/js/getSwaggerByVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ function getSwaggerByVersion(){
const wrapper = document.querySelector('.pageContainer .wrapper')
const redoc = document.createElement('redoc');

let options = document.querySelector('#version_select').querySelectorAll('option');
let optionList = [];
options.forEach(ele => {
optionList.push(ele.value);
})

if (!optionList.find(o => apiversion == o)) {
apiversion = optionList[0];
}

if (pathName.indexOf('admin-rest-api') >= 0) {
redoc.setAttribute('spec-url', '/swagger/' + version + '/' + apiversion + '/swagger.json')
Expand Down

0 comments on commit 7d4c23b

Please sign in to comment.