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

@ApiOperation "response" value causing docs to ignore model annotations #1785

Closed
bfinleyui opened this issue Apr 24, 2017 · 2 comments
Closed

Comments

@bfinleyui
Copy link

bfinleyui commented Apr 24, 2017

Java 8
Springfox 2.6.1
Spring boot

This is my first swagger project, and trying to get a handle on this stuff.

I have an AppUser.java class that extends Persistent.java. I've got a AppUserRest.java class that currently has handlers for PUT and GET methods.

I have annotated AppUser with several things that shouldn't be shown, or are read-only, etc. The model and example class is shown properly in the UI documentation. It all works well UNTIL I specify a response type on the second @ApiOperation in the AppUserRest class, at which time it seems to completely ignore all annotations on AppUser, and spits out default model/example in both the GET and PUT documentation. Showing all hidden/read-only/write-only fields, etc.

I'm sure it's something simple that I'm missing being a new swagger-er. Tried with the swagger folks over in their chat, and they sent me your way. Hoping you can point me in the right direction, I've really enjoyed everything else about the ecosystem so far.

Thanks

AppUserRest.java

@RestController
public class AppUserRest {

    private AppUserRepository appUserRepository;

    @Autowired
    AppUserService appUserService;

    @ApiOperation(value = "Create new user", response = Long.class)
    @RequestMapping(method = RequestMethod.PUT, value="/api/users")
    public ResponseEntity newUser(@ApiParam(value="User object to create", required=true) @RequestBody AppUser newUser) {
        newUser = appUserService.saveUser(newUser);
        return new ResponseEntity(newUser.getId(), HttpStatus.CREATED);
    }

    @ApiOperation(value = "Find user by ID",
            notes = "Retrieve a single user using their synthetic ID",
            response = AppUser.class

    )
    @RequestMapping(method = RequestMethod.GET, value="/api/users/{id}")
    public ResponseEntity<> getUser(@PathVariable("id") Long id) {
        AppUser user = appUserService.getUser(id);
        return new ResponseEntity<>(user, HttpStatus.OK);
    }

}

AppUser.java

@Entity
@ApiModel("AppUser")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class AppUser extends Persistent {

    @Basic(optional = false)
    @ApiModelProperty(required = true)
    private String name;

    @Basic(optional = false)
    @ApiModelProperty(required = true)
    private String phone;

    @Basic(optional = false)
    @ApiModelProperty(required = true)
    private String email;

    @Basic(optional = false)
    @ApiModelProperty(required = true)
    private String username;

    @Basic(optional = false)
    @ApiModelProperty(required = true)
    private Boolean idw;

    @Basic
    private String univId;

    @Basic(optional = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @ApiModelProperty(required = true)
    private String password;

...
...
...

  
}

Persistent.java


@MappedSuperclass
    public class Persistent implements Serializable {
        protected Persistent() {
            this.creationTime = new Timestamp(currentTimeMillis());
            this.modificationTime = new Timestamp(currentTimeMillis());
        }

        protected final static String DATE_FORMAT = "MM/dd/yyyy hh:mm a";

        @Id
        @GeneratedValue(strategy = IDENTITY)
        @JsonProperty(access = JsonProperty.Access.READ_ONLY)
        @ApiModelProperty(readOnly = true)
        private Long id;

        @Column(name = "CREATION_TIME")
        @JsonProperty(access = JsonProperty.Access.READ_ONLY)
        @ApiModelProperty(readOnly = true)
        private Timestamp creationTime;

        @Column(name = "MODIFICATION_TIME")
        @JsonProperty(access = JsonProperty.Access.READ_ONLY)
        @ApiModelProperty(readOnly = true)
        private Timestamp modificationTime;

        @JsonIgnore
        public boolean isPersistent() {
            return !(id == null);
        }
@bfinleyui bfinleyui changed the title @ApiResponse @ApiResponse "response" value causing docs to ignore model annotations Apr 24, 2017
@bfinleyui bfinleyui changed the title @ApiResponse "response" value causing docs to ignore model annotations @ApiOperation "response" value causing docs to ignore model annotations Apr 24, 2017
@bfinleyui
Copy link
Author

I think this may be a duplicate of #1725

...

@dilipkrish
Copy link
Member

That is absolutely correct. Closing this as a duplicate of #1725

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

No branches or pull requests

2 participants