@@ -40,7 +40,7 @@ def install_jwe_encryption(swagger_client, config)
4040 # Hooking ApiClient#call_api
4141 hook_call_api jwe
4242 # Hooking ApiClient#deserialize
43- hook_deserialize_jwe jwe
43+ hook_deserialize jwe
4444 McAPI ::Encryption ::OpenAPIInterceptor . init_call_api swagger_client
4545 McAPI ::Encryption ::OpenAPIInterceptor . init_deserialize swagger_client
4646 end
@@ -65,32 +65,20 @@ def hook_call_api(enc)
6565 end
6666 end
6767
68- def hook_deserialize ( fle )
68+ def hook_deserialize ( enc )
6969 self . class . send :define_method , :init_deserialize do |client |
7070 client . define_singleton_method ( :deserialize ) do |response , return_type |
7171 if response &.body
7272 endpoint = response . request . base_url . sub client . config . base_url , ''
73- to_decrypt = { headers : McAPI ::Utils . parse_header ( response . options [ :response_headers ] ) ,
74- request : { url : endpoint } ,
75- body : JSON . parse ( response . body ) }
76- decrypted = fle . decrypt ( JSON . generate ( to_decrypt , symbolize_names : false ) )
77- body = JSON . generate ( JSON . parse ( decrypted ) [ 'body' ] )
78- response . options [ :response_body ] = JSON . generate ( JSON . parse ( body ) )
79- end
80- # noinspection RubySuperCallWithoutSuperclassInspection
81- super ( response , return_type )
82- end
83- end
84- end
85-
86- def hook_deserialize_jwe ( jwe )
87- self . class . send :define_method , :init_deserialize do |client |
88- client . define_singleton_method ( :deserialize ) do |response , return_type |
89- if response &.body
90- endpoint = response . request . base_url . sub client . config . base_url , ''
91- to_decrypt = { request : { url : endpoint } ,
92- body : JSON . parse ( response . body ) }
93- decrypted = jwe . decrypt ( JSON . generate ( to_decrypt , symbolize_names : false ) )
73+ if enc . instance_of? McAPI ::Encryption ::FieldLevelEncryption
74+ to_decrypt = { headers : McAPI ::Utils . parse_header ( response . options [ :response_headers ] ) ,
75+ request : { url : endpoint } ,
76+ body : JSON . parse ( response . body ) }
77+ else
78+ to_decrypt = { request : { url : endpoint } ,
79+ body : JSON . parse ( response . body ) }
80+ end
81+ decrypted = enc . decrypt ( JSON . generate ( to_decrypt , symbolize_names : false ) )
9482 body = JSON . generate ( JSON . parse ( decrypted ) [ 'body' ] )
9583 response . options [ :response_body ] = JSON . generate ( JSON . parse ( body ) )
9684 end
0 commit comments