Skip to content
Snippets Groups Projects
Commit 8a81dd79 authored by Sebastian Böckelmann (NET Hiwi)'s avatar Sebastian Böckelmann (NET Hiwi)
Browse files

Refactor generation of api object type

parent 5cdc1f3d
No related branches found
No related tags found
No related merge requests found
from click.testing import CliRunner
import net_api_generator.generator
from net_api_generator.generator import es_webpack, vite, openapi
from net_api_generator.generator import es_webpack, typescript, openapi
if __name__ == "__main__":
net_api_generator.generator.loader.load()
# es_webpack(['--output-dir', 'test-out'])
vite(['--output-dir', 'test-out'])
typescript(['--output-dir', 'test-out'])
# openapi(['--default_endpoint', 'devel'])
\ No newline at end of file
......@@ -243,7 +243,7 @@ from typing import Union
f.close()
@cli.command(name='vite')
@click.option('--output-dir', default='src/api-services.gen/')
def vite(output_dir):
def typescript(output_dir):
def prepare_generation(output_dir):
# Check if output_dir exists - when not create it
if not os.path.isdir(output_dir):
......@@ -266,12 +266,20 @@ def vite(output_dir):
return data_type['json_name']
def generate_api_object(api_object: APIObject) -> str:
code = "export interface " + api_object.name + " {\n"
attributes = ""
for attribute_key, attribute in api_object.attributes.items():
attributes += "\t" + attribute_key + ": " + map_netdb_type_to_typescript_type(attribute.data_type) + "\n"
code += attributes + "}"
return code
code_template = ("export interface $APIOBJCT_NAME {\n"
"\t$ATTRIBUTE_LIST_ITEM"
"}")
code_template = code_template.replace("$APIOBJCT_NAME", api_object.name)
for index, attribute in enumerate(api_object.attributes.values()):
attribute_list_item = attribute.name + ": " + map_netdb_type_to_typescript_type(attribute.data_type)
if index < len(api_object.attributes) - 1:
replace_string = attribute_list_item + "\n\t$ATTRIBUTE_LIST_ITEM"
else:
replace_string = attribute_list_item + "\n"
code_template = code_template.replace("$ATTRIBUTE_LIST_ITEM", replace_string)
return code_template
def generate_param_list_type():
return "export interface ParamList {\n\t old: string[],\n\t new: string[]\n}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment