Skip to content

Commit ef2d91c

Browse files
authored
Merge pull request #536 from mulesoft/release/4.2.0
Release/4.2.0
2 parents 6e9b3cd + 165aede commit ef2d91c

File tree

10 files changed

+242
-88
lines changed

10 files changed

+242
-88
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<a name="4.2.0"></a>
2+
# [4.2.0](https://github.com/mulesoft/api-console/compare/v4.1.0...v4.2.0) (2017-10-25)
3+
4+
- Changed behavior of the `baseUri` property as described in [#535](https://github.com/mulesoft/api-console/issues/535)
5+
- Added this changelog
6+
- Many bug fixes in the internal web components
7+
8+
# [4.1.0](https://github.com/mulesoft/api-console/compare/v4.0.0...v4.1.0) (2017-08-17)
9+
10+
- New: Support for sending files
11+
- New: Added demo page for adding distributed content into the console.
12+
- New: Added demo page for selecting an API version inside the console.
13+
- New: Added `noAttribution` option. Attribution is now part of the console instead of the builder.
14+
- Update: redesign of the "body" editor in the request editor
15+
- Fix: Console is not completing the path whit host and port when Base URI set relative #502
16+
- Fix: Title of the API is not fully displayed #519
17+
- Fix: Add ability to add custom content to the console element as a distributed child #520
18+
- Fix: How to enter application/x-www-form-urlencoded for a post body? #374
19+
- Fix: No feedback for file type #199
20+
- Update: Updated demo pages of the console. See `demo` folder for more information

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
**See live example of the API console in our [demo application].**
2+
13
# The API Console
24

35
MuleSoft's API Console is a full-fledged API documentation tool that generates mobile-friendly web documentation based on RAML (Restful API Modeling Language) documents. In addition to providing documentation, the tool provides the capability for users to try out requests on the fly.
46

57
[![API Console](docs/new-console-header.png)](https://mulesoft.github.io/api-console)
68

7-
**See live example of the API console in our [demo application].**
8-
99
## Introduction
1010

1111
In this repository, you can find the source for a single HTML element that represents API Console.
@@ -16,6 +16,26 @@ The following sections briefly describe how to build and use the console. For mo
1616

1717
## Using the API console
1818

19+
Install our CLI tool globally using `-g` if possible:
20+
21+
```shell
22+
$ sudo npm install -g api-console-cli
23+
```
24+
25+
Generate API console from your RAML file:
26+
27+
```shell
28+
$ api-console build https://domain.com/api.raml # works with local files too
29+
```
30+
31+
Preview the console:
32+
33+
```shell
34+
$ api-console serve build/
35+
```
36+
37+
That's all you need to build the API console for your API. Below we'll describe how to customize the console.
38+
1939
API Console comes in two flavors.
2040

2141
* A **standalone web-application**

bower.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"authors": [
55
"The Advanced REST client authors <[email protected]>"
66
],
7-
"version": "4.1.0",
7+
"version": "4.2.0",
88
"keywords": [
99
"web-components",
1010
"polymer",
@@ -30,7 +30,7 @@
3030
"paper-icon-button": "PolymerElements/paper-icon-button#~1.1.0",
3131
"raml-aware": "advanced-rest-client/raml-aware#^1.0.2",
3232
"paper-toast": "PolymerElements/paper-toast#^1.3.0",
33-
"raml-request-panel": "advanced-rest-client/raml-request-panel#^0.2.1",
33+
"raml-request-panel": "advanced-rest-client/raml-request-panel#^0.3.2",
3434
"raml-documentation-panel": "advanced-rest-client/raml-documentation-panel#^2.0.9",
3535
"paper-progress": "PolymerElements/paper-progress#^1.0.11",
3636
"paper-button": "PolymerElements/paper-button#^1.0.14",
@@ -71,8 +71,5 @@
7171
"tasks",
7272
"demo",
7373
"docs"
74-
],
75-
"resolutions": {
76-
"payload-parser-behavior": "0.2.1"
77-
}
74+
]
7875
}

docs/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# API Console documentation
22

33
Select a topic
4-
- [API Console element documentation](api-console-element.md)
5-
- [API Console build tools](build-tools.md)
6-
- [API Console configuration options](configuring-api-console.md)
7-
- [Building API Console for GitHub pages on Travis](gh-pages.md)
8-
- [Handling CORS](cors.md)
9-
- [Passing RAML to the API Console](passing-raml-data.md)
10-
- [Rebuilding the api.json file in the CI process](rebuilding-api-json.md)
11-
- [Styling the API Console](theming.md)
4+
- [Starting guide to web components](web-components.md)
5+
- [API Console element documentation](api-console-element.md)
6+
- [API Console build tools](build-tools.md)
7+
- [API Console configuration options](configuring-api-console.md)
8+
- [Building API Console for GitHub pages on Travis](gh-pages.md)
9+
- [Handling CORS](cors.md)
10+
- [Passing RAML to the API Console](passing-raml-data.md)
11+
- [Rebuilding the api.json file in the CI process](rebuilding-api-json.md)
12+
- [Styling the API Console](theming.md)

docs/configuring-api-console.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ The following table describes HTML attributes.
4141
| `manual-navigation` | Disables navigation in the drawer and renders the navigation full screen when requested. Use in the narrow layouts with the `narrow` property. Set the `navigationOpened` property to `true` or `false` to open/close the navigation. | `Boolean` |
4242
| `navigation-opened` | If set, the `manual-navigation` attribute is set, and the full screen navigation will open/close. | `Boolean` |
4343
| `bower-location` | If the path to the `bower_components` is different than default (in the root path) then set this attribute to point the location of the folder, including folder name. | `String` |
44-
| `no-url-editor` | If set, the URL editor is hidden in the Try it panel. The editor is still attached to the DOM but it's invisible to the user. | `Boolean`
44+
| `no-url-editor` | If set, the URL editor is hidden in the Try it panel. The editor is still attached to the DOM but it's invisible to the user. | `Boolean` |
45+
| `base-uri` | Used to replace RAML's base URI. Once set it updates the request URL in the request panel (try it). The URL will always contain the same base URL until the attribute is cleared (removed, set to `null`, `undefined` or `false`) | `String`
46+
4547

4648
## Controlling the view
4749

docs/passing-raml-data.md

Lines changed: 103 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,108 @@
11
# Passing the RAML data
22

3-
## Before you begin: asynchronous environment
3+
The default version of the **API console does not contain the RAML parser**. It is by design to minimize the size of the console and to optimize startup time.
44

5-
Web components are asynchronous by nature. Importing the elements,
6-
registering them in the DOM, and finally initializing an element is done asynchronously. Therefore, you can't expect the element to work immediately after loading the page as a typical HTML element does. Consider the following example:
5+
You can use the console with the RAML parser by setting up the build / CLI tools or by adding the dependency manually. **This document describes why the parser has been removed from the core console code and how to use the parser with new console.**
76

8-
```html
9-
<link rel="import" href="bower_components/raml-js-parser/raml-js-parser.html">
10-
<raml-js-parser json></raml-js-parser>
11-
<script>
12-
var parser = document.querySelector('raml-js-parser');
13-
parser.loadApi(apiFileUrl);
14-
</script>
15-
```
7+
## Performance of the API console
168

17-
Running this code as the page loads throws a `TypeError` with the message: `parser.loadApi is not a function`.
9+
One of the challenges standing before us when we started developing version 4 of the API console was the performance. This is wide area so here we'll limit it to size of the source code and initial start time.
1810

19-
At the time of execution of this script block, the browser knows nothing about the `raml-js-parser` element. At this time, the element is an instance of `HTMLUnknownElement`.
11+
Before we go into detailed performance issues description read why we use the enhancer alongside the JS parser.
2012

