http-content-parser 0.0.14__tar.gz → 0.0.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: http_content_parser
3
- Version: 0.0.14
3
+ Version: 0.0.16
4
4
  Summary: parse http's payload and response
5
5
  Author-email: max su <suleiabc@gmail.com>
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "http_content_parser"
7
- version = "0.0.14"
7
+ version = "0.0.16"
8
8
  authors = [
9
9
  { name="max su", email="suleiabc@gmail.com" },
10
10
  ]
@@ -1,4 +1,5 @@
1
1
  # -*- coding: UTF-8 -*-
2
+ import copy
2
3
  import json
3
4
  import re
4
5
 
@@ -40,11 +41,23 @@ class GenerateApiFile:
40
41
  payload_list = self.convert_curl_data_to_model(
41
42
  curl_file_path=curl_file, curl_filter=curl_filter
42
43
  )
44
+ # handle duplicate key
45
+ new_payload_list = self.handle_duplicate_yaml_key(payload_list)
43
46
  # write to yaml
44
- for payload in payload_list:
47
+ for payload in new_payload_list:
45
48
  self.write_api_content_to_yaml(yaml_file, payload)
46
- # remove duplicate key
47
- self.remove_duplicate_key_for_yaml(yaml_file)
49
+
50
+ def handle_duplicate_yaml_key(self, payload_list: list[ReqData]) -> list[ReqData]:
51
+ key_filter = {}
52
+ new_payload_list = copy.deepcopy(payload_list)
53
+ for payload, p_copy in zip(payload_list, new_payload_list):
54
+ k = payload.temp_api_label
55
+ if k in key_filter.keys():
56
+ p_copy.temp_api_label = k + "_" + str(key_filter[k])
57
+ key_filter[k] += 1
58
+ else:
59
+ key_filter[k] = 1
60
+ return new_payload_list
48
61
 
49
62
  def convert_curl_data_to_model(
50
63
  self, curl_file_path, curl_filter=None
@@ -13,14 +13,10 @@ class TestCases:
13
13
  # with open("./postman.json", "r") as f:
14
14
  # json_dict = json.load(f)
15
15
  # gaf.produce_api_yaml_for_postman(json_dict, "./test.yaml")
16
- curl_file = '/Users/lei.susl/Desktop/test1/iac-dispatcher/tmp2'
17
- res = gaf.convert_curl_data_to_model(curl_file_path=curl_file)
18
- for r in res:
19
- print('body is: \n')
20
- print(r.body)
21
- print('header is: \n')
22
- print(r.header)
23
-
16
+ curl_file = ""
17
+ res = gaf.produce_api_yaml_for_curl(
18
+ curl_file=curl_file, yaml_file="api.yaml"
19
+ )
24
20
 
25
21
  def test_for(self):
26
22
  # c = 1
@@ -34,4 +30,4 @@ class TestCases:
34
30
  temp = '{ "job_id":{{job_id}}, "product_id": 4, "local_user_id": 0}'
35
31
  temp = json.dumps(data)
36
32
  temp = json.loads(temp)
37
- print(temp)
33
+ print(temp)