Skip to content

Commit 4bf0e3d

Browse files
authored
Merge pull request #890 from mulesoft/move-grpc-detection-to-api-console-app
@W-21176653 Move gRPC API detection and try panel hiding logic to ApiConsoleApp
2 parents 5ce0d59 + a6d7a35 commit 4bf0e3d

10 files changed

Lines changed: 1112 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ demo/models/flattened/*.json
6666
!demo/models/avro.json
6767
!demo/models/avro2.json
6868
!demo/models/grpc-test.json
69+
!demo/models/grpc-test-compact.json
6970

7071
.idea/
7172
.sfdx

demo/element/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ApicApplication extends DemoBase {
1414
constructor() {
1515
super();
1616
this.apis = [
17+
['grpc-test', 'gRPC API'],
1718
['google-drive-api', 'Google Drive API'],
1819
['httpbin', 'HTTPbin API'],
1920
['data-type-fragment', 'RAML data type fragment'],

demo/models/grpc-test-compact.json

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

demo/standalone/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ApicApplication extends DemoBase {
1111
constructor() {
1212
super();
1313
this.apis = [
14+
['grpc-test', 'gRPC API'],
1415
['google-drive-api', 'Google Drive API'],
1516
['httpbin', 'HTTPbin API'],
1617
['oAuth2', 'oAuth2'],

demo/themed/anypoint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ class ApicApplication extends DemoBase {
1414
super();
1515
this.apis = [
1616
['grpc-test', 'gRPC API'],
17+
['agents-api', 'Agents API'],
18+
['agents-api-compact', 'Agents API Compact'],
1719
['google-drive-api', 'Google Drive API'],
1820
['httpbin', 'HTTPbin API'],
1921
['data-type-fragment', 'RAML data type fragment'],
2022
['demo-api', 'Demo API'],
2123
['APIC-538', 'APIC-538'],
22-
['agents-api', 'Agents API Compact'],
2324
];
2425
}
2526

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "api-console",
33
"description": "The API Console to automatically generate API documentation from RAML and OAS files.",
4-
"version": "6.6.57",
4+
"version": "6.6.58",
55
"license": "CPAL-1.0",
66
"main": "index.js",
77
"module": "index.js",
@@ -39,7 +39,7 @@
3939
"@anypoint-web-components/anypoint-button": "^1.1.1",
4040
"@api-components/amf-helper-mixin": "^4.5.36",
4141
"@api-components/api-console-ext-comm": "^3.0.0",
42-
"@api-components/api-documentation": "^6.1.7",
42+
"@api-components/api-documentation": "^6.1.8",
4343
"@api-components/api-navigation": "^4.3.20",
4444
"@api-components/api-request": "^0.3.8",
4545
"@api-components/api-summary": "^4.6.16",

src/ApiConsole.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
463463
const webApi = this._computeApi(amf);
464464
this.webApi = webApi;
465465
this.methodName = this._computeMethodName(this.selectedShape, webApi);
466-
if (!this._isWebAPI(amf)) {
466+
// Hide try-it panel for gRPC APIs or non-WebAPI models
467+
if (!this._isWebAPI(amf) || this._isGrpcApi(amf)) {
467468
this._noTryItValue = true;
468469
}
469470
}

src/ApiConsoleApp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ export class ApiConsoleApp extends ApiConsole {
268268
*/
269269
async _processModelChange() {
270270
super._processModelChange();
271+
// Update try-it panel visibility based on API type (gRPC detection)
272+
this._updateRenderInlineTyit();
271273
this.apiTitle = this._computeApiTitle(this.webApi);
272274
await this.updateComplete;
273275
if (window.history.state) {

test/api-console.amf.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const selectOperation = (element, endpointName, operationName) => {
3636

3737
describe('ApiConsole', () => {
3838
const asyncApi = 'async-api';
39+
const grpcApi = 'grpc-test';
3940
const multiServer = 'multi-server';
4041
const apic553 = 'APIC-553';
4142
const apic554 = 'APIC-554';
@@ -212,6 +213,55 @@ describe('ApiConsole', () => {
212213
});
213214
});
214215

216+
describe('gRPC API', () => {
217+
[
218+
new ApiDescribe('Regular model'),
219+
new ApiDescribe('Compact model', true),
220+
].forEach(({ label, compact }) => {
221+
describe(label, () => {
222+
let amf;
223+
let element;
224+
225+
before(async () => {
226+
amf = await AmfLoader.load({ compact, fileName: grpcApi, flattened: false });
227+
});
228+
229+
beforeEach(async () => {
230+
element = await amfFixture(amf);
231+
await aTimeout(0);
232+
});
233+
234+
it('should have _noTryItValue set to true for gRPC API', () => {
235+
assert.isTrue(element._noTryItValue, '_noTryItValue should be true for gRPC API');
236+
});
237+
238+
it('should detect gRPC API correctly', () => {
239+
const isGrpc = element._isGrpcApi(amf);
240+
assert.isTrue(isGrpc, 'Should detect gRPC API');
241+
});
242+
243+
it('should hide try-it button when selecting a method', async () => {
244+
const webApi = AmfLoader.lookupWebApi(amf);
245+
const endpoints = element._computeEndpoints(webApi);
246+
if (endpoints && endpoints.length > 0) {
247+
const operations = element._computePropertyArray(
248+
endpoints[0],
249+
element.ns.aml.vocabularies.apiContract.supportedOperation
250+
);
251+
if (operations && operations.length > 0) {
252+
element.selectedShape = operations[0]['@id'];
253+
element.selectedShapeType = 'method';
254+
await nextFrame();
255+
await nextFrame();
256+
257+
assert.isTrue(element._noTryItValue, 'Try-it button should be hidden for gRPC API method');
258+
}
259+
}
260+
});
261+
});
262+
});
263+
});
264+
215265
describe('APIC-553', () => {
216266
[
217267
new ApiDescribe('Regular model'),

0 commit comments

Comments
 (0)