// Create a new command, set name/description/usage
Command apiCommand = new Command();
apiCommand.setName(command);
APICommand impl = clas.getAnnotation(APICommand.class);
if (impl == null) {
impl = clas.getSuperclass().getAnnotation(APICommand.class);
}
if (impl == null) {
throw new IllegalStateException(String.format("An %1$s annotation is required for class %2$s.",
APICommand.class.getCanonicalName(), clas.getCanonicalName()));
}
if (impl.includeInApiDoc()) {
String commandDescription = impl.description();
if (commandDescription != null && !commandDescription.isEmpty()) {
apiCommand.setDescription(commandDescription);
} else {
System.out.println("Command " + apiCommand.getName() + " misses description");
}
String commandUsage = impl.usage();
if (commandUsage != null && !commandUsage.isEmpty()) {
apiCommand.setUsage(commandUsage);
}
//Set version when the API is added
if(!impl.since().isEmpty()){
apiCommand.setSinceVersion(impl.since());
}
boolean isAsync = ReflectUtil.isCmdClassAsync(clas,
new Class<?>[] {BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
apiCommand.setAsync(isAsync);
Set<Field> fields = ReflectUtil.getAllFieldsForClass(clas,
new Class<?>[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class});
request = setRequestFields(fields);
// Get response parameters
Class<?> responseClas = impl.responseObject();
Field[] responseFields = responseClas.getDeclaredFields();
response = setResponseFields(responseFields, responseClas);
apiCommand.setRequest(request);
apiCommand.setResponse(response);