Swagger Java注解是否支持对API端点进行路径方式的文档化?

huangapple go评论64阅读模式
英文:

Is it possible to do path-wise documentation of API endpoints with Swagger Java annotations?

问题

我有一个名为Person的类根据端点的不同可能需要或不需要其firstName”。在Java中是否有一种使用Swagger OpenAPI文档标签来实现这一点的方法

如果可能的话我想它可能看起来有点像这样

public class Person {
    @Path("/endpoint1", required = true)
    @Path("/endpoint2", required = false)
    private String firstName;
}
英文:

I have, say, a class Person which, depending on the endpoint, would have its firstName either required or not. Is there a way of doing this with Swagger OpenAPI documentation tags in Java?

I'm imagining it could look a bit like this if it were/is possible:

public class Person {
    @Path("/endpoint1", required = true)
    @Path("/endpoint2", required = false)
    private String firstName;
}

答案1

得分: 1

你需要两个类 - 一个其中firstName属性是必需的,另一个其中firstName是可选的。为了减少代码重复,你可以定义一个基类,其中包含除firstName之外的所有属性,并从这个基类继承另外两个Person类。

英文:

You'll need two classes - one where the firstName property is required, and another one where it's optional. To reduce code duplication, you can define a base class that contains all properties except for firstName and inherit the other two Person classes from this base class.

huangapple
  • 本文由 发表于 2023年2月16日 05:08:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定