Skip to content

Commit

Permalink
[website]Support multi version for swagger (apache#5032)
Browse files Browse the repository at this point in the history
* Support multi version for admin rest api

* Support multi for functions, source and sinks rest api

* Default version is master

* generate swagger file for multi version

* Generate swagger json for multi api

* Add comment for copy file

* Generate swagger file only to master
  • Loading branch information
tuteng authored and merlimat committed Aug 29, 2019
1 parent a4cfcd7 commit f7aad57
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
5 changes: 2 additions & 3 deletions site2/website/pages/en/admin-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ const siteConfig = require(`${process.cwd()}/siteConfig.js`);

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

const swaggerUrl = `${siteConfig.baseUrl}swagger/swagger.json`
return (
<div className="pageContainer">
<Container className="mainContainer documentContainer postContainer" >
<redoc spec-url={`${swaggerUrl}`} lazy-rendering="true"></redoc>
<script src="https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"></script>
<script base-url={`${swaggerUrl}`} src="js/getSwaggerByVersion.js"></script>
</Container>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions site2/website/pages/en/functions-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class FunctionsRestApi extends React.Component {
return (
<div className="pageContainer">
<Container className="mainContainer documentContainer postContainer" >
<redoc spec-url={`${swaggerUrl}`} lazy-rendering="true"></redoc>
<script src="https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"></script>
<script base-url={`${swaggerUrl}`} src="js/getSwaggerByVersion.js"></script>
</Container>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions site2/website/pages/en/sink-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class SinkRestApi extends React.Component {
return (
<div className="pageContainer">
<Container className="mainContainer documentContainer postContainer" >
<redoc spec-url={`${swaggerUrl}`} lazy-rendering="true"></redoc>
<script src="https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"></script>
<script base-url={`${swaggerUrl}`} src="js/getSwaggerByVersion.js"></script>
</Container>
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions site2/website/pages/en/source-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class SourceRestApi extends React.Component {
return (
<div className="pageContainer">
<Container className="mainContainer documentContainer postContainer" >
<redoc spec-url={`${swaggerUrl}`} lazy-rendering="true"></redoc>
<script src="https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"></script>
<script base-url={`${swaggerUrl}`} src="js/getSwaggerByVersion.js"></script>
</Container>
</div>
);
Expand Down
15 changes: 11 additions & 4 deletions site2/website/static/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,24 @@ window.addEventListener('load', function() {
}
});

const href = document.querySelector('a[href="/en/versions"]');
let version = href.textContent;

if (version === 'next') {
version = 'master'
}

// 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>' +
'<div id="restapis-dropdown" class="hide">' +
'<ul id="restapis-dropdown-items">' +
'<li><a href="/admin-rest-api">Admin REST API </a></li>' +
'<li><a href="/functions-rest-api">Functions </a></li>' +
'<li><a href="/source-rest-api">Sources </a></li>' +
'<li><a href="/sink-rest-api">Sinks </a></li>' +
'<li><a href="/admin-rest-api?version=' + version + '">Admin REST API </a></li>' +
'<li><a href="/functions-rest-api?version=' + version + '">Functions </a></li>' +
'<li><a href="/source-rest-api?version=' + version + '">Sources </a></li>' +
'<li><a href="/sink-rest-api?version=' + version + '">Sinks </a></li>' +
'</ul>' +
'</div>' +
'</li>';
Expand Down
24 changes: 24 additions & 0 deletions site2/website/static/js/getSwaggerByVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function getSwaggerByVersion(){
var params = window.location.search
params = params.replace('?', '')
const paramsList = params.split('&')
var version = 'master'
for (var i in paramsList) {
var param = paramsList[i].split('=')
if (param[0] === 'version') {
version = param[1]
}
}
const wrapper = document.querySelector('.pageContainer .wrapper')
const redoc = document.createElement('redoc');
redoc.setAttribute('spec-url', '/swagger/' + version + '/swagger.json')
redoc.setAttribute('lazy-rendering', 'true')
const redocLink = document.createElement('script');
redocLink.setAttribute('src', 'https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js')
const script = document.querySelector('.pageContainer .wrapper script')

wrapper.insertBefore(redoc, script)
wrapper.insertBefore(redocLink, script)

}
window.onload=getSwaggerByVersion
9 changes: 5 additions & 4 deletions src/gen-swagger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ PULSAR_PATH=$(git rev-parse --show-toplevel)

cd $PULSAR_PATH

echo "Generating swagger json file ..."
git checkout master
echo "Generating swagger json file for master ..."
mvn -am -pl pulsar-broker install -DskipTests -Pswagger
echo "Swagger json file is generated."
echo "Swagger json file is generated for master."

cp pulsar-broker/target/docs/swagger*.json site2/website/static/swagger/
echo "Copied swagger json file."
cp pulsar-broker/target/docs/swagger*.json site2/website/static/swagger/master/
echo "Copied swagger json file for master."

0 comments on commit f7aad57

Please sign in to comment.