Skip to content

Commit 6e9b3cd

Browse files
authored
Merge pull request #521 from mulesoft/release/4.1.0
Release/4.1.0
2 parents 97d77c7 + c2f1dee commit 6e9b3cd

File tree

20 files changed

+9983
-151
lines changed

20 files changed

+9983
-151
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
language: node_js
2-
dist: trusty
32
node_js: stable
43
before_script:
5-
- npm install --silent bower polymer-cli
6-
- "./node_modules/.bin/bower install --silent"
4+
- bower install --silent
75
addons:
86
sauce_connect: true
97
script:
108
- npm run lint
11-
- ./node_modules/.bin/polymer test --plugin sauce --job-name "api-console:${TRAVIS_BRANCH}"
12-
--build-number=${TRAVIS_BUILD_NUMBER}
9+
- polymer test --plugin sauce --job-name "api-console:${TRAVIS_BRANCH}" --build-number=${TRAVIS_BUILD_NUMBER}
1310
cache:
1411
directories:
1512
- node_modules

api-console-request.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
redirects="{{redirects}}"
8080
source-message="{{sourceMessage}}"
8181
no-url-editor="{{noUrlEditor}}"
82+
base-uri="[[baseUri]]"
8283
on-api-console-request="_apiRequested"></raml-request-panel>
8384
<template is="dom-if" if="[[hasResponse]]">
8485
<response-view
@@ -220,7 +221,11 @@
220221
* Note that the editor is still in the DOM. This property just hiddes
221222
* it.
222223
*/
223-
noUrlEditor: Boolean
224+
noUrlEditor: Boolean,
225+
/**
226+
* Api's base URI.
227+
*/
228+
baseUri: String
224229
},
225230

226231
listeners: {

api-console.html

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@
6666
display: none !important;
6767
}
6868

