@@ -10,16 +10,16 @@ const BaseTypes = ("String", "Float64", "Float32", "Int", "Int64", "Int32", "Int
10
10
const ModelPrefixes = (" IoK8sApimachineryPkgApis" , " IoK8sApimachineryPkg" , " IoK8sApi" , " IoK8sKubeAggregatorPkgApis" , " IoK8sApiextensionsApiserverPkgApis" )
11
11
12
12
function get_swagger_ctx_call_return_type (fn_body)
13
- all_calls = findall (x-> (x . typ === CSTParser. BinaryOpCall ), fn_body. args)
13
+ all_calls = findall (x-> CSTParser. isbinarysyntax (x ), fn_body. args)
14
14
for nidx in all_calls
15
15
ncall = fn_body. args[nidx]
16
- fc = ncall. args[3 ]
16
+ fc = ncall. args[2 ]
17
17
if CSTParser. is_func_call (fc)
18
18
binop = fc. args[1 ]
19
- if binop . typ === CSTParser. BinaryOpCall
20
- if (CSTParser. str_value (binop. args[1 ]) == " Swagger" ) && CSTParser. is_dot (binop. args[ 2 ] ) && (binop. args[3 ] . typ === CSTParser . Quotenode ) && (CSTParser. str_value (binop. args[3 ]. args[1 ]) == " Ctx" )
21
- if (length (fc. args) > 6 ) && CSTParser. isidentifier (fc. args[7 ])
22
- return CSTParser. str_value (fc. args[7 ])
19
+ if CSTParser. isbinarysyntax (binop)
20
+ if (CSTParser. str_value (binop. args[1 ]) == " Swagger" ) && CSTParser. is_dot (binop. head ) && (binop. args[2 ] . head === :quotenode ) && (CSTParser. str_value (binop. args[2 ]. args[1 ]) == " Ctx" )
21
+ if (length (fc. args) > 3 ) && CSTParser. isidentifier (fc. args[4 ])
22
+ return CSTParser. str_value (fc. args[4 ])
23
23
end
24
24
end
25
25
end
32
32
Adds Swagger API call return types to be aliased to undecorated names.
33
33
"""
34
34
function emit_alias (fn_expr:: CSTParser.EXPR , api_decoration:: String , aliases:: KuberTypeAliasesSet )
35
- fn_body = CSTParser . get_body ( fn_expr)
35
+ fn_body = fn_expr. args[ end ]
36
36
return_type = get_swagger_ctx_call_return_type (fn_body)
37
37
((nothing === return_type) || (return_type in BaseTypes)) && return
38
38
push! (get! (()-> Set {String} (), aliases, api_decoration), return_type)
@@ -46,19 +46,19 @@ function kuberapitypes(file::String, aliases_set::KuberTypeAliasesSet)
46
46
x, ps = CSTParser. parse (ParseState (String (readchomp (file))))
47
47
api_decoration = " "
48
48
49
- while ! ps. done
49
+ while ! ps. done && (CSTParser . kindof (ps . nt) != = CSTParser . Tokens . ENDMARKER)
50
50
structsig = nothing
51
51
if CSTParser. defines_struct (x)
52
52
structsig = CSTParser. get_sig (x)
53
- elseif x . typ == CSTParser. MacroCall && CSTParser. str_value (x[1 ]) == " @doc"
53
+ elseif CSTParser. ismacrocall (x) && CSTParser. str_value (x[1 ]) == " @doc"
54
54
structsig = CSTParser. get_sig (x[3 ])
55
55
end
56
56
57
57
if structsig != = nothing
58
- if structsig . typ === CSTParser. BinaryOpCall
59
- op = structsig. args[ 2 ]
58
+ if CSTParser. isbinarysyntax (structsig)
59
+ op = structsig. head
60
60
if CSTParser. is_issubt (op)
61
- subtyp = CSTParser. str_value (CSTParser. get_name (structsig. args[3 ]))
61
+ subtyp = CSTParser. str_value (CSTParser. get_name (structsig. args[2 ]))
62
62
if subtyp == " SwaggerApi"
63
63
typename = CSTParser. str_value (CSTParser. get_name (structsig. args[1 ]))
64
64
if endswith (typename, " Api" )
@@ -71,7 +71,7 @@ function kuberapitypes(file::String, aliases_set::KuberTypeAliasesSet)
71
71
# Note: We are guaranteed to receive the struct definition before methods
72
72
# because of the sequence in which Swagger code is generated and also
73
73
# because of the Julia restriction of type being defined before use
74
- fn_expr = ((x . typ === CSTParser. MacroCall ) && CSTParser. defines_function (x. args[3 ])) ? x. args[3 ] : CSTParser. defines_function (x) ? x : nothing
74
+ fn_expr = (CSTParser. ismacrocall (x ) && CSTParser. defines_function (x. args[4 ])) ? x. args[4 ] : CSTParser. defines_function (x) ? x : nothing
75
75
if fn_expr != = nothing
76
76
emit_alias (fn_expr, api_decoration, aliases_set)
77
77
end
@@ -110,16 +110,21 @@ end
110
110
function kubermodeltypes (file:: String , sorted_apis:: Vector{String} , aliases_set:: KuberTypeAliasesSet , unmapped:: Set{String} )
111
111
x, ps = CSTParser. parse (ParseState (String (readchomp (file))))
112
112
113
- while ! ps. done
113
+ while ! ps. done && (CSTParser . kindof (ps . nt) != = CSTParser . Tokens . ENDMARKER)
114
114
structsig = nothing
115
115
if CSTParser. defines_struct (x)
116
116
structsig = CSTParser. get_sig (x)
117
- elseif x. typ == CSTParser. MacroCall && CSTParser. str_value (x[1 ]) == " @doc"
118
- structsig = CSTParser. get_sig (x[3 ])
117
+ elseif CSTParser. ismacrocall (x) && CSTParser. str_value (x[1 ]) == " @doc"
118
+ for elem in x
119
+ if CSTParser. defines_struct (elem)
120
+ structsig = elem
121
+ break
122
+ end
123
+ end
119
124
end
120
125
121
126
if structsig != = nothing
122
- model_name = CSTParser. str_value (CSTParser. get_name (structsig. args[ 1 ] ))
127
+ model_name = CSTParser. str_value (CSTParser. get_name (structsig))
123
128
if ! startswith (model_name, " IoK8sKubernetes" ) && ! (model_name == " IoK8sApimachineryPkgRuntimeRawExtension" )
124
129
api_idx = find_matching_api (sorted_apis, model_name)
125
130
if api_idx != = nothing
@@ -201,8 +206,12 @@ function gen_aliases(folder::String, output::String)
201
206
end
202
207
203
208
function main ()
204
- DIR = dirname (@__FILE__ )
205
- gen_aliases (joinpath (DIR, " ../src/ApiImpl/api" ), joinpath (DIR, " ../src/ApiImpl/typealiases.jl" ))
209
+ if length (ARGS ) > 0
210
+ output_path = ARGS [1 ]
211
+ else
212
+ output_path = joinpath (dirname (dirname (__FILE__)), " src" , " ApiImpl" )
213
+ end
214
+ gen_aliases (joinpath (output_path, " api" ), joinpath (output_path, " typealiases.jl" ))
206
215
end
207
216
208
217
main ()
0 commit comments