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.

@ApiModelProperty not displaying attribute when using @ModelAttributeode

See original GitHub issue

Hi,

I have a POJO (FilterRequest) that is used to configure various filter parameters for submission to a REST endpoint. I have added @ModelAttribute in the controller endpoint so that it is picked up by springfox.

@ApiOperation(value = "Filtering endpoint", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<<FilterResponse>> search(@ModelAttribute @Valid FilterRequest filterRequest) {
   ...
}

//The FilterRequest is defined as follows:

public class FilterRequest {
   private static final String FILTER1_NAME = "filter1"
   ...
   private static final String FILTER_N_NAME = "filterN"

   private final Map<String, String> filterMap = new HashMap<>();

   public void setFilter1(String filter){
       if (filter != null) {
            filterMap.put(FILTER1_NAME, filter);
        }
   }
   @ApiModelProperty(value = "Filters by filter1", required = true)
   public String getFilter1(){filterMap.get(FILTER1_NAME);}

    ...
   public void setFilterN(String filter){...}

   @ApiModelProperty(value = "Filters by filterN", required = true)
   public String getFilterN(){...}
}

In principle this should be enough seeing as @ApiModelProperty should work on getters. However this is not the case, and nothing appears in the swagger output. If I declare the filters as individual state attributes they appear. I want to be able to save all these fields in a map, seeing as I need to process these down the line.

How can I get the @ApiModelProperty to wotk in my case>?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
rantunesboreascommented, Aug 30, 2016

Sure, I’ll give it a try once I get back from holiday.

1reaction
rantunesboreascommented, Aug 16, 2016

HI Dilip,

Thanks for replying. I have tried applying the @ApiModelProperty to the setter methods but with no success. The filters still don’t appear in the documentation.

Do you have any other suggestions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger ApiModelProperty not working - Stack Overflow
Same problem with springfox-swagger2 package in 2.9.2 version, position property doesn't work for ordering property in swagger UI. – robynico. Mar 10, 2021...
Read more >
docs/release-notes.md · serv/springfox - Gitee.com
@jfiala; (#1449) @ApiModelProperty not displaying attribute when using @ModelAttributeode duplicate @rantunesboreas. Bugs. (#2039) Endpoints with the same ...
Read more >
Springfox 2.9.0 发布,开源的API doc 框架 - 码农网
(#2253) Producing "x-example" with @apiparam for @pathvariable feature ... (#1449) @apimodelproperty not displaying attribute when using @modelattributeode ...
Read more >
ApiModelProperty (swagger-annotations 1.5.0 API)
Adds and manipulates data of a model property. ... Allows for filtering a property from the API documentation. ... Currently not in use....
Read more >
value for @ApiModelProperty not showing up for lists
I'm working with swagger annotations 1.5.3. Code example for provenance: import com.wordnik.swagger.annotations.ApiModelProperty;.
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