Skip to content

Commit de806ec

Browse files
committed
chore: finalizing migration to the AmfStore
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 71bf8aa commit de806ec

File tree

126 files changed

+4006
-2644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+4006
-2644
lines changed

.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
{
22
"cSpell.words": [
3+
"amfstoreapiprotocols",
34
"amfstoreapisummary",
5+
"amfstoreapiversion",
6+
"amfstoredocumentationget",
7+
"amfstoredocumentationlist",
8+
"amfstoredocumentmeta",
49
"amfstoreendpointbypath",
510
"amfstoreendpointget",
611
"amfstoreendpointlist",
12+
"amfstoreopget",
13+
"amfstoreopgetparent",
14+
"amfstorepayloadget",
15+
"amfstorerequestget",
16+
"amfstoreresponseget",
17+
"amfstoresecurityget",
18+
"amfstoresecuritygetrequirement",
19+
"amfstoresecuritygetsettings",
20+
"amfstoresecuritylist",
21+
"amfstoretypeget",
722
"apierror",
823
"apinavigate",
924
"apirequest",

CHANGELOG.md

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
# Changelog
22

3-
## General changes
3+
## Old components vs this repository
4+
5+
### User (consumer) changelog
6+
7+
The UI in most cases is consistent with the previous version, except for the following items:
8+
9+
- Removed an option to disable a single parameter. The rationale is that these parameters are defined in the API and the request editor and the outgoing HTTP request should reflect what the API author designed.
10+
- Changes titles of operations and resource: added sub title describing the section.
11+
- The URI and query parameters are now combined into a single section: Parameters.
12+
- The information architecture for parameters changed for better readability and accessibility.
13+
- Schema documentation was redesigned to better visualize complex objects.
14+
- Authorization now support OpenID Connect which can be defined in an OAS file.
15+
16+
### Developer changelog
17+
18+
#### General changes
419

520
The `compatibility` has been renamed to `anypoint`.
621

722
The `selected` property has been renamed to `domainId` which is the id of the graph node rendered by the AMF parser.
823

924
The `selectedType` has been renamed to `domainType`. This is a value generated by the navigation element to help to reduce the scope of searching for an object in the graph model.
1025

11-
The components now ignore (in most cases) the rendered AMF graph model and instead uses the serialized graph objects to a simpler JavaScript objects. This serialization happens in the `ApiSerializer` class.
26+
The components do not read the generated graph model anymore (generated through the AMF library LD+JSON model). See **docs/architecture.md** for detailed description.
1227

13-
## Documentation components
28+
#### Documentation components
1429

15-
### Api navigation
30+
##### Api navigation
1631

1732
The API navigate event definition changed. With this version the detail object has the following properties.
1833

@@ -29,16 +44,16 @@ import { Events } from '@api-components/amf-components';
2944
Events.Navigation.apiNavigate(document.body, 'amf://id', 'resource');
3045
```
3146

32-
### ApiDocumentationElement (former api-documentation)
47+
##### ApiDocumentationElement (former api-documentation)
3348

34-
#### Refactored properties
49+
###### Refactored properties
3550

3651
- `selected` -> `domainId`
3752
- `selectedType` -> `domainType`
3853
- `inlineMethods` -> `tryItPanel`
3954
- `compatibility` -> `anypoint`
4055

41-
#### Removed properties
56+
###### Removed properties
4257

4358
- `noTryIt` - this has been replaced with `tryItButton`
4459
- `noUrlEditor` - this has been replaced with `httpUrlEditor`
@@ -48,16 +63,16 @@ Events.Navigation.apiNavigate(document.body, 'amf://id', 'resource');
4863
- `outlined` - we are dropping support for this property
4964
- `noBottomNavigation` - not used anymore
5065

51-
#### New properties
66+
###### New properties
5267

5368
- `tryItButton` - the opposite of the previous `noTryIt`
5469
- `httpUrlEditor` - passed to the request editor as `urlEditor`
5570
- `httpApplyAuthorization` - passed to the request editor as `applyAuthorization`
5671
- `httpCredentialsSource` - passed to the request editor as `credentialsSource`
5772

58-
### ApiResourceDocumentElement (former api-endpoint-documentation)
73+
##### ApiResourceDocumentElement (former api-endpoint-documentation)
5974

60-
#### Refactored properties
75+
###### Refactored properties
6176

6277
- `selected` -> `domainId`
6378
- `selectedType` - `domainType`
@@ -66,7 +81,7 @@ Events.Navigation.apiNavigate(document.body, 'amf://id', 'resource');
6681
- `inlineMethods` is renamed to `tryItPanel`. Has the same function.
6782
- `noUrlEditor` is now renamed to `urlEditor`. When `urlEditor` is set then the HTTP request editor renders the URL editor input field.
6883

69-
#### Removed properties
84+
###### Removed properties
7085

7186
- `apiVersion` - no longer in use
7287
- `endpointUri` - no longer in use
@@ -89,7 +104,7 @@ Events.Navigation.apiNavigate(document.body, 'amf://id', 'resource');
89104
- `graph` - no longer in use
90105
- `noNavigation` - no longer in use
91106

92-
#### New properties
107+
###### New properties
93108

94109
- `serverId` the domain id of the selected API server.
95110
- `operationId` - the domain id of the selected API operation, when `tryItPanel` is set.
@@ -101,17 +116,17 @@ Events.Navigation.apiNavigate(document.body, 'amf://id', 'resource');
101116
- `httpNoServerSelector` - passed to the request editor as `noServerSelector`
102117
- `asyncApi` - indicates the rendered API is an async API.
103118

104-
### ApiOperationDocumentElement (former api-operation-documentation)
119+
##### ApiOperationDocumentElement (former api-operation-documentation)
105120

106-
#### Refactored properties
121+
###### Refactored properties
107122

108123
- `tryIt` is renamed to `tryItButton`
109124
- `tryItButton` is always set to `false` when `tryItPanel` is set on the resource document element.
110125
- `method` is now `operation` which accepts serialized API operation model.
111126
- `endpoint` now accepts serialized API endpoint model.
112127
- `compatibility` -> anypoint
113128

114-
#### Removed properties
129+
###### Removed properties
115130

116131
- `methodName` - no longer in use
117132
- `httpMethod` - no longer in use
@@ -141,18 +156,18 @@ Events.Navigation.apiNavigate(document.body, 'amf://id', 'resource');
141156
- `ignoreBaseUri` - no longer in use
142157
- `protocol` - no longer in use
143158

144-
#### New properties
159+
###### New properties
145160

146161
- `serverId` the domain id of the selected API server.
147162
- `tryItButton` - the opposite of the previous `noTryIt`
148163
- `asyncApi` - indicates the rendered API is an async API.
149164
- `requestMimeType` - The mime type of rendered request.
150165

151-
## Request editor components
166+
#### Request editor components
152167

153-
### Authorization
168+
##### Authorization
154169

155-
#### Configuration and HTTP request
170+
###### Configuration and HTTP request
156171

157172
The authorization has been moved into this library and has a new API surface.
158173

@@ -169,33 +184,33 @@ To maximize the compatibility with 0.2.0 use the following configuration:
169184
></api-request-editor>
170185
```
171186

172-
### Caching values
187+
##### Caching values
173188

174189
The editor has a new boolean property `globalCache`. Once set it instruct the caching mechanism to cache user input in memory. The cached values are kept in memory even when API spec change.
175190
Use the `src/lib/InputCache.js` class to manipulate the cache programmatically when needed.
176191

177192
When the `globalCache` is not set then the values are stored in a reference to the editor element. After removing the element from the DOM all cached properties are GC'd.
178193

179-
### Request editor
194+
##### Request editor
180195

181-
#### Refactor
196+
###### Refactor
182197

183198
- `serializeRequest()` -> `serialize()`
184199
- removed option `allowDisableParams`
185200

186-
#### Setting URL values (baseUri, protocols, server)
201+
###### Setting URL values (baseUri, protocols, server)
187202

188203
With version `0.2.x` it was possible to set `server`, `baseUri`, and `protocols` properties so the component is able to compute the endpoint URL without having the `server` value read from the AMF graph model. This turned out to be a feature that is not used so it is removed in `0.3.0`. Use `baseUri` to override any value defined in the servers.
189204
Note, when `baseUri` is set it takes precedence over any other URI configuration (like a selected server).
190205

191-
### URL editor
206+
##### URL editor
192207

193208
The URL editor is optional by default. The input won't be rendered until the `urlEditor` property is set.
194209
For a better user experience do not set this option unless crucial for the application. To give user a feedback when updating parameters use option `urlLabel`.
195210

196211
Additionally, the user entered values are now updated on input value change rather than user input. This reduces UI changes (especially with URL editor enabled) while typing value into the editor.
197212

198-
### Body editor
213+
##### Body editor
199214

200215
The body editor has been re-created from scratch. The new editor uses monaco editor to render the body input.
201216
This requires loading monaco environment before the editor is rendered and activated.
@@ -214,7 +229,7 @@ await MonacoLoader.monacoReady(); // waits until all libraries are loaded.
214229

215230
Note, Monaco does not support encapsulation. Once loaded a global `Monaco` variable is created.
216231

217-
## Events
232+
#### Events
218233

219234
With this version the following events are deprecated:
220235

@@ -244,6 +259,6 @@ window.addEventListener(EventTypes.Request.apiRequest, (e) => {
244259
RequestEvents.apiRequest(window, { /* the request definition */ });
245260
```
246261

247-
## Tests
262+
#### Tests
248263

249264
The tests for Firefox currently fails because `playwright` uses a previous version of the browser which has no support for ES modules in web workers. However, the current version support them. Firefox is temporarily removed from tests.

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ npm install --save @api-components/amf-components
2222
<html>
2323
<head>
2424
<script type="module">
25-
import '@api-components/amf-components/api-documentation.js';
26-
import '@api-components/amf-components/api-request.js';
27-
import '@api-components/amf-components/api-navigation.js';
28-
import '@api-components/amf-components/xhr-simple-request.js';
25+
import '@api-components/amf-components/define/api-documentation.js';
26+
import '@api-components/amf-components/define/api-request.js';
27+
import '@api-components/amf-components/define/api-navigation.js';
28+
import '@api-components/amf-components/define/xhr-simple-request.js';
2929
import '@advanced-rest-client/app/define/oidc-authorization.js';
3030
import '@advanced-rest-client/app/define/oauth2-authorization.js';
3131
</script>
@@ -49,19 +49,24 @@ npm install --save @api-components/amf-components
4949
<api-request handleNavigationEvents></api-request>
5050
</aside>
5151

52-
<script>
52+
<script type="module">
53+
import { DomEventsAmfStore } from '@api-components/amf-components';
5354
(async () => {
54-
const model = getAmfModelSomehow();
55-
const nodes = document.querySelectorAll('api-navigation,api-documentation,api-request');
56-
Array.from(nodes).forEach((element) => {
57-
element.amf = model;
58-
});
55+
const apiStore = new DomEventsAmfStore();
56+
apiStore.amf = await getAmfModelSomehow();
5957
})();
6058
</script>
6159
</body>
6260
</html>
6361
```
6462

63+
### API store
64+
65+
The components, unlike previously, do not rely on the graph model generated by the AMF parser. Instead they use a custom JavaScript objects generated by the [src/helpers/AmfSerializer.js](AmfSerializer) class.
66+
These models are provided to the components by the [src/store/AmfStore.js](AmfStore) or the [src/store/DomEventsAmfStore.js](DomEventsAmfStore). This was developers implementing the components have the most flexibility of providing the console with the graph model that source may be in a different location (like HTTP queries).
67+
68+
See [docs/architecture.md](docs/architecture.md) for more details.
69+
6570
### Monaco editor
6671

6772
The request editor uses the Monaco editor (by Microsoft) to render the body editor.

demo/api-annotation.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { html } from 'lit-html';
22
import '@advanced-rest-client/arc-demo-helper/arc-interactive-demo.js';
33
import { AmfDemoBase } from './lib/AmfDemoBase.js';
4+
import { AmfSerializer } from '../src/helpers/AmfSerializer.js';
45
import '../define/api-annotation-document.js';
56

67
/** @typedef {import('../src/events/NavigationEvents').ApiNavigationEvent} ApiNavigationEvent */
@@ -12,10 +13,17 @@ class ComponentPage extends AmfDemoBase {
1213
'shape',
1314
]);
1415
this.shape = undefined;
16+
this.serializer = new AmfSerializer();
1517
this.componentName = 'api-annotation-document';
1618
this.redirectUri = `${window.location.origin}/node_modules/@advanced-rest-client/oauth-authorization/oauth-popup.html`;
1719
}
1820

21+
/** @param {string} file */
22+
async _loadFile(file) {
23+
await super._loadFile(file);
24+
this.serializer.amf = this.amf;
25+
}
26+
1927
/**
2028
* @param {ApiNavigationEvent} e
2129
*/
@@ -30,36 +38,37 @@ class ComponentPage extends AmfDemoBase {
3038
} else {
3139
this.shape = undefined;
3240
}
33-
console.log(this.shape);
3441
}
3542

3643
/**
3744
* @param {string} id
3845
*/
3946
setTypeData(id) {
4047
const declares = this._computeDeclares(this.amf);
41-
const type = declares.find((item) => item['@id'] === id);
42-
if (!type) {
48+
const shape = declares.find((item) => item['@id'] === id);
49+
if (!shape) {
4350
console.error('Type not found');
4451
return;
4552
}
46-
this.shape = type;
53+
this.shape = this.serializer.customDomainProperties(shape);
4754
}
4855

4956
/**
5057
* @param {string} id
5158
*/
5259
setEndpointData(id) {
5360
const webApi = this._computeWebApi(this.amf);
54-
this.shape = this._computeEndpointModel(webApi, id);
61+
const shape = this._computeEndpointModel(webApi, id);
62+
this.shape = this.serializer.customDomainProperties(shape);
5563
}
5664

5765
/**
5866
* @param {string} id
5967
*/
6068
setMethodData(id) {
6169
const webApi = this._computeWebApi(this.amf);
62-
this.shape = this._computeMethodModel(webApi, id);
70+
const shape = this._computeMethodModel(webApi, id);
71+
this.shape = this.serializer.customDomainProperties(shape);
6372
}
6473

6574
contentTemplate() {
@@ -92,7 +101,7 @@ class ComponentPage extends AmfDemoBase {
92101
}
93102

94103
componentTemplate() {
95-
const { demoStates, darkThemeActive, shape, amf } = this;
104+
const { demoStates, darkThemeActive, shape } = this;
96105
if (!shape) {
97106
return html`<p>Select API object in the navigation</p>`;
98107
}
@@ -103,8 +112,7 @@ class ComponentPage extends AmfDemoBase {
103112
?dark="${darkThemeActive}"
104113
>
105114
<api-annotation-document
106-
.amf="${amf}"
107-
.shape="${shape}"
115+
.customProperties="${shape}"
108116
slot="content"
109117
>
110118
</api-annotation-document>

demo/api-channel.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ComponentPage extends AmfDemoBase {
7878
}
7979

8080
componentTemplate() {
81-
const { demoStates, darkThemeActive, selectedId, selectedOperation, amf } = this;
81+
const { demoStates, darkThemeActive, selectedId, selectedOperation } = this;
8282
if (!selectedId) {
8383
return html`<p>Select API operation in the navigation</p>`;
8484
}
@@ -89,7 +89,6 @@ class ComponentPage extends AmfDemoBase {
8989
?dark="${darkThemeActive}"
9090
>
9191
<api-channel-document
92-
.amf="${amf}"
9392
.domainId="${selectedId}"
9493
.operationId="${selectedOperation}"
9594
slot="content"

0 commit comments

Comments
 (0)