Skip to content

Commit

Permalink
Add package management REST API show in doc (apache#8896)
Browse files Browse the repository at this point in the history
---

Master Issue: apache#8676

*Motivation*

Show REST API examples in the website.

*Modifications*

Add website related changes for package management REST APIs.

*ScreenShot*

![Screen Shot 2020-12-10 at 5 25 18 PM](https://user-images.githubusercontent.com/24502569/101753478-a42da300-3b0d-11eb-9aa9-ec07f0354ee8.png)
  • Loading branch information
zymap authored Dec 11, 2020
1 parent d08ac1d commit 9937d45
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
17 changes: 17 additions & 0 deletions pulsar-broker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,23 @@
<swaggerDirectory>${basedir}/target/docs</swaggerDirectory>
<swaggerFileName>swaggersink</swaggerFileName>
</apiSource>
<apiSource>
<springmvc>false</springmvc>
<locations>org.apache.pulsar.broker.admin.v3.Packages</locations>
<schemes>http,https</schemes>
<basePath>/admin/v3</basePath>
<info>
<title>Pulsar Packages REST API</title>
<version>v3</version>
<description>This provides the REST API for Pulsar Packages operations</description>
<license>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<name>Apache 2.0</name>
</license>
</info>
<swaggerDirectory>${basedir}/target/docs</swaggerDirectory>
<swaggerFileName>swaggerpackages</swaggerFileName>
</apiSource>
</apiSources>
</configuration>
<executions>
Expand Down
21 changes: 21 additions & 0 deletions site2/website/pages/en/packages-rest-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const React = require('react');
const CompLibrary = require('../../core/CompLibrary.js');

const Container = CompLibrary.Container;
const siteConfig = require(`${process.cwd()}/siteConfig.js`);

class PackagesRestApi extends React.Component {
render() {
const swaggerUrl = `${siteConfig.baseUrl}swagger/swaggerpackages.json`

return (
<div className="pageContainer">
<Container className="mainContainer documentContainer postContainer" >
<script base-url={`${swaggerUrl}`} src="../js/getSwaggerByVersion.js"></script>
</Container>
</div>
);
}
}

module.exports = PackagesRestApi;
3 changes: 3 additions & 0 deletions site2/website/siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const createVariableInjectionPlugin = variables => {
return renderUrl(initializedPlugin, sourceApiUrl + "#", keyparts);
} else if (keyparts[0] == 'sink') {
return renderUrl(initializedPlugin, sinkApiUrl + "#", keyparts);
} else if (keyparts[0] == 'packages') {
return renderUrl(initializedPlugin, packagesApiUrl + "#", keyparts);
} else {
keyparts = key.split("|");
// endpoint api: endpoint|<op>
Expand Down Expand Up @@ -92,6 +94,7 @@ const restApiUrl = url + "/admin-rest-api";
const functionsApiUrl = url + "/functions-rest-api";
const sourceApiUrl = url + "/source-rest-api";
const sinkApiUrl = url + "/sink-rest-api";
const packagesApiUrl = url + "/packages-rest-api";
const githubUrl = 'https://github.com/apache/incubator-pulsar';
const baseUrl = '/';

Expand Down
12 changes: 10 additions & 2 deletions site2/website/static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ window.addEventListener('load', function () {
} else {
sinkApiVersion = restApiVersions[version][1]['version']
}
let packagesApiVersion = ''
if (restApiVersions[version][0]['fileName'].indexOf('swaggerpackages') >= 0) {
packagesApiVersion = restApiVersions[version][0]['version']
} else {
packagesApiVersion = restApiVersions[version][1]['version']
}
// setup rest api menu items in nav bar
const restapis = document.querySelector("a[href='#restapis']").parentNode;
const restapisMenu =
Expand All @@ -81,6 +87,7 @@ window.addEventListener('load', function () {
'<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>' +
'<li><a href="/packages-rest-api?version=' + version + '&apiversion=' + packagesApiVersion + '">Packages </a></li>' +
'</ul>' +
'</div>' +
'</li>';
Expand Down Expand Up @@ -197,7 +204,8 @@ window.addEventListener('load', function () {
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) {
|| pathName.indexOf('/sink-rest-api') >= 0
|| pathName.indexOf('/packages-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 Expand Up @@ -233,4 +241,4 @@ window.addEventListener('load', function () {

})

});
});
4 changes: 3 additions & 1 deletion site2/website/static/js/getSwaggerByVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function getSwaggerByVersion(){
redoc.setAttribute('spec-url', '/swagger/' + version + '/' + apiversion + '/swaggersource.json')
} else if (pathName.indexOf('sink-rest-api') >= 0) {
redoc.setAttribute('spec-url', '/swagger/' + version + '/' + apiversion + '/swaggersink.json')
} else if (pathName.indexOf('packages-rest-api' >= 0)) {
redoc.setAttribute('spec-url', '/swagger/' + version + '/' + apiversion + '/swaggerpackages.json')
}
redoc.setAttribute('lazy-rendering', 'true')
const redocLink = document.createElement('script');
Expand All @@ -58,4 +60,4 @@ function getSwaggerByVersion(){
wrapper.insertBefore(redocLink, script)

}
window.onload=getSwaggerByVersion
window.onload=getSwaggerByVersion

0 comments on commit 9937d45

Please sign in to comment.