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
c4461378
Commit
c4461378
authored
3 months ago
by
Sebastian Böckelmann
Browse files
Options
Downloads
Patches
Plain Diff
Refactor generation of paramlist method
parent
8a81dd79
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
net_api_generator/generator.py
+25
-15
25 additions, 15 deletions
net_api_generator/generator.py
with
25 additions
and
15 deletions
net_api_generator/generator.py
+
25
−
15
View file @
c4461378
...
...
@@ -3,6 +3,7 @@ import os
import
re
import
sys
from
json
import
JSONEncoder
from
pprint
import
pprint
import
click
import
yaml
...
...
@@ -336,21 +337,30 @@ def typescript(output_dir):
return
api_code
def
generate_param_list
(
api_function
:
ApiFunction
)
->
str
:
paramlist_signature
=
"
\t
"
+
api_function
.
name
+
"
ParamsList(): ParamList {
\n
"
paramlist_return_statement
=
"
\t\t
return {
\n
"
paramlist_old
=
"
\t\t\t
'
old
'
: [$],
\n
"
paramlist_new
=
"
\t\t\t
'
new
'
: [$]
\n
"
for
function_parameter
in
api_function
.
parameters
.
items
():
if
function_parameter
[
1
].
old
is
not
None
:
paramlist_old
=
paramlist_old
.
replace
(
'
$
'
,
'
\'
'
+
function_parameter
[
1
].
name
+
'
\'
, $
'
)
if
function_parameter
[
1
].
new
is
not
None
:
paramlist_new
=
paramlist_new
.
replace
(
'
$
'
,
'
\'
'
+
function_parameter
[
1
].
name
+
'
\'
, $
'
)
paramlist_old
=
paramlist_old
.
replace
(
'
, $
'
,
''
)
paramlist_old
=
paramlist_old
.
replace
(
'
$
'
,
''
)
paramlist_new
=
paramlist_new
.
replace
(
'
, $
'
,
''
)
paramlist_new
=
paramlist_new
.
replace
(
'
$
'
,
''
)
paramlist_return_statement
+=
paramlist_old
+
paramlist_new
+
"
\t\t
}
"
return
paramlist_signature
+
paramlist_return_statement
+
"
\n\t
}
"
code_template
=
(
"
\t
$METHOD_NAMEParamList(): ParamList {
\n
"
"
\t\t
return {
\n
"
"
\t\t\t
'
old
'
: [$OLD],
\n
"
"
\t\t\t
'
new
'
: [$NEW],
\n
"
"
\t\t
}
\n
"
"
\t
}
"
)
code_template
=
code_template
.
replace
(
"
$METHOD_NAME
"
,
api_function
.
name
)
for
index
,
parameter
in
enumerate
(
api_function
.
parameters
.
values
()):
replace_string
=
"'"
+
parameter
.
name
+
"'"
if
parameter
.
old
is
not
None
:
if
index
<
len
(
api_function
.
parameters
)
-
1
:
replace_string
+=
"
, $OLD
"
code_template
=
code_template
.
replace
(
"
$OLD
"
,
replace_string
)
if
parameter
.
new
is
not
None
:
if
index
<
len
(
api_function
.
parameters
)
-
1
:
replace_string
+=
"
, $NEW
"
code_template
=
code_template
.
replace
(
"
$NEW
"
,
replace_string
)
# Cleanup to remove unused $OLD or $NEW
code_template
=
code_template
.
replace
(
'
$OLD
'
,
''
)
code_template
=
code_template
.
replace
(
'
$NEW
'
,
''
)
return
code_template
param_list_function
=
generate_param_list
(
api_function
)
api_function_code
=
generate_api_call
(
api_function
)
...
...
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