Skip to content

Commit

Permalink
When extends JpaRepository, using @parameter over the method results …
Browse files Browse the repository at this point in the history
…in duplicate of the same parameter. Fixes #2038
  • Loading branch information
bnasslahsen committed Feb 5, 2023
1 parent 4f9da58 commit 1af8c2f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springdoc.core.models.MethodAttributes;
import org.springdoc.core.service.GenericParameterService;
import org.springdoc.core.service.OperationService;
import org.springdoc.core.utils.SpringDocAnnotationsUtils;

Expand Down Expand Up @@ -209,9 +210,14 @@ private Operation buildSearchOperation(HandlerMethod handlerMethod, DataRestRepo
Type type = getParameterType(pName,method,description);
Schema<?> schema = SpringDocAnnotationsUtils.extractSchema(openAPI.getComponents(), type, null, null);
Parameter parameter = getParameterFromAnnotations(openAPI, methodAttributes, method, pName);
if (parameter == null)
if (parameter == null) {
parameter = new Parameter().name(pName).in(ParameterIn.QUERY.toString()).schema(schema);
operation.addParametersItem(parameter);
operation.addParametersItem(parameter);
}
else if (CollectionUtils.isEmpty(operation.getParameters()))
operation.addParametersItem(parameter);
else
GenericParameterService.mergeParameter(operation.getParameters(), parameter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import ch.qos.logback.core.rolling.helper.DateTokenConverter;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
Expand All @@ -23,6 +24,13 @@
@RepositoryRestResource(path = "product")
public interface ProductRepository extends JpaRepository<ProductEntity, Long> {

List<ProductEntity> findByPrice( @Parameter(
name = "price",
description = "test desc",
in = ParameterIn.QUERY,
required = true
)
@Param("price")String price);
/**
* 根据商品名称查询商品信息
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,46 @@
}
}
},
"/product/search/findTopByNameOrderByDateDesc": {
"/product/search/findByPrice": {
"get": {
"tags": [
"product-entity-search-controller"
],
"operationId": "executeSearch-productentity-get_5",
"parameters": [
{
"name": "price",
"in": "query",
"description": "test desc",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/hal+json": {
"schema": {
"$ref": "#/components/schemas/CollectionModelEntityModelProductEntity"
}
}
}
},
"404": {
"description": "Not Found"
}
}
}
},
"/product/search/findTopByNameOrderByDateDesc": {
"get": {
"tags": [
"product-entity-search-controller"
],
"operationId": "executeSearch-productentity-get_6",
"parameters": [
{
"name": "name2",
Expand Down

0 comments on commit 1af8c2f

Please sign in to comment.