Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to add example in an API response without having to describe again the schema? #3025

Unanswered
gotson asked this question in Q&A
Discussion options

Hi,

in #2479 it is mentioned that the whole @ApiResponse should be added in order to add an example.

This is not very convenient, given the response code and schema is already introspected from the code.

Isn't there a better way to handle this ?

You must be logged in to vote

Replies: 1 comment 3 replies

Comment options

The issue that you link looks to specifically be for Collections. If your model is represented by an object then the example can be attached to that object (or rather, its Schema) and it can easily be reused.

Could your specific scenario be clarified so it is clearer exactly what type of object that you would like to attach an example to?

You must be logged in to vote
3 replies
Comment options

My issue is with collections actually. For single objects you are right, adding @Schema with example on the Object class is sufficient.

Comment options

Ideally for collections, if the object has a schema example, then an example with a collection of 1 item with that example could be generated.

In addition, having a dedicated annotation to provide an example for a collection response without having to use @ApiResponse would be very useful.

Comment options

Could you provide a minimal specification and an expected json for such a case? It would make it easier to understand the exact scenario, and it would also make it possible to create a test case for which one could try to implement a behavior against.

I might look into the later of the scenarios (example based on object in collection), because I agree with the reasoning behind a collection containing an example if the object has one. I believe that Lists/arrays already work like this, but might be that your case is a more complex collection, like the HashMap that was stated in the issue which you linked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /