Skip to content

Commit 081d1d4

Browse files
committed
write http operations in source order
1 parent d13c7b6 commit 081d1d4

8 files changed

Lines changed: 39 additions & 47 deletions

File tree

  • openapi-processor-core-parser-api/src/main/kotlin/io/openapiprocessor/core/parser
  • openapi-processor-core-parser-openapi4j/src/main/kotlin/io/openapiprocessor/core/parser/openapi4j
  • openapi-processor-core-parser-swagger/src/main/kotlin/io/openapiprocessor/core/parser/swagger
  • openapi-processor-core/src/testInt/resources/tests

openapi-processor-core-parser-api/src/main/kotlin/io/openapiprocessor/core/parser/HttpMethod.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ package io.openapiprocessor.core.parser
99
* http methods.
1010
*/
1111
enum class HttpMethod(val method: String) {
12-
GET ("get"),
13-
PUT ("put"),
14-
POST ("post"),
1512
DELETE ("delete"),
16-
OPTIONS ("options"),
13+
GET ("get"),
1714
HEAD ("head"),
15+
OPTIONS ("options"),
1816
PATCH ("patch"),
17+
POST ("post"),
18+
PUT ("put"),
1919
TRACE ("trace")
2020
}

openapi-processor-core-parser-openapi4j/src/main/kotlin/io/openapiprocessor/core/parser/openapi4j/Path.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,8 @@ class Path(
2222
override fun getPath(): String = path
2323

2424
override fun getOperations(): List<ParserOperation> {
25-
val ops: MutableList<ParserOperation> = mutableListOf()
26-
27-
HttpMethod.entries.map {
28-
val op = info.getOperation(it.method)
29-
if (op != null) {
30-
ops.add (Operation(it, op, info, refResolver))
31-
}
32-
}
33-
34-
return ops
25+
return info
26+
.operations
27+
.map { Operation(HttpMethod.valueOf(it.key.uppercase()), it.value, info, refResolver) }
3528
}
36-
3729
}

openapi-processor-core-parser-swagger/src/main/kotlin/io/openapiprocessor/core/parser/swagger/Path.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class Path(
3939

4040
fun SwaggerPath.getOperation(method: String): SwaggerOperation? {
4141
return when(method) {
42-
HttpMethod.GET.method -> this.get
43-
HttpMethod.PUT.method -> this.put
44-
HttpMethod.POST.method -> this.post
4542
HttpMethod.DELETE.method -> this.delete
46-
HttpMethod.OPTIONS.method -> this.options
43+
HttpMethod.GET.method -> this.get
4744
HttpMethod.HEAD.method -> this.head
45+
HttpMethod.OPTIONS.method -> this.options
4846
HttpMethod.PATCH.method -> this.patch
47+
HttpMethod.POST.method -> this.post
48+
HttpMethod.PUT.method -> this.put
4949
HttpMethod.TRACE.method -> this.trace
5050
else -> null
5151
}

openapi-processor-core/src/testInt/resources/tests/endpoint-http-mapping/inputs/openapi30.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ info:
66
paths:
77
/endpoint:
88

9-
get:
9+
delete:
1010
responses:
1111
'204':
1212
description: empty
1313

14-
delete:
14+
get:
1515
responses:
1616
'204':
1717
description: empty

openapi-processor-core/src/testInt/resources/tests/ref-chain-spring-124.1/inputs/apis/user.v1.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ paths:
1818
required: true
1919
description: Id of an existing user.
2020

21+
delete:
22+
summary: Delete User by User ID
23+
description: Delete the user with the matching user ID.
24+
operationId: delete-user-by-userId
25+
tags:
26+
- user
27+
responses:
28+
'200':
29+
description: OK
30+
2131
get:
2232
summary: Get User by User ID
2333
description: Retrieve the information of the user with the matching user ID.
@@ -71,16 +81,6 @@ paths:
7181
Put User Alice Smith:
7282
$ref: '#/components/examples/UserExample'
7383

74-
delete:
75-
summary: Delete User by User ID
76-
description: Delete the user with the matching user ID.
77-
operationId: delete-user-by-userId
78-
tags:
79-
- user
80-
responses:
81-
'200':
82-
description: OK
83-
8484
'/user':
8585
post:
8686
summary: Create New User

openapi-processor-core/src/testInt/resources/tests/ref-chain-spring-124.1/outputs/api/UserApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public interface UserApi {
1616
@Mapping("/user")
1717
ResponseEntity<User> postUser(@Parameter User body);
1818

19+
@Mapping("/users/{userId}")
20+
ResponseEntity<Void> deleteUserByUserId(@Parameter Long userId);
21+
1922
@Mapping("/users/{userId}")
2023
ResponseEntity<User> getUserByUserId(@Parameter Long userId);
2124

@@ -24,9 +27,6 @@ ResponseEntity<User> putUserByUserId(
2427
@Parameter Long userId,
2528
@Parameter User body);
2629

27-
@Mapping("/users/{userId}")
28-
ResponseEntity<Void> deleteUserByUserId(@Parameter Long userId);
29-
3030
@Mapping("/users")
3131
ResponseEntity<Collection<User>> getAllUsers();
3232

openapi-processor-core/src/testInt/resources/tests/ref-chain-spring-124.2/inputs/apis/user-userId.api.v1.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ parameters:
66
required: true
77
description: Id of an existing user.
88

9+
delete:
10+
summary: Delete User by User ID
11+
description: Delete the user with the matching user ID.
12+
operationId: delete-user-by-userId
13+
tags:
14+
- user
15+
responses:
16+
'200':
17+
description: OK
18+
919
get:
1020
summary: Get User by User ID
1121
description: Retrieve the information of the user with the matching user ID.
@@ -58,13 +68,3 @@ put:
5868
Put User Alice Smith:
5969
$ref: ../examples/user.example.v1.yaml
6070
description: ''
61-
62-
delete:
63-
summary: Delete User by User ID
64-
description: Delete the user with the matching user ID.
65-
operationId: delete-user-by-userId
66-
tags:
67-
- user
68-
responses:
69-
'200':
70-
description: OK

openapi-processor-core/src/testInt/resources/tests/ref-chain-spring-124.2/outputs/api/UserApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
@Generated(value = "openapi-processor-core", version = "test")
1414
public interface UserApi {
1515

16+
@Mapping("/users/{userId}")
17+
ResponseEntity<Void> deleteUserByUserId(@Parameter Long userId);
18+
1619
@Mapping("/users/{userId}")
1720
ResponseEntity<User> getUserByUserId(@Parameter Long userId);
1821

@@ -21,9 +24,6 @@ ResponseEntity<User> putUserByUserId(
2124
@Parameter Long userId,
2225
@Parameter User body);
2326

24-
@Mapping("/users/{userId}")
25-
ResponseEntity<Void> deleteUserByUserId(@Parameter Long userId);
26-
2727
@Mapping("/user")
2828
ResponseEntity<User> postUser(@Parameter User body);
2929

0 commit comments

Comments
 (0)