phoenixnap / springmvc-raml-plugin

Spring MVC - RAML Spec Synchroniser Plugin. A Maven plugin designed to Generate Server & Client code in Spring from a RAML API descriptor and conversely, a RAML API document from the SpringMVC Server implementation.
Apache License 2.0
136 stars 84 forks source link

the return type is Object in controller,how to generate specific type in raml? #270

Open Richard777 opened 6 years ago

Richard777 commented 6 years ago

I have a spring-boot web project. I want to generate raml file by using the version of 0.10.14. But when the return type in controller' methods is Object, it generate any type in the json schema. The code like: @RequestMapping(value="/users")
public class UserController {

static Map<Long, User> users = Collections.synchronizedMap(new HashMap<Long, User>());
static {
    users.put(1L, new User(1L, "test1", 26));
    users.put(2L, new User(2L, "test2", 26));
}

@RequestMapping(value="/getUserDetail/{id}", method=RequestMethod.GET)
public Object getUser(@PathVariable Long id) {
    try {
        User ret = users.get(id);
        return ret;
    } catch (Exception e){
        return new UserNotFindException(1, "user id not exists");
    }
}

} it generate json schema in raml like: /users: displayName: Users Resource description: Users Resource /getUserDetail: displayName: GetUserDetail Resource description: GetUserDetail Resource /{id}: displayName: "{id} Resource" description: "{id} Resource" get: description: getUser responses: "200": description: Successful Response body: application/json: schema: | { "type" : "any" }

the User class like: public class User { @JsonProperty(required = true) private Long id; @JsonProperty(required = true) private String name; @JsonProperty() private Integer age;

public User(Long id, String name, Integer age) {
    this.id = id;
    this.name = name;
    this.age = age;
}

} the UserNotFindException class like: public class UserNotFindException { @JsonProperty(required = true) private int error_id; @JsonProperty(required = true) private String error_msg; public UserNotFindException(int error_id, String error_msg) { this.error_id = error_id; this.error_msg = error_msg; } }

the problem is that I want to genarate json schma in this response which represents User class, regardless of the UserNotFindException class. How can I achieve this without changing my code(the return type must be Object for some reason)?Is there an annotation?

stojsavljevic commented 5 years ago

Possible duplicate of #269