Skip to content

Commit d01ea23

Browse files
authored
Merge pull request #42 from advanced-rest-client/W-20359321/grpc-Adapt-api-endpoint-documentation-to-Hide-URL-Panel
@W-20359321 Adapt api-endpoint-documentation to Hide URL Panel
2 parents abf822c + 89e213d commit d01ea23

10 files changed

Lines changed: 20731 additions & 7763 deletions

.github/workflows/deployment.yml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: [ubuntu-20.04]
21-
# os: [ubuntu-18.04, ubuntu-20.04]
20+
os: [ubuntu-22.04]
2221
runs-on: ${{ matrix.os }}
2322
steps:
2423
- uses: actions/checkout@v2
2524
- uses: actions/setup-node@v1
2625
with:
27-
node-version: 14
28-
- uses: microsoft/playwright-github-action@v1
29-
- uses: actions/cache@v1
26+
node-version: 18
27+
- uses: actions/cache@v3
3028
with:
3129
path: ~/.npm
3230
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
3331
restore-keys: |
3432
${{ runner.os }}-node-
3533
- name: Install dependencies
36-
run: npm ci
34+
run: npm install
35+
- name: Install Playwright Browsers
36+
run: npx playwright install --with-deps
3737
- name: Run tests
3838
run: npm test
3939
test_win:
@@ -43,35 +43,38 @@ jobs:
4343
- uses: actions/checkout@v2
4444
- uses: actions/setup-node@v1
4545
with:
46-
node-version: 14
47-
- uses: microsoft/playwright-github-action@v1
48-
- uses: actions/cache@v1
46+
node-version: 18
47+
- uses: actions/cache@v3
4948
with:
5049
path: ~/.npm
5150
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
5251
restore-keys: |
5352
${{ runner.os }}-node-
5453
- name: Install dependencies
55-
run: npm ci
54+
run: npm install
55+
- name: Install Playwright Browsers
56+
run: npx playwright install --with-deps
5657
- name: Run tests
5758
run: npm test
5859
tag:
5960
name: "Publishing release"
6061
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
61-
needs:
62+
needs:
6263
- test_linux
6364
- test_win
6465
runs-on: ubuntu-latest
66+
permissions:
67+
contents: write
6568
steps:
6669
- name: Checkout code
67-
uses: actions/checkout@v2
70+
uses: actions/checkout@v4
6871
with:
6972
fetch-depth: 0
70-
- uses: actions/setup-node@v2
73+
- uses: actions/setup-node@v4
7174
with:
72-
node-version: '14.x'
75+
node-version: '18.x'
7376
registry-url: 'https://registry.npmjs.org'
74-
- uses: actions/cache@v1
77+
- uses: actions/cache@v3
7578
with:
7679
path: ~/.npm
7780
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ dist/
6262
# AMF models
6363
/demo/*.json
6464
!demo/apis.json
65+
66+
# gRPC test files
67+
!/demo/grpc-test.json

demo/grpc-test.json

Lines changed: 4490 additions & 0 deletions
Large diffs are not rendered by default.

demo/index.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import '@anypoint-web-components/anypoint-checkbox/anypoint-checkbox.js';
44
import '@anypoint-web-components/anypoint-item/anypoint-item.js';
55
import '@advanced-rest-client/arc-demo-helper/arc-demo-helper.js';
66
import '@advanced-rest-client/arc-demo-helper/arc-interactive-demo.js';
7+
// TODO: Update to api-navigation version with gRPC support once published (currently blocked by npm-token expiration)
8+
// Current version (^4.2.7) doesn't support gRPC, causing workarounds in _autoSelectGrpcEndpoint() and __amfChanged()
79
import '@api-components/api-navigation/api-navigation.js';
810
import '@polymer/paper-toast/paper-toast.js';
911
import '@anypoint-web-components/anypoint-styles/colors.js';
@@ -51,6 +53,79 @@ class ComponentDemo extends ApiDemoPage {
5153
this._serverHandler = this._serverHandler.bind(this);
5254
}
5355

56+
/**
57+
* TEMPORARY WORKAROUND: Auto-select first endpoint for gRPC APIs
58+
*
59+
* This method exists because the current published version of api-navigation
60+
* doesn't support gRPC APIs and crashes when processing them.
61+
*
62+
* TODO: Remove this method once api-navigation is updated with gRPC support.
63+
* The gRPC support has already been implemented in api-navigation but is pending
64+
* publication due to npm-token expiration issues.
65+
*
66+
* Once api-navigation with gRPC support is published:
67+
* 1. Remove this method
68+
* 2. Remove the __amfChanged override below
69+
* 3. Update package.json to use the new api-navigation version
70+
* 4. The normal auto-selection flow will work for gRPC APIs
71+
*/
72+
_autoSelectGrpcEndpoint() {
73+
if (!this.amf) {
74+
return;
75+
}
76+
const webApi = this._computeWebApi(this.amf);
77+
if (!webApi) {
78+
return;
79+
}
80+
81+
// Try multiple detection methods
82+
const isGrpcMethod1 = typeof this._isGrpcApi === 'function' ? this._isGrpcApi(webApi) : false;
83+
const isGrpcMethod2 = typeof this._isGrpcApi === 'function' ? this._isGrpcApi(this.amf) : false;
84+
85+
// Manual check: Look for endpoints and check if they have gRPC operations
86+
const endpoints = this._computeEndpoints(webApi);
87+
88+
let isGrpcManual = false;
89+
if (endpoints && endpoints.length > 0) {
90+
const firstEndpoint = endpoints[0];
91+
if (typeof this._isGrpcService === 'function') {
92+
isGrpcManual = this._isGrpcService(firstEndpoint);
93+
}
94+
}
95+
96+
const isGrpc = isGrpcMethod1 || isGrpcMethod2 || isGrpcManual;
97+
98+
if (isGrpc) {
99+
// Get gRPC services using the mixin's helper
100+
let services = typeof this._computeGrpcServices === 'function'
101+
? this._computeGrpcServices(webApi)
102+
: null;
103+
104+
// Fallback to regular endpoints if gRPC services method doesn't work
105+
if (!services || !services.length) {
106+
services = endpoints;
107+
}
108+
109+
if (services && services.length) {
110+
const firstService = services[0];
111+
// Auto-select the first service
112+
this.setData(firstService['@id'], 'endpoint');
113+
this.hasData = true;
114+
}
115+
}
116+
}
117+
118+
/**
119+
* TEMPORARY WORKAROUND: Override to trigger gRPC auto-selection
120+
* TODO: Remove this override once api-navigation with gRPC support is published
121+
*/
122+
__amfChanged(amf) {
123+
// @ts-ignore
124+
super.__amfChanged(amf);
125+
// Auto-select first endpoint for gRPC APIs
126+
setTimeout(() => this._autoSelectGrpcEndpoint(), 100);
127+
}
128+
54129
get server() {
55130
const { serverValue, serverType, endpointId, methodId } = this;
56131
if (serverType && serverType !== 'server') {
@@ -179,6 +254,7 @@ class ComponentDemo extends ApiDemoPage {
179254

180255
_apiListTemplate() {
181256
return [
257+
['grpc-test', 'GRPC Test'],
182258
['google-drive-api', 'Google Drive'],
183259
['multi-server', 'Multiple servers'],
184260
['exchange-experience-api', 'Exchange xAPI'],

0 commit comments

Comments
 (0)