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

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

Open
Richard777 opened this issue Aug 15, 2018 · 1 comment
Labels
question v0.X Related to v0x branch

Comments

@Richard777
Copy link

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
Copy link
Contributor

Possible duplicate of #269

@stojsavljevic stojsavljevic added question v0.X Related to v0x branch labels Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question v0.X Related to v0x branch
Projects
None yet
Development

No branches or pull requests

2 participants