21-
The browser has to import the source of the element first, and then the Polymer library has to register custom HTML element called `raml-js-parser`.
2213

23-
To run the code properly you have to listen for the `WebComponentsReady` event. It's fired when the elements are ready to use.
14+
### RAML <> JavaScript enhancer
15+
16+
As you may already know the API console consists of over 150 web components. They are responsible for displaying the documentation, rendering the request and response panels in the "try it" function and to make test requests to an endpoint.
17+
18+
[RAML's JavaScript parser][5] has been created to give access to RAML document's [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree). It is very inconvenient to use it with HTML templating systems (like Polymer's or Angular's). The parser simply hasn't been created for this use case. Apart from offering the AST the parser produces a JavaScript object. The object can be used in many cases in JavaScript environment. However the output is not as helpful in the world of web components.
19+
20+
The components serves one purpose and are responsible for a single task in the API console. For example there is an element that renders annotation added to a type only. Because of that not every element need to have access to full RAML description. It only uses part of the documentation that it is going to use. Parser's JavaScript output gives literally translated YAML structure to a JavaScript object. It means that if you, for example, declare a type on a `body` declaration as a name of previously defined type on the root of the RAML document, the parser's output is this name and not the type definition. Therefore parser JavaScript output requires additional transformations before it can be used with web components architecture.
21+
22+
For the API Console we use our fork of the [raml2obj][11] library as a base transformer. With the [expansion library][12] we've created an web component [raml-json-enhance][3] and node module [raml-json-enhance-node][4] that transforms parser's output to a form that can be used with the components of the API console.
23+
24+
Output of the enhancer is then to be used as an input data of the API console. Use of the enhancer also allowed us to minimize code base of all the web components because they don't need to contain code to compute missing properties.
25+
26+
### Console source size
27+
28+
The first issue is the size of the console. When you install dependencies of the console it turns out that the whole project is about 40MB (excluding `node_modules`). That's a lot but this is a development version of the console.
29+
We have prepared a [build tools][1] for the console, that works on top of Polymer's [build tools][1] to produce production ready version of the console. With optimization option enabled (default behavior) it produces a single file with all web components definitions concatenated to a single 2MB file. It is still quite a lot but so far we were able to reduce the code to this size.
30+
31+
### Console startup time
32+
33+
Big issue for the API console in version < 4.0.0 was startup time. Each time the console was loaded into the browser it had to download all RAML sources, parse it and then render the console based on JavaScript parser output. In many cases two first steps are simply redundant. If the API specification doesn't change very often there's no reason to parse the RAML each time the console is opened. We've replaced this part with prebuilt of the parser's output file that contains transformed RMAL data. In case of huge and complicated APIs it can significantly reduce startup time.
34+
35+
Separation of the data source and the API console has additional advantage. In new architecture, when source RAML changes you can just rebuild the JSON file with new data instead of rebuilding the console. This speeds up publish time of new API an can be easily automated in your [CI pipeline][10].
36+
37+
Our [build tools][1] gives you options to include the parser and enhancer to the final build so, depending on your use case, you can optimize startup time of the console.
38+
39+
## Installing parser and enhancer
40+
41+
You can install parser and enhancer in your project by calling [bower][9] command:
2442

25-
```html
26-
<link rel="import" href="bower_components/raml-js-parser/raml-js-parser.html">
27-
<raml-js-parser json></raml-js-parser>
28-
<script>
29-
function init() {
30-
var parser = document.querySelector('raml-js-parser');
31-
parser.loadApi(apiFileUrl);
32-
};
33-
window.addEventListener('WebComponentsReady', init);
34-
</script>
43+
```
44+
$ bower install --save advanced-rest-client/raml-json-enhance advanced-rest-client/raml-js-parser
3545
```
3646

37-
## JSON instead of RAML
47+
You can use `package.json` script declaration for the same command:
3848

39-
The API console web component requires a JavaScript object produced by the [raml-js-parser] and [raml-js-enhance] elements. Parsing and enhancing RAML is not part of the `api-console` element and must be performed separately as described below.
49+
```json
50+
"scripts": {
51+
"install-parser": "bower install --save advanced-rest-client/raml-json-enhance advanced-rest-client/raml-js-parser"
52+
}
53+
```
54+
```
55+
$ npm run install-parser
56+
```
4057

41-
**Head's up!** You can use our [build tools] to generate the JSON file from the RAML in Node (using node modules) and Shell (with the API Console CLI tool).
58+
Or in combination with installation of the console:
4259

43-
Use the [raml-js-parser] element to parse YAML data or to download RAML from a remote location. __Note__: You may also use our [raml-js-parser-2] node library as it yields the same output.
60+
```
61+
$ bower install --save mulesoft/api-console advanced-rest-client/raml-json-enhance advanced-rest-client/raml-js-parser
62+
```
4463

45-
Then, you **must** use the [raml-js-enhance] element to produce data output that is recognizable by the `api-console`. The enhancer creates a common data structure and expands RAML types by flattening any type having a complex inheritance structure.
64+
It installs source files in `bower_components` directory. You can then reference those files in the `import` directive. After the components are imported and registered you can use them as described in our [web components guide][2].
4665

47-
Elements used to build API Console expect the JSON object to contain complete data about a method / endpoint / type / security scheme and so on. They do not look into nor have access to the data in the root of RAML definition. The enhancer replaces objects with arrays, adding a `key` property to each item, for use in a templating system. Also, the `example` property of the RAML is always translated to an `examples` array. Finally, the enhancer creates a `fullUrl` property on each HTTP method so the console doesn't need to compute it each time you open the documentation page.
66+
Also check out our usage guide of the `<api-console>` element in our [element's guide][8].
4867

49-
#### Example: parsing and enhancing RAML
68+
### Example use of parser and enhancer
5069

5170
```html
71+
<link rel="import" href="bower_components/raml-js-parser/raml-js-parser.html">
72+
<link rel="import" href="bower_components/raml-json-enhance/raml-json-enhance.html">
73+
<link rel="import" href="bower_components/api-console/api-console.html">
74+
5275
<raml-js-parser json></raml-js-parser>
5376
<raml-json-enhance></raml-json-enhance>
77+
<api-console></api-console>
78+
5479
<script>
55-
var parser = document.querySelector('raml-js-parser');
56-
parser.addEventListener('api-parse-ready', function(e) {
57-
var enhacer = document.querySelector('raml-json-enhance');
58-
enhacer.json = e.detail.json.specification;
59-
});
60-
window.addEventListener('raml-json-enhance-ready', function(e) {
61-
// The e.detail.json contains the final JavaScript object
62-
console.log(e.detail.json);
63-
});
64-
function init() {
65-
parser.loadApi(apiFileUrl);
80+
var MyAPiApp = {
81+
init: function() {
82+
var parser = document.querySelector('raml-js-parser');
83+
parser.addEventListener('api-parse-ready', MyAPiApp._ramlReady);
84+
parser.loadApi('https://domain.com/api.raml');
85+
window.addEventListener('raml-json-enhance-ready', MyAPiApp._jsonReady);
86+
},
87+
88+
_ramlReady: function(e) {
89+
var enhacer = document.querySelector('raml-json-enhance');
90+
enhacer.json = e.detail.json.specification;
91+
},
92+
93+
_jsonReady: function(e) {
94+
// The e.detail.json contains the final JavaScript object
95+
var apiConsole = document.querySelector('api-console');
96+
apiConsole.raml = e.detail.json;
97+
}
6698
};
67-
window.addEventListener('WebComponentsReady', init);
99+
window.addEventListener('WebComponentsReady', MyAPiApp.init);
68100
</script>
69101
```
70102

71-
1) After the elements are initialized, the`WebComponentsReady` event occurs and calls the `loadApi()` function on the [raml-js-parser] element.
72-
2) The element fires the `api-parse-ready` custom event that should be handled by the application and the result of parsing (`e.detail.json.specification`) should be passed to the enhancer's `json` property.
73-
3) When the enhancer transforms the object, it fires the `raml-json-enhance-ready` custom event. The result is in the `e.detail.json` property.
103+
The `json` attribute set on `raml-js-parser` element tells the parser that the output should be a JavaScript object instead of the AST.
74104

75-
Parsing and enhancing can consumes significant system resources, depending on the RAML structure and number of referenced files. It is a good idea to do perform these operations once and cache the results. Then, when the user visits the page again, restore the cached JSON object, and pass it as the `api-console` parameter as discussed below.
76-
77-
### Setting RAML data as an HTML attribute
105+
### Setting RAML data as a HTML attribute
78106

79107
The basic method for determining what API Console displays is to use the `raml` attribute. The attribute accepts the JavaScript object produced by the parser and the enhancer described above.
80108

@@ -96,19 +124,28 @@ The `<api-console>` element also has a convenient `json-file` attribute that can
96124
<api-console json-file="api.json"></api-console>
97125
```
98126

99-
This method is the most flexible method of passing the RAML data. You can use our [build tools] to regenerate the `api.json` file in your CI process automatically as soon as you publish changes in your API.
127+
This method is the most flexible method of passing the RAML data. You can use our [build tools][1] to regenerate the `api.json` file in your CI process automatically as soon as you publish changes in your API.
100128

101129
### Using RAML aware to pass the data
102130

103-
API console internally uses the [raml-aware] element.
131+
API console internally uses the [raml-aware][6] element.
104132
This element can be used to pass the RAML data to the console if direct access to the
105-
element is not possible, for example, if the console is encapsulated in the [shadow DOM].
133+
element is not possible, for example, if the console is encapsulated in the [shadow DOM][7].
134+
135+
See the [raml-aware][6] documentation page for more information.
136+
137+
#### Install
106138

107-
See the [raml-aware] documentation page for more information.
139+
```
140+
$ bower install --save advanced-rest-client/raml-aware
141+
```
108142

109143
#### Example
110144

111145
```html
146+
<link rel="import" href="bower_components/raml-aware/raml-aware.html">
147+
<link rel="import" href="bower_components/api-console/api-console.html">
148+
112149
<raml-aware scope="main-raml"></raml-aware>
113150
<api-console aware="main-raml"></api-console>
114151
```
@@ -121,9 +158,15 @@ window.addEventListener('raml-json-enhance-ready', function(e) {
121158
parser.loadApi(urlToApi);
122159
```
123160

124-
[build tools]: docs/build-tools.md
125-
[raml-js-enhance]: https://elements.advancedrestclient.com/elements/raml-json-enhance
126-
[raml-js-parser]: https://elements.advancedrestclient.com/elements/raml-js-parser
127-
[raml-js-parser-2]: https://github.com/raml-org/raml-js-parser-2
128-
[raml-aware]: https://elements.advancedrestclient.com/elements/raml-aware
129-
[shadow DOM]: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM
161+
[1]: build-tools.md
162+
[2]: web-components.md
163+
[3]: https://elements.advancedrestclient.com/elements/raml-json-enhance
164+
[4]: https://elements.advancedrestclient.com/elements/raml-json-enhance-node
165+
[5]: https://github.com/raml-org/raml-js-parser-2
166+
[6]: https://elements.advancedrestclient.com/elements/raml-aware
167+
[7]: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM
168+
[8]: api-console-element.html
169+
[9]: https://bower.io
170+
[10]: rebuilding-api-json.md
171+
[11]: https://github.com/advanced-rest-client/raml2obj
172+
[12]: https://github.com/raml-org/datatype-expansion/

0 commit comments

Comments
 (0)