Skip to content

Commit

Permalink
Serialization to openapi of org.springframework.data.domain.Sort is n…
Browse files Browse the repository at this point in the history
…ot done correctly

fixes #2447
  • Loading branch information
bnasslahsen committed Feb 27, 2024
1 parent 78e857f commit 9b6de3a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;

import org.springdoc.core.converters.SortOpenAPIConverter;
import org.springdoc.core.converters.models.SortObject;
import org.springdoc.core.customizers.DataRestDelegatingMethodParameterCustomizer;
import org.springdoc.core.customizers.DelegatingMethodParameterCustomizer;
import org.springdoc.core.providers.ObjectMapperProvider;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class SpringDocSortConfiguration {
@Lazy(false)
SortOpenAPIConverter sortOpenAPIConverter(ObjectMapperProvider objectMapperProvider) {
getConfig().replaceParameterObjectWithClass(org.springframework.data.domain.Sort.class, org.springdoc.core.converters.models.Sort.class);
getConfig().replaceWithClass(org.springframework.data.domain.Sort.class, SortObject.class);
return new SortOpenAPIConverter(objectMapperProvider);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
*
* *
* * *
* * * *
* * * * * Copyright 2019-2022 the original author or authors.
* * * * *
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * * you may not use this file except in compliance with the License.
* * * * * You may obtain a copy of the License at
* * * * *
* * * * * https://www.apache.org/licenses/LICENSE-2.0
* * * * *
* * * * * Unless required by applicable law or agreed to in writing, software
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * * See the License for the specific language governing permissions and
* * * * * limitations under the License.
* * * *
* * *
* *
*
*/
package org.springdoc.core.converters.models;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* The type Sort response.
* @author bnasslahsen
*/
public class SortObject {

/**
* The Direction.
*/
@JsonProperty
private String direction;

/**
* The Null handling.
*/
@JsonProperty
private String nullHandling;

/**
* The Ascending.
*/
@JsonProperty
private boolean ascending;

/**
* The Property.
*/
@JsonProperty
private String property;

/**
* The Ignore case.
*/
@JsonProperty
private boolean ignoreCase;

}
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public final class Constants {
/**
* The constant SPRINGDOC_SORT_CONVERTER_ENABLED.
*/
public static final String SPRINGDOC_SORT_CONVERTER_ENABLED = "springdoc.model-converters.sort-converter.enabled";
public static final String SPRINGDOC_SORT_CONVERTER_ENABLED = "springdoc.sort-converter.enabled";

/**
* The constant SPRINGDOC_NULLABLE_REQUEST_PARAMETER_ENABLED.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@
"type": "integer",
"format": "int64"
},
"numberOfElements": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
Expand All @@ -108,12 +104,16 @@
"type": "integer",
"format": "int32"
},
"pageable": {
"$ref": "#/components/schemas/PageableObject"
},
"sort": {
"$ref": "#/components/schemas/SortObject"
},
"numberOfElements": {
"type": "integer",
"format": "int32"
},
"pageable": {
"$ref": "#/components/schemas/PageableObject"
},
"first": {
"type": "boolean"
},
Expand All @@ -132,6 +132,9 @@
"type": "integer",
"format": "int64"
},
"sort": {
"$ref": "#/components/schemas/SortObject"
},
"pageNumber": {
"type": "integer",
"format": "int32"
Expand All @@ -140,27 +143,30 @@
"type": "integer",
"format": "int32"
},
"sort": {
"$ref": "#/components/schemas/SortObject"
},
"unpaged": {
"paged": {
"type": "boolean"
},
"paged": {
"unpaged": {
"type": "boolean"
}
}
},
"SortObject": {
"type": "object",
"properties": {
"sorted": {
"type": "boolean"
"direction": {
"type": "string"
},
"nullHandling": {
"type": "string"
},
"unsorted": {
"ascending": {
"type": "boolean"
},
"empty": {
"property": {
"type": "string"
},
"ignoreCase": {
"type": "boolean"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@
"Pageable": {
"type": "object",
"properties": {
"paged": {
"type": "boolean"
"offset": {
"type": "integer",
"format": "int64"
},
"unpaged": {
"type": "boolean"
"sort": {
"$ref": "#/components/schemas/SortObject"
},
"pageNumber": {
"type": "integer",
Expand All @@ -72,25 +73,30 @@
"type": "integer",
"format": "int32"
},
"offset": {
"type": "integer",
"format": "int64"
"paged": {
"type": "boolean"
},
"sort": {
"$ref": "#/components/schemas/SortObject"
"unpaged": {
"type": "boolean"
}
}
},
"SortObject": {
"type": "object",
"properties": {
"sorted": {
"type": "boolean"
"direction": {
"type": "string"
},
"nullHandling": {
"type": "string"
},
"unsorted": {
"ascending": {
"type": "boolean"
},
"empty": {
"property": {
"type": "string"
},
"ignoreCase": {
"type": "boolean"
}
}
Expand Down

0 comments on commit 9b6de3a

Please sign in to comment.