0

I have a REST endpoint in my java webapp that accepts an Instant as a query parameter as seen in the code below

@GET
@Produces(MediaType.APPLICATION_JSON)
Response getHistory(
    @QueryParam("beforeTime")
    Instant beforeTime,

    @QueryParam("afterTime")
    Instant afterTime) {
    ...
}

This worked well under swagger 1.x, but when we switch to swagger 2.x the objects of Instant are showing up as $int64 instead of a date-time field. What can I do with the swagger annotations to get this to work?

1 Answer 1

1

I was able to use the @ApiParam annotation to fix this issue. Setting the type to date-time and format to java.time.Instant fixed the issue.

@GET
@Produces(MediaType.APPLICATION_JSON)
Response getHistory(
    @QueryParam("beforeTime")
    @ApiParam(type="date-time", format = "java.time.Instant")
    Instant beforeTime,

    @QueryParam("afterTime")
    @ApiParam(type="date-time", format = "java.time.Instant")
    Instant afterTime) {
    ...
}
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.