69-
iron-pages {
69+
.main-content {
70+
min-height: 100%;
71+
@apply --api-console-main-container;
72+
}
73+
74+
.pages-content {
7075
height: 100%;
76+
@apply --api-console-pages-container;
7177
}
7278

7379
iron-pages>* {
@@ -93,6 +99,22 @@
9399
@apply(--layout-horizontal);
94100
}
95101
}
102+
103+
.powered-by {
104+
padding: 12px 0px;
105+
border-top: 1px rgba(0,0,0,0.24) solid;
106+
margin: 8px 12px 0 12px;
107+
}
108+
109+
a img {
110+
text-underline: none;
111+
}
112+
113+
a.attribution {
114+
display: inline-block;
115+
width: 177px;
116+
margin-left: 24px;
117+
}
96118
</style>
97119
<paper-drawer-panel responsive-width="860px" force-narrow="[[manualNavigation]]">
98120
<template is="dom-if" if="[[!manualNavigation]]">
@@ -109,20 +131,25 @@
109131
first-level-opened
110132
resources-opened
111133
documentation-opened></raml-path-selector>
112-
<content select="[nav-addon]"></content>
134+
<template is="dom-if" if="[[!noAttribution]]" restamp>
135+
<div class="powered-by">
136+
<a href="https://github.com/mulesoft/api-console" class="attribution" target="_blank">
137+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 818.9 148"><defs><style>.cls-1{fill:#424143;}.cls-2{font-size:60px;fill:#414042;font-family:OpenSans, Open Sans;}</style></defs><path class="cls-1" d="M436.08,12.57a61.79,61.79,0,1,0,62.08,61.79A62,62,0,0,0,436.08,12.57Zm0,118.8a56.63,56.63,0,1,1,56.63-56.63A56.63,56.63,0,0,1,436.09,131.36Z"/><path class="cls-1" d="M420.34,102.08a28.4,28.4,0,0,1-15.87-25.84,29.25,29.25,0,0,1,4.89-16.29l20.42,30.43h12.34l20.42-30.43a29.25,29.25,0,0,1,4.89,16.29,28.55,28.55,0,0,1-14,24.87l3.93,15.06a46.47,46.47,0,0,0,2.45-81.29L436.08,71.47,412.6,34.75A46.47,46.47,0,0,0,416.45,117Z"/><polygon class="cls-1" points="544.97 80.8 529.71 48.31 521.79 48.31 521.79 100.53 529.71 100.53 529.71 65.62 542.03 91.08 547.9 91.08 559.93 65.62 559.93 100.53 567.85 100.53 567.85 48.31 559.93 48.31 544.97 80.8"/><path class="cls-1" d="M597.61,86c0,5.73-3.53,8.29-7.7,8.29s-7.48-2.5-7.48-8.29V63.34h-7.48V87.11c0,4.19.88,7.71,3.74,10.5a12.93,12.93,0,0,0,9.17,3.37,13.28,13.28,0,0,0,9.9-4.18v3.74h7.34V63.34h-7.48Z"/><path class="cls-1" d="M619.75,89.83V48.31h-7.48v42c0,5.51,3.08,10.27,10.2,10.27h4.62V94.16h-3.3C620.77,94.16,619.75,92.68,619.75,89.83Z"/><path class="cls-1" d="M645.07,62.91c-9.54,0-15.77,7-15.77,19,0,14.16,7.41,19.07,16.73,19.07,6.53,0,10.12-2,13.93-5.79L655.2,90.7a11.08,11.08,0,0,1-9,3.81c-6.09,0-9.46-4-9.46-10.41h24.13V80.8C660.85,70.24,655.05,62.91,645.07,62.91Zm-8.36,16a11.79,11.79,0,0,1,1-5.06,7.77,7.77,0,0,1,7.41-4.69,7.66,7.66,0,0,1,7.34,4.69,11.62,11.62,0,0,1,1,5.06Z"/><path class="cls-1" d="M697.78,74.93c-2.2-2-4.91-3.15-9.76-3.89l-5.94-.88a11.67,11.67,0,0,1-5.87-2.42,6.24,6.24,0,0,1-2-4.84c0-4.62,3.37-8.15,9.54-8.15,4.4,0,8.14,1,11.37,4l5.06-5c-4.47-4.18-9.31-5.94-16.21-5.94-10.86,0-17.46,6.23-17.46,15.33,0,4.25,1.25,7.55,3.82,10,2.27,2.12,5.64,3.59,9.9,4.18l6.16.89c3.09.44,4.4,1,5.73,2.2a7,7,0,0,1,2.05,5.43c0,5.06-4,8-10.78,8-5.36,0-9.54-1.17-13.35-5l-5.28,5.21c5,5.06,10.64,6.9,18.48,6.9C694.18,101,702,95.25,702,85.65,702,81.16,700.63,77.43,697.78,74.93Z"/><path class="cls-1" d="M721.76,62.91a14.88,14.88,0,0,0-11.08,4.4c-3.52,3.66-4.4,8.36-4.4,14.6s.88,11,4.4,14.67a14.88,14.88,0,0,0,11.08,4.4,15,15,0,0,0,11.15-4.4c3.52-3.66,4.4-8.36,4.4-14.67s-.88-10.94-4.4-14.6A15,15,0,0,0,721.76,62.91Zm5.5,29.19a7.65,7.65,0,0,1-5.5,2.2,7.44,7.44,0,0,1-5.42-2.2c-2.28-2.27-2.57-6.17-2.57-10.2s.29-7.92,2.57-10.2a7.39,7.39,0,0,1,5.42-2.13,7.6,7.6,0,0,1,5.5,2.13c2.27,2.27,2.57,6.16,2.57,10.2S729.54,89.83,727.27,92.1Z"/><path class="cls-1" d="M744.88,58.29V64h-4.26v5.73h4.26v30.81h7.48V69.73h7.41V64h-7.41V58.65c0-2.71,1.31-4.33,4.1-4.33h3.31V47.94h-4.7C748.1,47.94,744.88,52.93,744.88,58.29Z"/><path class="cls-1" d="M776.12,52.71h-7.48V64h-4.26v5.73h4.26V90.19c0,5.36,3.22,10.35,10.19,10.35h4.47V94.16h-3.08c-2.78,0-4.11-1.62-4.11-4.33V69.73h7.19V64h-7.19Z"/><path class="cls-1" d="M792.58,58.48a4,4,0,0,0-2.14-2.11,4.11,4.11,0,0,0-3.11,0,4.07,4.07,0,0,0-1.29.84,4,4,0,0,0-.87,1.26,3.86,3.86,0,0,0-.32,1.58,3.94,3.94,0,0,0,.32,1.6,4,4,0,0,0,.87,1.28,4,4,0,0,0,1.29.84,4.19,4.19,0,0,0,3.11,0,3.92,3.92,0,0,0,1.28-.84,4.1,4.1,0,0,0,.87-1.28,4,4,0,0,0,.32-1.6A3.86,3.86,0,0,0,792.58,58.48Zm-.66,2.94a3.34,3.34,0,0,1-.7,1.09,3.25,3.25,0,0,1-1,.72,3.19,3.19,0,0,1-1.3.26,3.24,3.24,0,0,1-2.36-1,3.35,3.35,0,0,1-.7-1.09,3.64,3.64,0,0,1-.25-1.37,3.54,3.54,0,0,1,.25-1.34,3.26,3.26,0,0,1,3.06-2.06,3.21,3.21,0,0,1,1.3.26,3.26,3.26,0,0,1,1.74,1.8,3.52,3.52,0,0,1,.25,1.34A3.62,3.62,0,0,1,791.92,61.42Z"/><path class="cls-1" d="M790.42,60a1.14,1.14,0,0,0,.35-.93,1.23,1.23,0,0,0-.4-1,1.92,1.92,0,0,0-1.24-.33h-1.81v4.68H788v-2h.77l1.28,2h.78l-1.34-2.07A1.59,1.59,0,0,0,790.42,60Zm-1.61-.19H788V58.32h1l.37,0a1,1,0,0,1,.33.1.63.63,0,0,1,.24.21A.68.68,0,0,1,790,59a.79.79,0,0,1-.1.43.61.61,0,0,1-.27.23,1.19,1.19,0,0,1-.39.09Z"/><text class="cls-2" transform="translate(19 91.93)">Powered by</text></svg>
138+
</a>
139+
</div>
140+
</template>
113141
</div>
114142
</paper-header-panel>
115143
</template>
116144
<paper-header-panel main>
117145
<paper-toolbar>
118146
<paper-icon-button icon="arc:menu" paper-drawer-toggle hidden$="[[manualNavigation]]"></paper-icon-button>
119147
<div class="title">[[raml.title]]</div>
120-
<span class="flex"></span>
121148
<div class="nav-content">
122149
<content select="[nav]"></content>
123150
</div>
124151
</paper-toolbar>
125-
<div>
152+
<div class="main-content">
126153
<template is="dom-if" if="[[manualNavigation]]">
127154
<raml-path-selector opened$=[[navigationOpened]]
128155
narrow="[[narrow]]"
@@ -132,7 +159,7 @@
132159
resources-opened
133160
documentation-opened></raml-path-selector>
134161
</template>
135-
<iron-pages selected="[[page]]" attr-for-selected="name" role="main" id="mainPages">
162+
<iron-pages class="pages-content" selected="[[page]]" attr-for-selected="name" role="main" id="mainPages">
136163
<raml-documentation-panel
137164
name="docs"
138165
narrow="[[narrow]]"
@@ -152,8 +179,10 @@
152179
proxy="[[proxy]]"
153180
proxy-encode-url="[[proxyEncodeUrl]]"
154181
bower-location="[[bowerLocation]]"
155-
no-url-editor="{{noUrlEditor}}"></api-console-request>
182+
no-url-editor="{{noUrlEditor}}"
183+
base-uri="[[baseUri]]"></api-console-request>
156184
</iron-pages>
185+
<content select=".api-console-content"></content>
157186
</div>
158187
</paper-header-panel>
159188
</paper-drawer-panel>
@@ -285,7 +314,23 @@
285314
* Note that the editor is still in the DOM. This property just hiddes
286315
* it.
287316
*/
288-
noUrlEditor: Boolean
317+
noUrlEditor: Boolean,
318+
/**
319+
* A base URI for the API. To be set if RAML spec is missing `baseUri`
320+
* declaration and this produces invalid URL input. This information
321+
* is passed to the URL editor that prefixes the URL with `baseUri` value
322+
* if passed URL is a relative URL.
323+
*/
324+
baseUri: String,
325+
/**
326+
* Removes the "Powered by Mulesoft" attribution from the main navigation.
327+
* The use of this feature must be in accordance with all licensing
328+
* and copyright protections required by the use of this software
329+
*/
330+
noAttribution: {
331+
type: Boolean,
332+
value: false
333+
}
289334
},
290335

