Contributions
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, Javamethod with Swagger annotations: (some data removed) @GET @Path("/data-by-district/{authtoken}/{country}/{districtid}") @ApiImplicitParams({ @ApiImplicitParam( name = "authtoken", dataType = "string" ), @ApiImplicitParam( name = "country", dataType = "string" ), @ApiImplicitParam( name = "districtid", dataType = "long" ) }) @ApiOperation(value = "...", notes = "...") public MyObject getData(@PathParam("authtoken") String authtoken, @PathParam("country") String country, @PathParam("districtid") Long districtId) { ... MyObject is actually the JPA Bean with nested objects/lists, etc. It works perfectly for receiving and sending back information. I've got Swagger annotations as well for my method andSwagger UI works as expected. My question is: how can I easily stub this my method, so that UI developers could get a response like this: { //This is "MyObject "id": "3567", //random number "name": "random-string1", "someNestedJpaObject": { "id": "123", //random number "position": "random-string2", "code":"random-string3", "myclassifier": { "key": "random-string4" } } } Swagger - is a part of my application (Maven dependency). So, I assume, it knows the structure of my (JPA) class and types of all fields. Can I get something like mentioned above - a "quick" instance of MyObject, filled with random data? I looked through all the "swagger code generators" around, but it looks like huge overkill in this case: I've already got swagger annotations (I can add an extra ones, if needed), data containers and types, but all the "stub-frameworks" wants me to create YAML files with a lot of information regarding the mock data... I believe I don't need this extra work(yaml code),- I've got all the necessary info in Java code...no?!Solved4.6KViews0likes6Comments