Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When extends JpaRepository, using @Parameter over the method results in duplicate of the same parameter #2038

Closed
zctmdc opened this issue Jan 14, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@zctmdc
Copy link

zctmdc commented Jan 14, 2023

Describe the bug

  • If you are reporting a bug, please help to speed up problem diagnosis by providing as
    much information as possible:
  • A clear and concise description of what the bug is: the title of an issue is not enough

When extends JpaRepository, using @Parameter over the method results in duplicate of the same parameter

我怀疑是不是不能这样使用,我参考了 springdoc-openapi-demos/.../AccountRepository.java ,发现没有使用这个注解
I doubt whether it can't be used like this, I have referred to it. It was found that this annotation was not used.
To Reproduce
Steps to reproduce the behavior:
The steps are the same as #2010
image

  • What version of spring-boot you are using?
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.7</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
  • What modules and versions of springdoc-openapi are you using?
	<properties>
		<java.version>17</java.version>
		<version.openapi>1.6.13</version.openapi>
	</properties>
		<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-ui</artifactId>
			<version>${version.openapi}</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-data-rest -->
		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-data-rest</artifactId>
			<version>${version.openapi}</version>
		</dependency>
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    application.yaml
springdoc:
    swagger-ui:
        path: /swagger-ui.html
  • Provide with a sample code (HelloController) or Test that reproduces the problem
// BuyerRepository.java
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;

/**
 * @author zctmdc
 */
@RepositoryRestResource(path = "buyer")
public interface BuyerRepository extends JpaRepository<BuyerEntity, Long> {
    /**
     * 通过名字获取
     * 
     * @param name 名字
     * @return Buyer
     */
    BuyerEntity findByName(
            @Parameter(
                name = "name", 
                description = "购买者名字", 
                in = ParameterIn.QUERY,
                required = true
            ) 
            @Param("name") String name);
}

Expected behavior

  • A clear and concise description of what you expected to happen.
  • What is the expected result using OpenAPI Description (yml or json)?

Screenshots
If applicable, add screenshots to help explain your problem.

I used in = ParameterIn.QUERY with reference to #1901 , but it didn't work.
image

image

Additional context
Add any other context about the problem here.

// BuyerEntity.java
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * 购买方
 * 
 * @author zctmdc
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "BUYER_ENTITY")
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
public class BuyerEntity extends BaseEntity {
    /** SVUID */
    private static final long serialVersionUID = 1L;

    /** 名字 */
    @NotNull
    @Column(nullable = false, unique = true, length = 64)
    private String name;

    /** 编码 */
    @NotNull
    @Column(nullable = false, unique = true, length = 32)
    private String code;

    @Override
    public boolean isValid() {
        return name != null && code != null;
    }
}
// BaseEntity.java
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.UpdateTimestamp;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.time.LocalDateTime;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * @author zctmdc
 * @date 2022/4/8 01:51
 */
@Data
@MappedSuperclass
@DynamicInsert(true)
@DynamicUpdate(true)
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
public abstract class BaseEntity implements Serializable {

    /** SVUDI */
    private static final long serialVersionUID = 1L;

    /** 数据库中的ID */
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "ID", unique = true, nullable = false, insertable = false, updatable = false)
    private Long id;

    /** 其他信息 */
    @Column(name = "DETAIL", length = 255)
    private String detal;

    /** 创建人 */
    @ColumnDefault("'ZCTMDC'")
    @Column(name = "CREATED_USER", length = 255)
    private String createdUser;

    /** 创建时间 */
    @CreationTimestamp
    @Column(name = "CREATED_DATE")
    private LocalDateTime createDate;

    /** 修改人 */
    @ColumnDefault("'ZCTMDC'")
    @Column(name = "MODIFILED_USER", length = 255)
    private String modifiedUser;

    /** 修改时间 */
    @UpdateTimestamp
    @Column(name = "MODIFILED_DATE")
    private LocalDateTime modifiedDate;

    /** 是否被删除 */
    @ColumnDefault("0")
    @Column(name = "DELETED", length = 1)
    private Boolean deleted;

    /**
     * 数据是否合法
     * 
     * @return 是否合法
     */
    public abstract boolean isValid();
}
bnasslahsen added a commit that referenced this issue Feb 5, 2023
@bnasslahsen bnasslahsen added the bug Something isn't working label Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants