Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f0109a3
Refactored code so that documentation is handled by separate class
DianaStrauss Jun 10, 2024
630f571
refactored code
DianaStrauss Jun 10, 2024
bef16c0
Adjusted prompt_engineer to create better prompts
DianaStrauss Jun 13, 2024
74062ff
Refactored documentation_handler.py to update .yaml file when it get …
DianaStrauss Jun 13, 2024
7591be3
Created SubmitHTTPMethod.py for better separation
DianaStrauss Jun 13, 2024
73fe5c4
Created Converter and parser for handeling yaml and json files
DianaStrauss Jun 13, 2024
430cb1f
Refactored converter and parser
DianaStrauss Jun 14, 2024
cef43e9
Added token count so that prompts are not too long -> WIP shorten pro…
DianaStrauss Jun 14, 2024
89956d7
Refactored code and added yamlFile.py
DianaStrauss Jun 17, 2024
e7ce9ae
Refactored code
DianaStrauss Jun 19, 2024
995b199
Added simple scoring to prompt engineer
DianaStrauss Jul 4, 2024
cbafdf2
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
34593e3
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
b95dd31
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
e267621
Addition of examples works with redocly
DianaStrauss Jul 9, 2024
56bc5ff
Added yaml file assistant
DianaStrauss Jul 9, 2024
7c681af
Can create openapi spec with examples
DianaStrauss Jul 9, 2024
120b09f
Cleaned up code
DianaStrauss Jul 12, 2024
2fcca09
Refactor code
DianaStrauss Jul 12, 2024
29aa192
Refactor code
DianaStrauss Jul 12, 2024
b2632ab
Cleaned up code
DianaStrauss Jul 12, 2024
3af909a
Cleaned up code
DianaStrauss Jul 12, 2024
b1f9886
Cleaned up code
DianaStrauss Jul 12, 2024
5915187
Merge branch 'main' of https://github.com/DianaStrauss/hackingBuddyGP…
andreashappe Jul 22, 2024
8e58cad
Merge branch 'development' into DianaStrauss-main
andreashappe Jul 22, 2024
bbb8133
update dependencies
andreashappe Jul 22, 2024
fd4323e
some simple renames
andreashappe Jul 22, 2024
ec3a0ee
Fixed attribute initialization of use_cases and transparent types
Neverbolt Jul 26, 2024
0babd39
Refactored code and fixed import bugs in simple_web_api_testing and s…
DianaStrauss Aug 1, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored converter and parser
  • Loading branch information
DianaStrauss committed Jun 14, 2024
commit 430cb1f932b0ece62b02ca4a6ef64695af6a16a7
82 changes: 39 additions & 43 deletions src/hackingBuddyGPT/usecases/web_api_testing/openapi_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,54 @@

import yaml
import json


class OpenAPISpecificationConverter:
def __init__(self, filepath):
self.filepath = filepath
def yaml_to_json(self, yaml_filepath):
def __init__(self, base_directory):
self.base_directory = base_directory

def convert_file(self, input_filepath, output_directory, input_type, output_type):
"""
Convert a YAML file to a JSON file.
Generic method to convert files between YAML and JSON.

:param yaml_filepath: Path to the input YAML file.
:param input_filepath: Path to the input file.
:param output_directory: Subdirectory for the output files.
:param input_type: Type of the input file ('yaml' or 'json').
:param output_type: Type of the output file ('json' or 'yaml').
"""
try:
# Get the filename from the path
filename = os.path.basename(yaml_input)
json_filepath = filename.split(".yaml")[0]+ ".json"
converted_path = os.path.join(self.filepath, "json")
if not os.path.exists(converted_path) :
os.makedirs(converted_path, exist_ok=True)
with open(yaml_filepath, 'r') as yaml_file:
yaml_content = yaml.safe_load(yaml_file)
final_path = os.path.join(converted_path, json_filepath)
with open(final_path, 'w') as json_file:
json.dump(yaml_content, json_file, indent=2)

print(f"Successfully converted {yaml_filepath} to {json_filepath}")
return final_path
except Exception as e:
print(f"Error converting YAML to JSON: {e}")
return ""
filename = os.path.basename(input_filepath)
output_filename = filename.replace(f".{input_type}", f".{output_type}")
output_path = os.path.join(self.base_directory, output_directory, output_filename)

os.makedirs(os.path.dirname(output_path), exist_ok=True)

def json_to_yaml(self,json_filepath):
"""
Convert a JSON file to a YAML file.
with open(input_filepath, 'r') as infile:
if input_type == 'yaml':
content = yaml.safe_load(infile)
else:
content = json.load(infile)

with open(output_path, 'w') as outfile:
if output_type == 'yaml':
yaml.dump(content, outfile, allow_unicode=True, default_flow_style=False)
else:
json.dump(content, outfile, indent=2)

print(f"Successfully converted {input_filepath} to {output_filename}")
return output_path

:param json_filepath: Path to the input JSON file.
"""
try:
# Get the filename from the path
filename = os.path.basename(json_filepath)
yaml_filepath = filename.split(".json")[0] + ".yaml"
converted_path = os.path.join(self.filepath, "yaml")
if not os.path.exists(converted_path):
os.makedirs(converted_path, exist_ok=True)
with open(json_filepath, 'r') as json_file:
json_content = json.load(json_file)
final_path = os.path.join(converted_path, yaml_filepath)

with open(final_path, 'w') as yaml_file:
yaml.dump(json_content, yaml_file, allow_unicode=True, default_flow_style=False)

print(f"Successfully converted {json_filepath} to {yaml_filepath}")
except Exception as e:
print(f"Error converting JSON to YAML: {e}")
print(f"Error converting {input_filepath}: {e}")
return None

def yaml_to_json(self, yaml_filepath):
"""Convert a YAML file to a JSON file."""
return self.convert_file(yaml_filepath, "json", 'yaml', 'json')

def json_to_yaml(self, json_filepath):
"""Convert a JSON file to a YAML file."""
return self.convert_file(json_filepath, "yaml", 'json', 'yaml')


# Usage example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def print_api_details(self):

# Usage example
if __name__ == '__main__':
openapi_parser = OpenAPISpecificationParser('/path/to/your/openapi_spec_example3.yaml')
openapi_parser = OpenAPISpecificationParser('/home/diana/Desktop/masterthesis/hackingBuddyGPT/src/hackingBuddyGPT/usecases/web_api_testing/openapi_spec/openapi_spec_2024-06-13_17-16-25.yaml')
openapi_parser.print_api_details()