-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_all.py
More file actions
38 lines (33 loc) · 1.38 KB
/
Copy pathgenerate_all.py
File metadata and controls
38 lines (33 loc) · 1.38 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
import json
from pathlib import Path
from stix2extensions.automodel.automodel import AUTOMODEL_REGISTRY
from stix2 import base
import json
from stix2extensions.automodel.definitions import get_extension_type_name, get_title
# Generate Schema for all objects registered (writes to file)
base_dir = Path("automodel_generated/")
schema_dir = base_dir/'schemas'
ext_dir = base_dir/'extension-definitions'
ext_dir.mkdir(parents=True, exist_ok=True)
schema_dir.mkdir(parents=True, exist_ok=True)
print("Generating Automodel Schemas and Extension Definitions...")
print("==================================")
for model in AUTOMODEL_REGISTRY:
if not hasattr(model, '_type'):
continue
k = get_title(model)
dir = get_extension_type_name(model)
name = f"{dir}/{k}.json"
path = schema_dir/name
ext_path = ext_dir/name
print(path, model.__name__)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(model.schema, indent=4))
if hasattr(model, 'extension_definition'):
ext_path.parent.mkdir(parents=True, exist_ok=True)
ext_path.write_text(model.extension_definition.serialize(indent=4))
# Generate Examples for all example files (writes to file)
from stix2extensions.examples.generate import generate_examples
print("==================================")
print("Generating example STIX object JSON files...")
generate_examples(Path("."))