0

I have the following ApiModel for my endpoint -

public class CreateConfigRequest { @ApiModelProperty(example = "hive") String entityType; @ApiModelProperty(example = "imports") String entityNamespace; @ApiModelProperty(example = "hotel") String entityName; @ApiModelProperty(example = "{\"name\": \"hotel\", \"batch\": {\"type\": \"FullScan\"}}") JobConfig content; } 

Where JobConfig is another pojo class. Code below :

@Data public class JobConfig { @NonNull private String name; @NonNull private BatchSpec batch; private ProfileConfig profile; private ValidateConfig validate; private ActionConfig action; } 

My swagger looks like - enter image description here

Which is basically the structure of the POJO.

How it should look like -

enter image description here

Basically i am looking to understand how i can set it to a default JSON structure.

2
  • 1
    Can you please add the code for JobConfig? Thanks! Commented Nov 24, 2021 at 18:57
  • Added the code for the same. Commented Nov 24, 2021 at 19:10

1 Answer 1

1

If you don't want to include profile, validate and action at all in your JSONs you can simply use @JsonIgnore as follows:

@Data public class JobConfig { @NonNull private String name; @NonNull private BatchSpec batch; @JsonIgnore private ProfileConfig profile; @JsonIgnore private ValidateConfig validate; @JsonIgnore private ActionConfig action; } 

If you simply don't want to list them in Swagger documentation, you can use @ApiModelProperty as follows:

@Data public class JobConfig { @NonNull private String name; @NonNull private BatchSpec batch; @ApiModelProperty(hidden = true) private ProfileConfig profile; @ApiModelProperty(hidden = true) private ValidateConfig validate; @ApiModelProperty(hidden = true) private ActionConfig action; } 

Given that you don't want to hide properties but instead show a more realistic example, try the following:

@Data public class JobConfig { @NonNull @ApiModelProperty(example = "hotel") private String name; @NonNull private BatchSpec batch; private ProfileConfig profile; private ValidateConfig validate; private ActionConfig action; } 
@Data public class BatchSpec { @ApiModelProperty(example = "FullScan") private String type; } 
Sign up to request clarification or add additional context in comments.

8 Comments

I don't want to hide it completely, Right now it is showing default structure. I want to create an object and show it on swagger.
Sorry, I am not following you. Then what do you want to not show and when?
Right now if you see in the image, it shows "String". I want to put a reasonable value there so create a jobConfig object of my choice and then show it on the swaggger.
Now I understand what you mean. @ApiModelProperty(example = ) should do it, but I would say you need to annotate each property in JobConfig and also in BatchSpec, ProfileConfig, ValidateConfig and ActionConfig properties.
Thanks for your reply, If you see I have @ApiModelProperty(example = "{\"name\": \"hotel\", \"batch\": {\"type\": \"FullScan\"}}") but it does not reflect anything. Also this accepts only String, I don't know how to give it a variable here.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.