2

I followed this article: https://stackoverflow.com/a/30407999/2458858 and have successfully created a jersey rest api with a custom queryparam

@GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("/test")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(notes = "test api", value = "Get", nickname = "gettest", tags = {"Salus/Identity" })
    public Response identity2(@QueryParam("user") Tempuser user1) {
        return Response.ok().build();   
    }

I have also used @ApiModel on this custom class:

@XmlRootElement(name="TempUser")
@ApiModel(value="DifferentModel", description="Sample model for the documentation")
public class Tempuser {

        private String name;

        public Tempuser(String name) {
            this.name = name;
        }

        @XmlElement(name = "name")  
    @ApiModelProperty(required = true)
      public String getName() {
        return name;
      }

      public void setType(String name) {
        this.name = name;
      }

      public static Tempuser valueOf(String name) {
          return new Tempuser(name);
      }

}

But when I load swagger doc, it still shows this TempUser as String type: enter image description here

Swagger does not support custom data types?

Vladas Maier
  • 2,054
  • 2
  • 22
  • 34
tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
  • 1
    Those types are tied to Java. APIs should generally be universal and clients should not be concerned with the implementation details. It's a string because that is ultimately what the client will be sending. Does the client need to know that the underlying type is a Java class named TempUser? Would that information _help_ them or possibly _confuse_ them? I'd guess the latter. – Paul Samsotha Apr 27 '19 at 06:00
  • Simple example where this might be useful: we have a class that represents an ISO date-time parameter, but it also accepts relative offsets like "+2d". It would be nice to either name or describe that format in one place, and the docs would use that description everywhere it applies. – Bampfer Oct 24 '19 at 15:39

0 Answers0