Skip to content

Commit ee2dfc4

Browse files
authoredNov 23, 2024
Merge pull request #2777 from ondrejkrpec/ondrejkrpec/add-sort-as-query-param
Add SortAsQueryParam annotation
2 parents 1fdddf6 + f8c22af commit ee2dfc4

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.springdoc.core.converters.models;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
import io.swagger.v3.oas.annotations.Parameter;
9+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
10+
import io.swagger.v3.oas.annotations.media.ArraySchema;
11+
import io.swagger.v3.oas.annotations.media.Schema;
12+
13+
/**
14+
* The Sort class as query param.
15+
*
16+
* @author ondrejkrpec
17+
*/
18+
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
19+
@Retention(RetentionPolicy.RUNTIME)
20+
@Parameter(in = ParameterIn.QUERY
21+
, description = "Sorting criteria in the format: property,(asc|desc). "
22+
+ "Default sort order is ascending. " + "Multiple sort criteria are supported."
23+
, name = "sort"
24+
, array = @ArraySchema(schema = @Schema(type = "string"))
25+
)
26+
public @interface SortAsQueryParam {}

Diff for: ‎springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/java/test/org/springdoc/api/app3/HelloController.java

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.springdoc.core.converters.models.PageableAsQueryParam;
2222

23+
import org.springdoc.core.converters.models.SortAsQueryParam;
2324
import org.springframework.http.MediaType;
2425
import org.springframework.web.bind.annotation.GetMapping;
2526
import org.springframework.web.bind.annotation.RequestMapping;
@@ -36,4 +37,10 @@ public String operation4() {
3637
return "operation4";
3738
}
3839

40+
@GetMapping("operation5")
41+
@SortAsQueryParam
42+
public String operation5() {
43+
return "operation5";
44+
}
45+
3946
}

Diff for: ‎springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/resources/results/app3.json

+33
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,39 @@
1111
}
1212
],
1313
"paths": {
14+
"/demo/operation5": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "operation5",
20+
"parameters": [
21+
{
22+
"name": "sort",
23+
"in": "query",
24+
"description": "Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
25+
"schema": {
26+
"type": "array",
27+
"items": {
28+
"type": "string"
29+
}
30+
}
31+
}
32+
],
33+
"responses": {
34+
"200": {
35+
"description": "OK",
36+
"content": {
37+
"text/plain": {
38+
"schema": {
39+
"type": "string"
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
},
1447
"/demo/operation4": {
1548
"get": {
1649
"tags": [

0 commit comments

Comments
 (0)
Please sign in to comment.