Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api-generator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scc-net
netvs
api-generator
Commits
8a81dd79
Commit
8a81dd79
authored
3 months ago
by
Sebastian Böckelmann (NET Hiwi)
Browse files
Options
Downloads
Patches
Plain Diff
Refactor generation of api object type
parent
5cdc1f3d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+2
-4
2 additions, 4 deletions
main.py
net_api_generator/generator.py
+15
-7
15 additions, 7 deletions
net_api_generator/generator.py
with
17 additions
and
11 deletions
main.py
+
2
−
4
View file @
8a81dd79
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
This diff is collapsed.
Click to expand it.
net_api_generator/generator.py
+
15
−
7
View file @
8a81dd79
...
...
@@ -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
}
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment