1

I have a object like

public GenericBO {

   private int id;

   private String code;

   private int parentId;

   private List<GenericBO> child = new ArrayList<GenericBO>();

  //getters and setters respectively
}

How can I create the model for the same in swagger?

3
  • Do you write the OpenAPI definition manually or generate it from code? Commented Nov 20, 2019 at 7:49
  • I write it from manually, How do I generate from the code? Commented Nov 20, 2019 at 19:19
  • Check out Springfox or Swagger Core. Vladlas Maier's answer below shows how you would annotate the code. Commented Nov 21, 2019 at 7:34

1 Answer 1

1

There is no difference between annotating nested or not nested Swagger models.

You have to add io.swagger.annotations.ApiModelProperty annotation to each attribute of the model.

public GenericModel {

   @ApiModelProperty(value = "ID")
   private int id;

   @ApiModelProperty(value = "Code")
   private String code;

   @ApiModelProperty(value = "Parent Id")
   private int parentId;

   @ApiModelProperty(value = "Children")
   private List<GenericModel> children = new ArrayList<>();

   ...
}

If the list object is a collection of other models you must annotate the corresponding model (with @ApiModelProperty annotations) as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.