How to define abstract property in Model - Swagger

2,072 views
Skip to first unread message

Gökhan Ayrancıoğlu

unread,
Nov 14, 2017, 3:59:52 AM11/14/17
to Swagger

I am trying to implement Swagger to my rest api which is development with Java Spring Boot. There is a problem on model parts of swagger. The problem is Detail abstract class and extended classes are not seem in Swagger UI's and the other output files. I am just seeing the baseclass with detail object as  null.


You can find the code on below.


public class BaseClass {

   @ApiModelProperty(value ="Id of baseClass.", readOnly = true)
    private String     id;

  @ApiModelProperty(value = "Description of baseClass.")
    private String     description;

    @ApiModelProperty(value = "Value is equal to subclass json object value.")
    private Detail     detail;
...


My abstract class which is attribute of baseclass.


@ApiModel(value = "Detail",subTypes = {Page.class,Rank.class},discriminator = "detail")
public abstract class Detail {
}


My extended classes from Detail Abstract Class;


Page Class:

@ApiModel(parent = Detail.class,value = "Page")
public class Page extends Detail {
       @ApiModelProperty(value = "The page URL.")
        private String                  url;
    ...


Rank Class:


 @ApiModel(parent = Detail.class,value = "Rank")
 public class Rank extends Detail {

     @ApiModelProperty(value = "Number List of Rank")
     private List<String> numbers;
    ...

Ron Ratovsky

unread,
Nov 14, 2017, 2:38:18 PM11/14/17
to swagger-sw...@googlegroups.com

Which library do you use to generate the API definition?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gökhan Ayrancıoğlu

unread,
Nov 15, 2017, 9:10:35 AM11/15/17
to Swagger
Libraries and dependencies are below.

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
swaggerVersion = '2.6.1'

compile ("io.springfox:springfox-swagger2:${swaggerVersion}")
compile ("io.springfox:springfox-swagger-ui:${swaggerVersion}")
compile ("io.springfox:springfox-staticdocs:${swaggerVersion}")
compile ("org.springframework.restdocs:spring-restdocs-mockmvc:1.2.0.RELEASE")

14 Kasım 2017 Salı 22:38:18 UTC+3 tarihinde Ron yazdı:

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
Nov 15, 2017, 9:34:45 AM11/15/17
to swagger-sw...@googlegroups.com

Springfox is not one o the libraries we maintain. You’d need to file a ticket with the project to get support.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--

You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Phanindra Sastry

unread,
May 8, 2018, 11:17:39 AM5/8/18
to Swagger
Is there a way we can decorate the models as abstract in Swagger Spec 2.0? Thank you.
Reply all
Reply to author
Forward
0 new messages