Skip to content

Commit

Permalink
Add SortAsQueryParam annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejkrpec committed Nov 8, 2024
1 parent 1fdddf6 commit f8c22af
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.springdoc.core.converters.models;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;

/**
* The Sort class as query param.
*
* @author ondrejkrpec
*/
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Parameter(in = ParameterIn.QUERY
, description = "Sorting criteria in the format: property,(asc|desc). "
+ "Default sort order is ascending. " + "Multiple sort criteria are supported."
, name = "sort"
, array = @ArraySchema(schema = @Schema(type = "string"))
)
public @interface SortAsQueryParam {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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

import org.springdoc.core.converters.models.SortAsQueryParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -36,4 +37,10 @@ public String operation4() {
return "operation4";
}

@GetMapping("operation5")
@SortAsQueryParam
public String operation5() {
return "operation5";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@
}
],
"paths": {
"/demo/operation5": {
"get": {
"tags": [
"hello-controller"
],
"operationId": "operation5",
"parameters": [
{
"name": "sort",
"in": "query",
"description": "Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/demo/operation4": {
"get": {
"tags": [
Expand Down

0 comments on commit f8c22af

Please sign in to comment.