Search in sources :

Example 1 with DiscoveryField

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();
}
Also used : DiscoveryField(com.google.api.codegen.config.DiscoveryField) Schema(com.google.api.codegen.discovery.Schema) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) Nullable(javax.annotation.Nullable)

Aggregations

DiscoveryField (com.google.api.codegen.config.DiscoveryField)1 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 Schema (com.google.api.codegen.discovery.Schema)1 Nullable (javax.annotation.Nullable)1