@@ -26,7 +26,13 @@ import { saveFlowClick } from 'services/service-builder';
2626import { EndpointDefinitionJson , Service , ServiceState , Step , StepType } from 'types' ;
2727import { Assign } from 'types/assign' ;
2828import { Chip } from 'types/chip' ;
29- import { EndpointData , EndpointEnv , EndpointTab , PreDefinedEndpointEnvVariables } from 'types/endpoint' ;
29+ import {
30+ EndpointData ,
31+ EndpointDefinition ,
32+ EndpointEnv ,
33+ EndpointTab ,
34+ PreDefinedEndpointEnvVariables ,
35+ } from 'types/endpoint' ;
3036import { EndpointResponseVariable } from 'types/endpoint/endpoint-response-variables' ;
3137import { EndpointType } from 'types/endpoint/endpoint-type' ;
3238import { RequestVariablesTabsRawData , RequestVariablesTabsRowsData } from 'types/request-variables' ;
@@ -259,7 +265,7 @@ const useServiceStore = create<ServiceStoreState>((set, get) => ({
259265 url : endpoint . url ,
260266 method : endpoint . methodType ,
261267 headers : extractMapValues ( endpoint . headers ) ,
262- body : extractMapValues ( endpoint . body ) ,
268+ body : getEndpointBody ( endpoint ) ,
263269 params : extractMapValues ( endpoint . params ) ,
264270 } ) ) ,
265271 ) ;
@@ -282,6 +288,12 @@ const useServiceStore = create<ServiceStoreState>((set, get) => ({
282288 } ) ;
283289 }
284290
291+ chips . push ( {
292+ name : 'Base Response' ,
293+ value : `${ endpoint ?. name . replaceAll ( ' ' , '_' ) } _res.response.body` ,
294+ data : `${ endpoint ?. name . replaceAll ( ' ' , '_' ) } _res.response.body` ,
295+ } ) ;
296+
285297 chips . push ( {
286298 name : 'Status Code' ,
287299 value : `${ endpoint ?. name . replaceAll ( ' ' , '_' ) } _res.response.statusCodeValue` ,
@@ -915,7 +927,24 @@ const useServiceStore = create<ServiceStoreState>((set, get) => ({
915927 canRedo : ( ) => get ( ) . historyIndex < get ( ) . history . length - 1 ,
916928} ) ) ;
917929
918- function extractMapValues ( element : any ) {
930+ export function getEndpointBody ( endpoint : EndpointDefinition ) : any {
931+ const isRawBodySelected = endpoint ?. body ?. isRawSelected ?? false ;
932+ const rawBody = endpoint ?. body ?. rawData ?? { } ;
933+ let body : any = extractMapValues ( endpoint . body ) ;
934+
935+ if ( isRawBodySelected ) {
936+ try {
937+ const rawJson = JSON . parse ( rawBody ?. value ?? '' ) ;
938+ body = rawJson ;
939+ } catch ( e : any ) {
940+ body = extractMapValues ( endpoint . body ) ;
941+ console . log ( `Unable to save JSON to Yaml. ${ e . message } ` ) ;
942+ }
943+ }
944+ return body ;
945+ }
946+
947+ export function extractMapValues ( element : any ) {
919948 if ( ! element ) return { } ;
920949
921950 if ( element . rawData && element . rawData . length > 0 ) {
0 commit comments