-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_sisp_to_dict.py
More file actions
66 lines (54 loc) · 1.89 KB
/
Copy pathconvert_sisp_to_dict.py
File metadata and controls
66 lines (54 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
"""
Script to extract valid samples from a structured API parameter validation schema.
Input JSON schema (each item in the top-level list):
{
"op_name": "string", # API path including parameter(s)
"type": "string", # Data type (e.g., "string")
"param_name": "string", # Name of the path parameter
"format": ["regex", ...], # Allowed formats as regex strings
"valid": [ # Valid sample definitions
{
"param_name": "string",
"category": "string", # Category of the valid sample
"description": "string", # Description of the category
"samples": ["string", ...] # Sample valid values (take one per category)
},
...
],
"invalid": [ # (Ignored here) Invalid sample definitions
...
]
}
Output JSON format:
[
{
"name": "param_name", # e.g., "orderId"
"value": "valid_sample" # e.g., "abc-123-def"
},
...
]
"""
def extract_valid_samples(input_file: str, output_file: str):
with open(input_file, 'r') as f:
data = json.load(f)
output = []
for entry in data:
param_name = entry.get('param_name')
valid_entries = entry.get('valid', [])
seen_categories = set()
for valid in valid_entries:
category = valid.get('category')
samples = valid.get('samples', [])
if category not in seen_categories and samples:
seen_categories.add(category)
output.append({
"name": param_name,
"value": samples[0]
})
# Sort output by 'name'
output_sorted = sorted(output, key=lambda x: x['name'])
with open(output_file, 'w') as f:
json.dump(output_sorted, f, indent=2)
if __name__ == '__main__':
extract_valid_samples('sisp.json', 'tt_fuzz_dict.json')