Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request Body parameter - providing different json examples to the end user in swagger (same object in multiple endpoints) #170

Open
robsquireq opened this issue Jul 13, 2021 · 0 comments

Comments

@robsquireq
Copy link

I'll try to explain my problem as clearly as possible...

We have numerous endpoints in our system that specify the same @RequestBody object and essentially we would like to provide example json requests to each specific endpoint. The request object itself has fields we wish to exclude in some cases and not in others. Ideally I am looking to annotate our Spring Rest controller methods each with an exact json string which would show as a useful visual for the user in the swagger UI.

Lets say I have a Request object class that represents our object for multiple endpoints:

public class PrepRequest{

    String name;
    String type;
    Location location;
    Destination destinaton;
}

If I have two different endpoints that both receive the PrepRequest above - for the first one I want the example to show on swagger UI as let's say:

{
   'name' : 'A',
   'type' : 'search'
}

and for the second endpoint I would like to display the example json to the user as:

{
   'type' : 'compute',
   'location': {
       'state': 'CA'
   }
}

This is just a super basic example - I hope it makes sense but we basically need to modify the example json per endpoint so that the user will know which style of request to provide.

I have seen in numerous places the possibility of using @ApiImplicitParams just above the controller endpoint method or by tagging the request body parameter as @ApiParam(examples = @example(...

But in both cases I cannot seem to get the example json window of swagger to actually show what I would like to see...in all cases it seems to give me the full requestBody object and all of it's fields.

Is there a way to tag per controller endpoint or at the Api parameter level - the exact json I want to show to the end user in swagger as an example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant