Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 5dcab07

Browse files
* Fixing interceptor for OpenAPI generator versions 5+
1 parent 69d0a32 commit 5dcab07

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/mcapi/encryption/openapi_interceptor.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def hook_deserialize(enc)
7676

7777
decrypted = enc.decrypt(JSON.generate(to_decrypt, symbolize_names: false))
7878
body = JSON.generate(JSON.parse(decrypted)['body'])
79+
if enc.instance_of? McAPI::Encryption::JweEncryption
80+
body = McAPI::Utils.parse_decrypted_payload(body)
81+
end
7982
response.options[:response_body] = JSON.generate(JSON.parse(body))
8083
end
8184
# noinspection RubySuperCallWithoutSuperclassInspection

lib/mcapi/encryption/utils/utils.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,14 @@ def self.compute_body(config_param, body_map)
186186
def self.encryption_param?(enc_param, body_map)
187187
enc_param.length == 1 && body_map.length == 1
188188
end
189+
190+
def self.parse_decrypted_payload(payload)
191+
parsed_payload = payload.gsub("\\u000f", "")
192+
parsed_payload = parsed_payload.gsub("\\", "")
193+
if parsed_payload[0] == "\""
194+
parsed_payload = parsed_payload.delete_prefix('"').delete_suffix('"')
195+
end
196+
parsed_payload
197+
end
189198
end
190199
end

0 commit comments

Comments
 (0)