291336
listeners: {
@@ -392,7 +437,7 @@
392437
}
393438
},
394439
// Handler for the path changed event. Switches to docs if needed.
395-
_pathChangedEventHandler: function(e) {
440+
_pathChangedEventHandler: function() {
396441
if (this.page !== 'docs') {
397442
this.page = 'docs';
398443
}

bower.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"authors": [
55
"The Advanced REST client authors <[email protected]>"
66
],
7+
"version": "4.1.0",
78
"keywords": [
89
"web-components",
910
"polymer",
@@ -29,7 +30,7 @@
2930
"paper-icon-button": "PolymerElements/paper-icon-button#~1.1.0",
3031
"raml-aware": "advanced-rest-client/raml-aware#^1.0.2",
3132
"paper-toast": "PolymerElements/paper-toast#^1.3.0",
32-
"raml-request-panel": "advanced-rest-client/raml-request-panel#^0.1.0",
33+
"raml-request-panel": "advanced-rest-client/raml-request-panel#^0.2.1",
3334
"raml-documentation-panel": "advanced-rest-client/raml-documentation-panel#^2.0.9",
3435
"paper-progress": "PolymerElements/paper-progress#^1.0.11",
3536
"paper-button": "PolymerElements/paper-button#^1.0.14",
@@ -71,5 +72,7 @@
7172
"demo",
7273
"docs"
7374
],
74-
"version": "4.0.0"
75+
"resolutions": {
76+
"payload-parser-behavior": "0.2.1"
77+
}
7578
}

demo/api-selector/app.js

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/**
2+
* @license
3+
* Copyright 2017 The Advanced REST client authors <[email protected]>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
/**
16+
* The following script will handle API console routing when using the console as
17+
* a standalone application.
18+
*
19+
* It uses native JavaScript APIs so it can be used outside Polymer scope.
20+
*
21+
* @author Pawel Psztyc <[email protected]>
22+
*/
23+
(function() {
24+
'use strict';
25+
// API Console namespace.
26+
var apiconsole = {};
27+
// Namespace for standalone application.
28+
apiconsole.app = {};
29+
/**
30+
* Initialize event listeners for console's path and page properties and observers
31+
* router data change.
32+
*/
33+
apiconsole.app.init = function() {
34+
apiconsole.app.setInitialRouteData();
35+
apiconsole.app.addParserListeners();
36+
apiconsole.app.observeRouteEvents();
37+
apiconsole.app.observeApiToggle();
38+
apiconsole.app.loadDefault();
39+
};
40+
41+
apiconsole.app.setInitialRouteData = function() {
42+
// sets the initial path for routing from external source.
43+
// The API console sets default path to `summary` after RAML change.
44+
var location = document.querySelector('app-location');
45+
var locationPath = location.path;
46+
if (!locationPath) {
47+
return;
48+
}
49+
var parsedPath = locationPath.replace(/\-/g, '.');
50+
if (parsedPath[0] === '/') {
51+
parsedPath = parsedPath.substr(1);
52+
}
53+
var _route = parsedPath.split('/');
54+
var page = _route[0];
55+
var path = _route[1];
56+
57+
apiconsole.app.__initialPage = page;
58+
apiconsole.app.__initialPath = path;
59+
};
60+
/**
61+
* Adds event listeres to elements that are related to RAML dataq parsing.
62+
*/
63+
apiconsole.app.addParserListeners = function() {
64+
document.querySelector('raml-js-parser')
65+
.addEventListener('api-parse-ready', function(e) {
66+
document.querySelector('raml-json-enhance')
67+
.json = e.detail.json.specification;
68+
});
69+
70+
document.querySelector('paper-menu.api-menu')
71+
.addEventListener('selected-changed', function(e) {
72+
var url = e.detail.value;
73+
document.querySelector('raml-js-parser').loadApi(url);
74+
document.getElementById('loadingApi').active = true;
75+
});
76+
77+
window.addEventListener('raml-json-enhance-ready', function(e) {
78+
var apiConsole = document.querySelector('api-console');
79+
apiConsole.raml = e.detail.json;
80+
document.getElementById('loadingApi').active = false;
81+
if (apiconsole.app.__initialPage && apiconsole.app.__initialPage !== apiConsole.page) {
82+
apiconsole.app.pageChanged(apiconsole.app.__initialPage);
83+
apiconsole.app.__initialPage = undefined;
84+
}
85+
if (apiconsole.app.__initialPath && apiconsole.app.__initialPath !== apiConsole.path) {
86+
apiconsole.app.pathChanged(apiconsole.app.__initialPath);
87+
apiconsole.app.__initialPath = undefined;
88+
}
89+
});
90+
};
91+
/**
92+
* Adds event listeres to elements that are related to the routing:
93+
* app-location, app-route and api-console.
94+
*/
95+
apiconsole.app.observeRouteEvents = function() {
96+
var apiConsole = document.querySelector('api-console');
97+
var location = document.querySelector('app-location');
98+
99+
apiConsole.addEventListener('path-changed', apiconsole.app._pathChanged);
100+
apiConsole.addEventListener('page-changed', apiconsole.app._pageChanged);
101+
location.addEventListener('route-changed', apiconsole.app._routeChanged);
102+
};
103+
// Event handler for the path change.
104+
apiconsole.app._pathChanged = function(e) {
105+
apiconsole.app.pathChanged(e.detail.value);
106+
};
107+
// Called when path changed from the api-console.
108+
apiconsole.app.pathChanged = function(path) {
109+
if (!path) {
110+
return;
111+
}
112+
var location = document.querySelector('app-location');
113+
var parsedPath = path.replace(/\./g, '-');
114+
var newPath = '/docs/' + parsedPath;
115+
if (newPath !== location.path) {
116+
location.set('path', newPath);
117+
}
118+
};
119+
// Event handler for the page change.
120+
apiconsole.app._pageChanged = function(e) {
121+
apiconsole.app.pageChanged(e.detail.value);
122+
};
123+
// Called when page change.
124+
apiconsole.app.pageChanged = function(page) {
125+
var apiConsole = document.querySelector('api-console');
126+
if (apiConsole.page !== page) {
127+
apiConsole.page = page;
128+
}
129+
};
130+
// Event handler for the route change.
131+
apiconsole.app._routeChanged = function(e) {
132+
apiconsole.app.routeChanged(e.detail.value);
133+
};
134+
// Updates api console path if different than curent URL
135+
apiconsole.app.routeChanged = function(route) {
136+
var locationPath = route.path;
137+
if (!locationPath || locationPath === '/') {
138+
document.querySelector('app-location').set('path', '/docs');
139+
return;
140+
}
141+
var parsedPath = locationPath.replace(/\-/g, '.');
142+
if (parsedPath[0] === '/') {
143+
parsedPath = parsedPath.substr(1);
144+
}
145+
var _route = parsedPath.split('/');
146+
var page = _route[0];
147+
var path = _route[1];
148+
var apiConsole = document.querySelector('api-console');
149+
if (apiConsole.page !== page) {
150+
apiConsole.page = page;
151+
}
152+
if (apiConsole.path !== path) {
153+
apiConsole.path = path;
154+
}
155+
};
156+
/**
157+
* Reads page name and the path from location path.
158+
*
159+
* @param {String} locationPath Current path read from path change event or read fomr the
160+
* `app-location` element.
161+
*/
162+
apiconsole.app._readPagePath = function(locationPath) {
163+
var parsedPath = locationPath.replace(/\-/g, '.');
164+
if (parsedPath[0] === '/') {
165+
parsedPath = parsedPath.substr(1);
166+
}
167+
var _route = parsedPath.split('/');
168+
var page = _route[0];
169+
var path = _route[1];
170+
return {
171+
page: page,
172+
path: path
173+
};
174+
};
175+
176+
apiconsole.app.observeApiToggle = function() {
177+
document.getElementById('apiSelectorToggle')
178+
.addEventListener('tap', function() {
179+
document.querySelector('.api-console-content')
180+
.classList.toggle('closed');
181+
});
182+
};
183+
184+
apiconsole.app.loadDefault = function() {
185+
var url = document.querySelector('paper-menu.api-menu').selected;
186+
document.querySelector('raml-js-parser').loadApi(url);
187+
document.getElementById('loadingApi').active = true;
188+
};
189+
190+
// Notifys user when something went wrong...
191+
apiconsole.app.notifyInitError = function(message) {
192+
window.alert('Cannot initialize API console. ' + message);
193+
};
194+
apiconsole.app.init();
195+
})();

0 commit comments

Comments
 (0)