Skip to content

Commit 8b0aa92

Browse files
committed
tests for REST method and path overloading
1 parent 113a708 commit 8b0aa92

File tree

2 files changed

+113
-75
lines changed

2 files changed

+113
-75
lines changed

commons-core/src/test/scala/com/avsystem/commons/rest/RestTestApi.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ trait RestTestApi {
5151

5252
@pathDescription("path with a followed by b")
5353
@description("A really complex GET operation")
54-
@GET("a/b") def complexGet(
54+
@GET("multi/param") def complexGet(
5555
@Path("p1") p1: Int, @description("Very serious path parameter") @title("Stri") @Path p2: String,
5656
@Header("X-H1") h1: Int, @Header("X-H2") h2: String,
5757
q1: Int, @Query("q=2") @whenAbsent("q2def") q2: String = whenAbsent.value
5858
): Future[RestEntity]
5959

60-
@POST def multiParamPost(
60+
@POST("multi/param") def multiParamPost(
6161
@Path("p1") p1: Int, @Path p2: String,
6262
@Header("X-H1") h1: Int, @Header("X-H2") h2: String,
6363
@Query q1: Int, @Query("q=2") q2: String,
@@ -86,7 +86,12 @@ trait RestTestApi {
8686

8787
def complexParams(
8888
baseEntity: BaseEntity,
89-
flatBaseEntity: Opt[FlatBaseEntity] = Opt.Empty
89+
@whenAbsent(Opt.Empty) flatBaseEntity: Opt[FlatBaseEntity]
90+
): Future[Unit]
91+
92+
@PUT def complexParams(
93+
flatBaseEntity: FlatBaseEntity,
94+
@whenAbsent(Opt.Empty) baseEntity: Opt[BaseEntity]
9095
): Future[Unit]
9196

9297
def customResponse(@Query value: String): Future[CustomResp]
@@ -107,6 +112,7 @@ object RestTestApi extends DefaultRestApiCompanion[RestTestApi] {
107112
def prefix(p0: String, h0: String, q0: String): RestTestSubApi =
108113
RestTestSubApi.impl(s"$p0-$h0-$q0")
109114
def complexParams(baseEntity: BaseEntity, flatBaseEntity: Opt[FlatBaseEntity]): Future[Unit] = Future.unit
115+
def complexParams(flatBaseEntity: FlatBaseEntity, baseEntity: Opt[BaseEntity]): Future[Unit] = Future.unit
110116
def customResponse(value: String): Future[CustomResp] = Future.successful(CustomResp(value))
111117
}
112118
}

commons-core/src/test/scala/com/avsystem/commons/rest/openapi/OpenApiGenerationTest.scala

Lines changed: 104 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -53,80 +53,40 @@ class OpenApiGenerationTest extends FunSuite {
5353
| }
5454
| }
5555
| },
56-
| "/a/b/{p1}/p1/{p2}": {
57-
| "description": "path with a followed by b",
58-
| "get": {
59-
| "description": "A really complex GET operation",
60-
| "operationId": "complexGet",
61-
| "parameters": [
62-
| {
63-
| "name": "p1",
64-
| "in": "path",
65-
| "required": true,
66-
| "schema": {
67-
| "type": "integer",
68-
| "format": "int32"
69-
| }
70-
| },
71-
| {
72-
| "name": "p2",
73-
| "in": "path",
74-
| "description": "Very serious path parameter",
75-
| "required": true,
76-
| "schema": {
77-
| "type": "string",
78-
| "title": "Stri"
79-
| }
80-
| },
81-
| {
82-
| "name": "X-H1",
83-
| "in": "header",
84-
| "required": true,
85-
| "schema": {
86-
| "type": "integer",
87-
| "format": "int32"
88-
| }
89-
| },
90-
| {
91-
| "name": "X-H2",
92-
| "in": "header",
93-
| "required": true,
94-
| "schema": {
95-
| "type": "string"
96-
| }
97-
| },
98-
| {
99-
| "name": "q1",
100-
| "in": "query",
101-
| "required": true,
102-
| "schema": {
103-
| "type": "integer",
104-
| "format": "int32"
56+
| "/complexParams": {
57+
| "put": {
58+
| "operationId": "put_complexParams",
59+
| "requestBody": {
60+
| "content": {
61+
| "application/json": {
62+
| "schema": {
63+
| "type": "object",
64+
| "properties": {
65+
| "flatBaseEntity": {
66+
| "$ref": "#/components/schemas/FlatBaseEntity"
67+
| },
68+
| "baseEntity": {
69+
| "nullable": true,
70+
| "allOf": [
71+
| {
72+
| "$ref": "#/components/schemas/BaseEntity"
73+
| }
74+
| ],
75+
| "default": null
76+
| }
77+
| },
78+
| "required": [
79+
| "flatBaseEntity"
80+
| ]
81+
| }
10582
| }
10683
| },
107-
| {
108-
| "name": "q=2",
109-
| "in": "query",
110-
| "schema": {
111-
| "type": "string",
112-
| "default": "q2def"
113-
| }
114-
| }
115-
| ],
84+
| "required": true
85+
| },
11686
| "responses": {
117-
| "200": {
118-
| "content": {
119-
| "application/json": {
120-
| "schema": {
121-
| "$ref": "#/components/schemas/RestEntity"
122-
| }
123-
| }
124-
| }
125-
| }
87+
| "204": {}
12688
| }
127-
| }
128-
| },
129-
| "/complexParams": {
89+
| },
13090
| "post": {
13191
| "operationId": "complexParams",
13292
| "requestBody": {
@@ -144,7 +104,8 @@ class OpenApiGenerationTest extends FunSuite {
144104
| {
145105
| "$ref": "#/components/schemas/FlatBaseEntity"
146106
| }
147-
| ]
107+
| ],
108+
| "default": null
148109
| }
149110
| },
150111
| "required": [
@@ -258,7 +219,78 @@ class OpenApiGenerationTest extends FunSuite {
258219
| }
259220
| }
260221
| },
261-
| "/multiParamPost/{p1}/p1/{p2}": {
222+
| "/multi/param/{p1}/p1/{p2}": {
223+
| "description": "path with a followed by b",
224+
| "get": {
225+
| "description": "A really complex GET operation",
226+
| "operationId": "complexGet",
227+
| "parameters": [
228+
| {
229+
| "name": "p1",
230+
| "in": "path",
231+
| "required": true,
232+
| "schema": {
233+
| "type": "integer",
234+
| "format": "int32"
235+
| }
236+
| },
237+
| {
238+
| "name": "p2",
239+
| "in": "path",
240+
| "description": "Very serious path parameter",
241+
| "required": true,
242+
| "schema": {
243+
| "type": "string",
244+
| "title": "Stri"
245+
| }
246+
| },
247+
| {
248+
| "name": "X-H1",
249+
| "in": "header",
250+
| "required": true,
251+
| "schema": {
252+
| "type": "integer",
253+
| "format": "int32"
254+
| }
255+
| },
256+
| {
257+
| "name": "X-H2",
258+
| "in": "header",
259+
| "required": true,
260+
| "schema": {
261+
| "type": "string"
262+
| }
263+
| },
264+
| {
265+
| "name": "q1",
266+
| "in": "query",
267+
| "required": true,
268+
| "schema": {
269+
| "type": "integer",
270+
| "format": "int32"
271+
| }
272+
| },
273+
| {
274+
| "name": "q=2",
275+
| "in": "query",
276+
| "schema": {
277+
| "type": "string",
278+
| "default": "q2def"
279+
| }
280+
| }
281+
| ],
282+
| "responses": {
283+
| "200": {
284+
| "content": {
285+
| "application/json": {
286+
| "schema": {
287+
| "$ref": "#/components/schemas/RestEntity"
288+
| }
289+
| }
290+
| }
291+
| }
292+
| }
293+
| },
262294
| "post": {
263295
| "operationId": "multiParamPost",
264296
| "parameters": [

0 commit comments

Comments
 (0)