@@ -52,6 +52,9 @@ export class OperationDetails {
5252 public readonly protocol : ko . Computed < string > ;
5353 public readonly examples : ko . Observable < OperationExamples > ;
5454
55+ public readonly selectedRepresentatnionsValue : ko . Observable < object > ;
56+
57+
5558 constructor (
5659 private readonly apiService : ApiService ,
5760 private readonly oauthService : OAuthService ,
@@ -73,6 +76,8 @@ export class OperationDetails {
7376 this . defaultSchemaView = ko . observable ( "table" ) ;
7477 this . useCorsProxy = ko . observable ( ) ;
7578 this . includeAllHostnames = ko . observable ( ) ;
79+ this . selectedRepresentatnionsValue = ko . observable < object > ( ) ;
80+
7681 this . requestUrlSample = ko . computed ( ( ) => {
7782
7883 const api = this . api ( ) ;
@@ -115,6 +120,7 @@ export class OperationDetails {
115120
116121 return api . protocols ?. join ( ", " ) ;
117122 } ) ;
123+
118124 this . examples = ko . observable ( { } ) ;
119125
120126 this . apiType = ko . observable ( ) ;
@@ -231,7 +237,10 @@ export class OperationDetails {
231237
232238 if ( operation ) {
233239 await this . loadDefinitions ( operation ) ;
234- if ( this . showExamples ) this . parseExamples ( operation ) ;
240+ if ( this . showExamples ) this . parseResponseExamples ( operation ) ;
241+
242+ this . loadRequestExamples ( operation ) ;
243+
235244 this . operation ( operation ) ;
236245 }
237246 else {
@@ -244,6 +253,19 @@ export class OperationDetails {
244253 this . working ( false ) ;
245254 }
246255
256+ public async loadRequestExamples ( operation : Operation ) : Promise < void > {
257+ const representations = operation . request . meaningfulRepresentations ( ) ;
258+ const requestExamples = { } ;
259+ if ( representations && representations . length ) {
260+ for ( let i = 0 ; i < representations . length ; i ++ ) {
261+ const value = representations [ i ] . examples ?. [ 0 ] ;
262+ if ( ! value ) continue ;
263+ requestExamples [ representations [ i ] . contentType ] = ko . observable ( value . title ) ;
264+ }
265+ }
266+ this . selectedRepresentatnionsValue ( requestExamples ) ;
267+ }
268+
247269 public async loadDefinitions ( operation : Operation ) : Promise < void > {
248270 const cachedDefinitions = this . definitionsCache . getItem ( operation . id ) ;
249271 if ( cachedDefinitions ) {
@@ -346,11 +368,11 @@ export class OperationDetails {
346368 return result ;
347369 }
348370
349- private parseExamples ( operation : Operation ) : void {
371+ private parseResponseExamples ( operation : Operation ) : void {
350372 const examples = operation . getMeaningfulResponses ( ) . reduce ( ( acc , cur ) => {
351373 const representations = cur . meaningfulRepresentations ( ) ;
352374 if ( ! representations || ! representations . length ) return acc ;
353-
375+
354376 const examplesObj = { }
355377 representations . forEach ( representation => {
356378 const value = representation . examples ?. [ 0 ] ?. value ;
0 commit comments