最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to override spring-data-rest default methods for swagger openApi documentation - Stack Overflow

programmeradmin1浏览0评论

I have a entity class something like this

@Entity
public class People {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private String name;
    private String email;

    // standard getters and setters
}

and the repository is something like this

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PeopleRepository extends JpaRepository<People, Long> {
    List<People> findByName(@Param("name") String name);
}

In the swagger it is showing in the below screenshot

before

i wanted to see description and name for each default method that is created by spring data rest (CRUD methods)

by default it is generating the description something like this

for get -> get-people

for post -> create-people

for getbyid -> get-people

for delete -> delete-people etc

i wanted to change it to my custom description. I wanted to see something like this

expected outcome

Things that i tried: When i am using @Operation annotation then only custom method description is showing in the swagger. Example :

@Operation(name="getbyname", description="fetch all data by name")
List<People> findByName(@Param("name") String name);

Above one is working and it is showing in the swagger with proper description but when i am tring to do the same with the default methods that is generated by spring data rest, then it is not working

i tried something like this

@Override
@Operation(name="getAll", description="fetch all data")
List<People> findAll();

then the description and name is not showing.

Is there any way that i can override the default description and name for all the default spring data rest methods?

I tried multiple ways to override the methods or changed some properites but noting worked for me.

发布评论

评论列表(0)

  1. 暂无评论