question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Streamline annotating a method's @Response when using JAX-RS Response object

See original GitHub issue

Originally posted in SmallRye here: https://github.com/smallrye/smallrye-open-api/issues/76

Content copy/pasted from source:


OpenApi has an ApiResponse annotation which, via its nested Content, can provide the information about the JAX-RS Response entity class.

While this annotation covers well for a case where Response dynamically sets different entity types per the current response media type, it is too complex for a typical case of Response returning a known single entity type only, with @Produces already typing a response media type.

One proposal is to have something like this:

@Produces("application/json")
@ApiResponseType(MyType.class)
@GET
public Response get() { return Response.ok(new MyType()).build(); }   

but other options should also be considered

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
MikeEdgarcommented, Oct 5, 2019

Assuming everyone agrees this should be a new annotation and not a modification to ApiResponse and @RequestBody, how about the following (to keep the naming in alignment with existing objects). Whether or not there are additional attributes besides value (status code?), also needs to be determined.

@ApiResponseSchema(value = MyResponse.class)
@RequestBodySchema(value = MyRequest.class)
2reactions
arthurdmcommented, Oct 7, 2019

I like those names @MikeEdgar, +1

My suggestion is to keep these new annotations very simple, with just the single field (Pojo ref). For anything else, such as setting multiple responses based on status code, the user would then utilize @APIResponses & @APIResponse.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing REST Services with RESTEasy Reactive
If you want to stream JSON objects in your response, you can use Server-Sent Events by just annotating your endpoint method with ......
Read more >
Response (Java(TM) EE 7 Specification APIs)
The method may be annotated as @Deprecated in a future release of JAX-RS API. Returns: response headers as a multivalued map. getHeaders. public...
Read more >
Developing a JAX-RS RESTful Service - dennis-xlc
The method returns a complex response to the client using the javax.ws.rs.core.Response class. The static Response.created() method creates a Response object ...
Read more >
Chapter 8. JAX-RS Entity Providers
The last parameter of the isWriteable method is the mediaType which is the media type attached to the response entity by annotating the...
Read more >
Response.ResponseBuilder (RESTEasy JAX-RS 3.0.9. ...
Several methods have parameters of type URI, UriBuilder provides convenient methods to create such values as does URI.create() . Where multiple variants of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found