@@ -4,6 +4,8 @@ import '@anypoint-web-components/anypoint-checkbox/anypoint-checkbox.js';
44import '@anypoint-web-components/anypoint-item/anypoint-item.js' ;
55import '@advanced-rest-client/arc-demo-helper/arc-demo-helper.js' ;
66import '@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()
79import '@api-components/api-navigation/api-navigation.js' ;
810import '@polymer/paper-toast/paper-toast.js' ;
911import '@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