Forum Discussion

dimedrol's avatar
New Contributor
6 years ago

Swagger: How to stub REST service with Java code/annotations

Greetings, All! I'm using Swagger in my Java project.  And I've got REST service, Java method with Swagger annotations:  (some data removed) @GET @Path("/data-by-district/{authtoken}/{c...
  • ralphdoe's avatar
    6 years ago

    This pice of code might be helpful for your question. 


     @ApiOperation(value = "Finds Pets by status",
        notes = "Multiple status values can be provided with comma seperated strings",
        response = Pet.class,
        responseContainer = "List")
     public Response findPetsByStatus(...) { ... }

    In the response parameter you can put a class, in your case: MyObject.class.
    You can also add metadata to your model, with the @ApiModelProperty annotation, in class and parameters level. 


    @ApiModel(value="DifferentModel", description="Sample model for the documentation")
    class OriginalModel {...}
     @ApiModelProperty(value = "pet status in the store", allowableValues = "available,pending,sold")
      public String getStatus() {
        return status;


    You can see other useful annotations in this link: Wiki Annotations


    I hope this info can help you to solve your doubts and don't hesitate in ask again if this doesn't work for you.


    Have a nice day!