use of com.google.api.codegen.config.DiscoveryField in project toolkit by googleapis.
the class DiscoveryMethodTransformer method generatePageStreamingResponse.
/**
* Returns a non-null PageStreamingResponseView iff the method has a response object that contains
* a nextPageToken child property.
*/
@Nullable
@Override
public PageStreamingResponseView generatePageStreamingResponse(MethodModel methodModel) {
DiscoveryMethodModel method = (DiscoveryMethodModel) methodModel;
String resourcesField = null;
boolean hasNextPageToken = false;
for (DiscoveryField field : method.getOutputFields()) {
String fieldName = field.getSimpleName();
if (!fieldName.equals(pagingParameters.getNameForNextPageToken())) {
for (Schema property : field.getDiscoveryField().properties().values()) {
if (property.getIdentifier().equals(pagingParameters.getNameForNextPageToken())) {
hasNextPageToken = true;
resourcesField = Name.anyCamel(fieldName).toUpperCamel();
break;
}
}
}
}
if (resourcesField == null || !hasNextPageToken) {
return null;
}
return PageStreamingResponseView.newBuilder().tokenField(pagingParameters.getNameForNextPageToken()).resourcesField(resourcesField).build();
}
Aggregations