Skip to content

Commit 25410c1

Browse files
authored
update generated test code (#4)
* remove unnecessary Random, create Regex as consts * generate models and apis in subfolders * export statements are not generated by default
1 parent 156f0b1 commit 25410c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+331
-287
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.openapi-generator-ignore
21
README.md
32
docs/ApiResponse.md
43
docs/Category.md
@@ -10,13 +9,13 @@ docs/Tag.md
109
docs/User.md
1110
docs/UserApi.md
1211
src/PetStoreClient.jl
13-
src/api_PetApi.jl
14-
src/api_StoreApi.jl
15-
src/api_UserApi.jl
16-
src/model_ApiResponse.jl
17-
src/model_Category.jl
18-
src/model_Order.jl
19-
src/model_Pet.jl
20-
src/model_Tag.jl
21-
src/model_User.jl
12+
src/apis/api_PetApi.jl
13+
src/apis/api_StoreApi.jl
14+
src/apis/api_UserApi.jl
2215
src/modelincludes.jl
16+
src/models/model_ApiResponse.jl
17+
src/models/model_Category.jl
18+
src/models/model_Order.jl
19+
src/models/model_Pet.jl
20+
src/models/model_Tag.jl
21+
src/models/model_User.jl

test/client/petstore_v2/petstore/src/PetStoreClient.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33

44
module PetStoreClient
55

6-
using Random
76
using Dates, TimeZones
87
using OpenAPI
98
using OpenAPI.Clients
109

1110
include("modelincludes.jl")
1211

13-
include("api_PetApi.jl")
14-
include("api_StoreApi.jl")
15-
include("api_UserApi.jl")
16-
17-
export check_required
12+
include("apis/api_PetApi.jl")
13+
include("apis/api_StoreApi.jl")
14+
include("apis/api_UserApi.jl")
1815

1916
# export models
2017
export ApiResponse

test/client/petstore_v2/petstore/src/api_PetApi.jl renamed to test/client/petstore_v2/petstore/src/apis/api_PetApi.jl

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ struct PetApi <: OpenAPI.APIClientImpl
55
client::OpenAPI.Clients.Client
66
end
77

8-
function _oacinternal_add_pet(_api::PetApi, body::Pet; _mediaType=nothing)
9-
return_types = Dict{Regex,Type}()
10-
return_types[Regex("^" * replace("405", "x"=>".") * "\$")] = Nothing
8+
const _returntypes_add_pet = Dict{Regex,Type}(
9+
Regex("^" * replace("405", "x"=>".") * "\$") => Nothing,
10+
)
1111

12-
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", return_types, "/pet", ["petstore_auth", ], body)
12+
function _oacinternal_add_pet(_api::PetApi, body::Pet; _mediaType=nothing)
13+
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", _returntypes_add_pet, "/pet", ["petstore_auth", ], body)
1314
OpenAPI.Clients.set_header_accept(_ctx, [])
1415
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "application/xml", ] : [_mediaType])
1516
return _ctx
@@ -32,12 +33,13 @@ function add_pet(_api::PetApi, response_stream::Channel, body::Pet; _mediaType=n
3233
return OpenAPI.Clients.exec(_ctx, response_stream)
3334
end
3435

35-
function _oacinternal_delete_pet(_api::PetApi, pet_id::Int64; api_key=nothing, _mediaType=nothing)
36-
return_types = Dict{Regex,Type}()
37-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
38-
return_types[Regex("^" * replace("404", "x"=>".") * "\$")] = Nothing
36+
const _returntypes_delete_pet = Dict{Regex,Type}(
37+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
38+
Regex("^" * replace("404", "x"=>".") * "\$") => Nothing,
39+
)
3940

40-
_ctx = OpenAPI.Clients.Ctx(_api.client, "DELETE", return_types, "/pet/{petId}", ["petstore_auth", ])
41+
function _oacinternal_delete_pet(_api::PetApi, pet_id::Int64; api_key=nothing, _mediaType=nothing)
42+
_ctx = OpenAPI.Clients.Ctx(_api.client, "DELETE", _returntypes_delete_pet, "/pet/{petId}", ["petstore_auth", ])
4143
OpenAPI.Clients.set_param(_ctx.path, "petId", pet_id) # type Int64
4244
OpenAPI.Clients.set_param(_ctx.header, "api_key", api_key) # type String
4345
OpenAPI.Clients.set_header_accept(_ctx, [])
@@ -63,12 +65,13 @@ function delete_pet(_api::PetApi, response_stream::Channel, pet_id::Int64; api_k
6365
return OpenAPI.Clients.exec(_ctx, response_stream)
6466
end
6567

66-
function _oacinternal_find_pets_by_status(_api::PetApi, status::Vector{String}; _mediaType=nothing)
67-
return_types = Dict{Regex,Type}()
68-
return_types[Regex("^" * replace("200", "x"=>".") * "\$")] = Vector{Pet}
69-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
68+
const _returntypes_find_pets_by_status = Dict{Regex,Type}(
69+
Regex("^" * replace("200", "x"=>".") * "\$") => Vector{Pet},
70+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
71+
)
7072

71-
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", return_types, "/pet/findByStatus", ["petstore_auth", ])
73+
function _oacinternal_find_pets_by_status(_api::PetApi, status::Vector{String}; _mediaType=nothing)
74+
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_find_pets_by_status, "/pet/findByStatus", ["petstore_auth", ])
7275
OpenAPI.Clients.set_param(_ctx.query, "status", status) # type Vector{String}
7376
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", "application/xml", ])
7477
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType])
@@ -94,12 +97,13 @@ function find_pets_by_status(_api::PetApi, response_stream::Channel, status::Vec
9497
return OpenAPI.Clients.exec(_ctx, response_stream)
9598
end
9699

97-
function _oacinternal_find_pets_by_tags(_api::PetApi, tags::Vector{String}; _mediaType=nothing)
98-
return_types = Dict{Regex,Type}()
99-
return_types[Regex("^" * replace("200", "x"=>".") * "\$")] = Vector{Pet}
100-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
100+
const _returntypes_find_pets_by_tags = Dict{Regex,Type}(
101+
Regex("^" * replace("200", "x"=>".") * "\$") => Vector{Pet},
102+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
103+
)
101104

102-
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", return_types, "/pet/findByTags", ["petstore_auth", ])
105+
function _oacinternal_find_pets_by_tags(_api::PetApi, tags::Vector{String}; _mediaType=nothing)
106+
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_find_pets_by_tags, "/pet/findByTags", ["petstore_auth", ])
103107
OpenAPI.Clients.set_param(_ctx.query, "tags", tags) # type Vector{String}
104108
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", "application/xml", ])
105109
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType])
@@ -125,13 +129,14 @@ function find_pets_by_tags(_api::PetApi, response_stream::Channel, tags::Vector{
125129
return OpenAPI.Clients.exec(_ctx, response_stream)
126130
end
127131

128-
function _oacinternal_get_pet_by_id(_api::PetApi, pet_id::Int64; _mediaType=nothing)
129-
return_types = Dict{Regex,Type}()
130-
return_types[Regex("^" * replace("200", "x"=>".") * "\$")] = Pet
131-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
132-
return_types[Regex("^" * replace("404", "x"=>".") * "\$")] = Nothing
132+
const _returntypes_get_pet_by_id = Dict{Regex,Type}(
133+
Regex("^" * replace("200", "x"=>".") * "\$") => Pet,
134+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
135+
Regex("^" * replace("404", "x"=>".") * "\$") => Nothing,
136+
)
133137

134-
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", return_types, "/pet/{petId}", ["api_key", ])
138+
function _oacinternal_get_pet_by_id(_api::PetApi, pet_id::Int64; _mediaType=nothing)
139+
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_get_pet_by_id, "/pet/{petId}", ["api_key", ])
135140
OpenAPI.Clients.set_param(_ctx.path, "petId", pet_id) # type Int64
136141
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", "application/xml", ])
137142
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType])
@@ -157,13 +162,14 @@ function get_pet_by_id(_api::PetApi, response_stream::Channel, pet_id::Int64; _m
157162
return OpenAPI.Clients.exec(_ctx, response_stream)
158163
end
159164

160-
function _oacinternal_update_pet(_api::PetApi, body::Pet; _mediaType=nothing)
161-
return_types = Dict{Regex,Type}()
162-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
163-
return_types[Regex("^" * replace("404", "x"=>".") * "\$")] = Nothing
164-
return_types[Regex("^" * replace("405", "x"=>".") * "\$")] = Nothing
165+
const _returntypes_update_pet = Dict{Regex,Type}(
166+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
167+
Regex("^" * replace("404", "x"=>".") * "\$") => Nothing,
168+
Regex("^" * replace("405", "x"=>".") * "\$") => Nothing,
169+
)
165170

166-
_ctx = OpenAPI.Clients.Ctx(_api.client, "PUT", return_types, "/pet", ["petstore_auth", ], body)
171+
function _oacinternal_update_pet(_api::PetApi, body::Pet; _mediaType=nothing)
172+
_ctx = OpenAPI.Clients.Ctx(_api.client, "PUT", _returntypes_update_pet, "/pet", ["petstore_auth", ], body)
167173
OpenAPI.Clients.set_header_accept(_ctx, [])
168174
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", "application/xml", ] : [_mediaType])
169175
return _ctx
@@ -186,11 +192,12 @@ function update_pet(_api::PetApi, response_stream::Channel, body::Pet; _mediaTyp
186192
return OpenAPI.Clients.exec(_ctx, response_stream)
187193
end
188194

189-
function _oacinternal_update_pet_with_form(_api::PetApi, pet_id::Int64; name=nothing, status=nothing, _mediaType=nothing)
190-
return_types = Dict{Regex,Type}()
191-
return_types[Regex("^" * replace("405", "x"=>".") * "\$")] = Nothing
195+
const _returntypes_update_pet_with_form = Dict{Regex,Type}(
196+
Regex("^" * replace("405", "x"=>".") * "\$") => Nothing,
197+
)
192198

193-
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", return_types, "/pet/{petId}", ["petstore_auth", ])
199+
function _oacinternal_update_pet_with_form(_api::PetApi, pet_id::Int64; name=nothing, status=nothing, _mediaType=nothing)
200+
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", _returntypes_update_pet_with_form, "/pet/{petId}", ["petstore_auth", ])
194201
OpenAPI.Clients.set_param(_ctx.path, "petId", pet_id) # type Int64
195202
OpenAPI.Clients.set_param(_ctx.form, "name", name) # type String
196203
OpenAPI.Clients.set_param(_ctx.form, "status", status) # type String
@@ -218,11 +225,12 @@ function update_pet_with_form(_api::PetApi, response_stream::Channel, pet_id::In
218225
return OpenAPI.Clients.exec(_ctx, response_stream)
219226
end
220227

221-
function _oacinternal_upload_file(_api::PetApi, pet_id::Int64; additional_metadata=nothing, file=nothing, _mediaType=nothing)
222-
return_types = Dict{Regex,Type}()
223-
return_types[Regex("^" * replace("200", "x"=>".") * "\$")] = ApiResponse
228+
const _returntypes_upload_file = Dict{Regex,Type}(
229+
Regex("^" * replace("200", "x"=>".") * "\$") => ApiResponse,
230+
)
224231

225-
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", return_types, "/pet/{petId}/uploadImage", ["petstore_auth", ])
232+
function _oacinternal_upload_file(_api::PetApi, pet_id::Int64; additional_metadata=nothing, file=nothing, _mediaType=nothing)
233+
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", _returntypes_upload_file, "/pet/{petId}/uploadImage", ["petstore_auth", ])
226234
OpenAPI.Clients.set_param(_ctx.path, "petId", pet_id) # type Int64
227235
OpenAPI.Clients.set_param(_ctx.form, "additionalMetadata", additional_metadata) # type String
228236
OpenAPI.Clients.set_param(_ctx.file, "file", file) # type String

test/client/petstore_v2/petstore/src/api_StoreApi.jl renamed to test/client/petstore_v2/petstore/src/apis/api_StoreApi.jl

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ struct StoreApi <: OpenAPI.APIClientImpl
55
client::OpenAPI.Clients.Client
66
end
77

8+
const _returntypes_delete_order = Dict{Regex,Type}(
9+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
10+
Regex("^" * replace("404", "x"=>".") * "\$") => Nothing,
11+
)
12+
813
function _oacinternal_delete_order(_api::StoreApi, order_id::Int64; _mediaType=nothing)
914
OpenAPI.validate_param("order_id", "delete_order", :minimum, order_id, 1, false)
1015

11-
return_types = Dict{Regex,Type}()
12-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
13-
return_types[Regex("^" * replace("404", "x"=>".") * "\$")] = Nothing
14-
15-
_ctx = OpenAPI.Clients.Ctx(_api.client, "DELETE", return_types, "/store/order/{orderId}", [])
16+
_ctx = OpenAPI.Clients.Ctx(_api.client, "DELETE", _returntypes_delete_order, "/store/order/{orderId}", [])
1617
OpenAPI.Clients.set_param(_ctx.path, "orderId", order_id) # type Int64
1718
OpenAPI.Clients.set_header_accept(_ctx, [])
1819
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType])
@@ -38,11 +39,12 @@ function delete_order(_api::StoreApi, response_stream::Channel, order_id::Int64;
3839
return OpenAPI.Clients.exec(_ctx, response_stream)
3940
end
4041

41-
function _oacinternal_get_inventory(_api::StoreApi; _mediaType=nothing)
42-
return_types = Dict{Regex,Type}()
43-
return_types[Regex("^" * replace("200", "x"=>".") * "\$")] = Dict{String, Int64}
42+
const _returntypes_get_inventory = Dict{Regex,Type}(
43+
Regex("^" * replace("200", "x"=>".") * "\$") => Dict{String, Int64},
44+
)
4445

45-
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", return_types, "/store/inventory", ["api_key", ])
46+
function _oacinternal_get_inventory(_api::StoreApi; _mediaType=nothing)
47+
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_get_inventory, "/store/inventory", ["api_key", ])
4648
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", ])
4749
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType])
4850
return _ctx
@@ -66,16 +68,17 @@ function get_inventory(_api::StoreApi, response_stream::Channel; _mediaType=noth
6668
return OpenAPI.Clients.exec(_ctx, response_stream)
6769
end
6870

71+
const _returntypes_get_order_by_id = Dict{Regex,Type}(
72+
Regex("^" * replace("200", "x"=>".") * "\$") => Order,
73+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
74+
Regex("^" * replace("404", "x"=>".") * "\$") => Nothing,
75+
)
76+
6977
function _oacinternal_get_order_by_id(_api::StoreApi, order_id::Int64; _mediaType=nothing)
7078
OpenAPI.validate_param("order_id", "get_order_by_id", :maximum, order_id, 10, false)
7179
OpenAPI.validate_param("order_id", "get_order_by_id", :minimum, order_id, 1, false)
7280

73-
return_types = Dict{Regex,Type}()
74-
return_types[Regex("^" * replace("200", "x"=>".") * "\$")] = Order
75-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
76-
return_types[Regex("^" * replace("404", "x"=>".") * "\$")] = Nothing
77-
78-
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", return_types, "/store/order/{orderId}", [])
81+
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_get_order_by_id, "/store/order/{orderId}", [])
7982
OpenAPI.Clients.set_param(_ctx.path, "orderId", order_id) # type Int64
8083
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", "application/xml", ])
8184
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType])
@@ -101,12 +104,13 @@ function get_order_by_id(_api::StoreApi, response_stream::Channel, order_id::Int
101104
return OpenAPI.Clients.exec(_ctx, response_stream)
102105
end
103106

104-
function _oacinternal_place_order(_api::StoreApi, body::Order; _mediaType=nothing)
105-
return_types = Dict{Regex,Type}()
106-
return_types[Regex("^" * replace("200", "x"=>".") * "\$")] = Order
107-
return_types[Regex("^" * replace("400", "x"=>".") * "\$")] = Nothing
107+
const _returntypes_place_order = Dict{Regex,Type}(
108+
Regex("^" * replace("200", "x"=>".") * "\$") => Order,
109+
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
110+
)
108111

109-
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", return_types, "/store/order", [], body)
112+
function _oacinternal_place_order(_api::StoreApi, body::Order; _mediaType=nothing)
113+
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", _returntypes_place_order, "/store/order", [], body)
110114
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", "application/xml", ])
111115
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json", ] : [_mediaType])
112116
return _ctx

0 commit comments

Comments
 (0)