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
a99ebb50
Commit
a99ebb50
authored
1 month ago
by
Sebastian Böckelmann
Browse files
Options
Downloads
Patches
Plain Diff
UPD: Fix typos in generated api code
parent
3b1173fd
No related branches found
Branches containing commit
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
+22
-17
22 additions, 17 deletions
net_api_generator/generator.py
with
22 additions
and
17 deletions
net_api_generator/generator.py
+
22
−
17
View file @
a99ebb50
...
...
@@ -286,11 +286,11 @@ def typescript(output_dir):
def
generate_imports
()
->
str
:
return
(
"
import type { ParamList } from
'
@/util/api/ParamList
'
\n
"
"
import type { AxiosConfig } from
'
@/util/api/AxiosConfig
"
"
import type {
AxiosRe
"
"
import type { AxiosRequestConfig } from
'
axios
'"
"
import type { AxiosConfig } from
'
@/util/api/AxiosConfig
'
\n
"
"
import type {
AxiosCreateRequestBody, AxiosDeleteRequestBody, AxiosUpdateRequestBody} from
'
@/util/api/AxiosRequestBody
'
\n
"
"
import type { AxiosRequestConfig } from
'
axios
'
\n
"
"
import { useAxios, type UseAxiosReturn } from
'
@vueuse/integrations/useAxios
'
\n
"
"
import APIUtils from
'
@/util/apiutil
'
\n
"
"
import APIUtils from
'
@/util/
api/
apiutil
'
\n
"
"
import NETVSConfig from
'
@/netvs.config
'
\n\n
"
)
...
...
@@ -324,13 +324,13 @@ def typescript(output_dir):
def
generate_api_function
(
api_function
:
ApiFunction
)
->
str
:
api_call
=
(
"
$METHOD_NAME (config: AxiosConfig, $FUNCTION_PARAMETER)
$RETURN_TYPE {
\n
"
"
\t
const requestData = $REQUEST_DATA
\n\n
"
api_call
=
(
"
$METHOD_NAME (config: AxiosConfig, $FUNCTION_PARAMETER)$RETURN_TYPE {
\n
"
"
\t
const requestData
: $AXIOS_REQUEST_DATA
= $REQUEST_DATA
\n\n
"
"
\t
const axiosRequestConfig: AxiosRequestConfig<$AXIOS_REQUEST_DATA> = {
\n
"
"
\t\t
method: $HTTP_METHOD,
\n
"
"
\t\t
baseU
rl
: config.baseUrl,
\n
"
"
\t\t
headers: config.headers
\n
"
"
\t\t
method:
'
$HTTP_METHOD
'
,
\n
"
"
\t\t
baseU
RL
: config.baseUrl,
\n
"
"
\t\t
headers: config.headers
,
\n
"
"
\t\t
$PARAMS_OR_REQUEST_BODY: requestData
\n
"
"
\t
}
\n\n
"
"
\t
const url = `${NETVSConfig.NETDB_API_BASE_URL}/${NETVSConfig.NETDB_API_VERSION}/$PATH`
\n
"
...
...
@@ -342,7 +342,7 @@ def typescript(output_dir):
api_call
=
api_call
.
replace
(
"
$HTTP_METHOD
"
,
"
POST
"
if
api_function
.
is_data_manipulating
else
"
GET
"
)
api_call
=
api_call
.
replace
(
"
$PATH
"
,
api_function
.
fq_name
.
replace
(
"
.
"
,
"
/
"
))
return_type
=
f
"
Promise<UseAxiosReturn<
{
api_function
.
object_type
.
capitalize
()
}
>>
"
if
api_function
.
is_returning
else
""
return_type
=
f
"
:
Promise<UseAxiosReturn<
{
api_function
.
object_type
.
capitalize
()
}
>>
"
if
api_function
.
is_returning
else
""
api_call
=
api_call
.
replace
(
"
$RETURN_TYPE
"
,
return_type
)
api_call
=
api_call
.
replace
(
"
$RETURN_ENABLED
"
,
"
return
"
if
api_function
.
is_returning
else
""
)
...
...
@@ -353,8 +353,11 @@ def typescript(output_dir):
signature_length
=
indent
function_parameters
=
""
request_data
=
{
"
old
"
:
""
,
"
new
"
:
""
}
number_parameters
=
len
(
seperated_parameters
[
'
old
'
])
+
len
(
seperated_parameters
[
'
new
'
])
for
parameter_scope
,
parameter_list
in
seperated_parameters
.
items
():
for
i
,
parameter
in
enumerate
(
parameter_list
):
if
api_function
.
name
==
"
update
"
:
print
(
"
Update!
"
)
parameter_definition
=
"'
$PARAMETER_NAME
'
: $PARAMETER_NAME_REFERENCE
"
if
i
>
0
else
"
\t\t
'
$PARAMETER_NAME
'
: $PARAMETER_NAME_REFERENCE
"
if
api_function
.
is_data_manipulating
:
function_parameter_item
=
f
"
{
parameter
.
name
}
_
{
parameter_scope
}
:
{
map_netdb_type_to_typescript_type
(
parameter
.
data_type
)
}
"
...
...
@@ -371,13 +374,13 @@ def typescript(output_dir):
"
$PARAMETER_NAME
"
)
parameter_definition
=
parameter_definition
.
replace
(
"
$PARAMETER_NAME
"
,
parameter
.
name
)
if
parameter_counter
<
len
(
api_function
.
parameters
)
-
1
:
if
parameter_counter
<
number_
parameters
-
1
:
parameter_definition
+=
"
,
\n\t\t
"
request_data
[
"
old
"
]
+=
parameter_definition
if
parameter_counter
<
len
(
api_function
.
parameters
.
values
())
-
1
:
if
parameter_counter
<
number_parameters
-
1
:
if
signature_length
>
120
:
function_parameters
+=
function_parameter_item
+
"
\n
"
+
"
"
*
(
indent
+
1
)
function_parameters
+=
function_parameter_item
+
"
,
\n
"
+
"
"
*
(
indent
+
1
)
signature_length
=
indent
else
:
function_parameters
+=
function_parameter_item
+
"
,
"
...
...
@@ -398,16 +401,18 @@ def typescript(output_dir):
request_data_declaration_code
=
(
"
{
\n
"
"
\t\t
old: {
\n
"
f
"
\t\t\t
{
request_data
[
"
old
"
]
}
,
\n
"
"
\t\t
}
\n
"
"
\t\t
}
,
\n
"
"
\t\t
new: {
\n
"
f
"
\t\t\t
{
request_data
[
"
new
"
]
}
,
\n
"
"
\t\t
}
"
)
"
\t\t
}
\n
"
"
\t
}
"
)
elif
len
(
seperated_parameters
[
"
old
"
])
>
0
and
len
(
seperated_parameters
[
"
new
"
])
==
0
:
request_type
=
"
AxiosDeleteRequestBody<any>
"
request_data_declaration_code
=
(
"
{
\n
"
"
\t\t
old: {
\n
"
f
"
\t\t\t
{
request_data
[
"
old
"
]
}
,
\n
"
"
\t\t
}
"
)
"
\t\t
}
\n
"
"
\t
}
"
)
else
:
request_type
=
"
AxiosCreateRequestBody<any>
"
request_data_declaration_code
=
(
"
{
\n
"
...
...
@@ -419,7 +424,7 @@ def typescript(output_dir):
request_type
=
"
any
"
request_data_declaration_code
=
(
"
APIUtils.denullify_dict({
\n
"
f
"
{
request_data
[
"
old
"
]
}
\n
"
"
\t
}
"
)
"
\t
}
)
"
)
api_call
=
api_call
.
replace
(
"
$AXIOS_REQUEST_DATA
"
,
request_type
)
api_call
=
api_call
.
replace
(
"
$REQUEST_DATA
"
,
request_data_declaration_code
)
...
...
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