Search in sources :

Example 1 with MethodConfigProto

use of com.google.api.codegen.MethodConfigProto in project toolkit by googleapis.

the class DiscoGapicInterfaceConfig method createMethodConfigMap.

private static ImmutableMap<String, DiscoGapicMethodConfig> createMethodConfigMap(DiscoApiModel model, String language, InterfaceConfigProto interfaceConfigProto, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, ImmutableSet<String> retryCodesConfigNames, ImmutableSet<String> retryParamsConfigNames) {
    ImmutableMap.Builder<String, DiscoGapicMethodConfig> methodConfigMapBuilder = ImmutableMap.builder();
    for (MethodConfigProto methodConfigProto : interfaceConfigProto.getMethodsList()) {
        Method method = lookupMethod(model.getDocument(), methodConfigProto.getName());
        if (method == null) {
            model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "method not found: %s", methodConfigProto.getName()));
            continue;
        }
        DiscoGapicMethodConfig methodConfig = DiscoGapicMethodConfig.createDiscoGapicMethodConfig(model, language, methodConfigProto, method, messageConfigs, resourceNameConfigs, retryCodesConfigNames, retryParamsConfigNames);
        if (methodConfig == null) {
            continue;
        }
        methodConfigMapBuilder.put(methodConfigProto.getName(), methodConfig);
    }
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    } else {
        return methodConfigMapBuilder.build();
    }
}
Also used : MethodConfigProto(com.google.api.codegen.MethodConfigProto) Method(com.google.api.codegen.discovery.Method) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with MethodConfigProto

use of com.google.api.codegen.MethodConfigProto in project toolkit by googleapis.

the class DiscoGapicInterfaceConfig method createMethodConfigMap.

private static ImmutableMap<String, DiscoGapicMethodConfig> createMethodConfigMap(DiscoApiModel model, TargetLanguage language, InterfaceConfigProto interfaceConfigProto, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, RetryCodesConfig retryCodesConfig, ImmutableSet<String> retryParamsConfigNames) {
    ImmutableMap.Builder<String, DiscoGapicMethodConfig> methodConfigMapBuilder = ImmutableMap.builder();
    for (MethodConfigProto methodConfigProto : interfaceConfigProto.getMethodsList()) {
        Method method = lookupMethod(model.getDocument(), methodConfigProto.getName());
        if (method == null) {
            model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "method not found: %s", methodConfigProto.getName()));
            continue;
        }
        DiscoGapicMethodConfig methodConfig = DiscoGapicMethodConfig.createDiscoGapicMethodConfig(model, language, methodConfigProto, method, messageConfigs, resourceNameConfigs, retryCodesConfig, retryParamsConfigNames);
        if (methodConfig == null) {
            continue;
        }
        methodConfigMapBuilder.put(methodConfigProto.getName(), methodConfig);
    }
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    } else {
        return methodConfigMapBuilder.build();
    }
}
Also used : MethodConfigProto(com.google.api.codegen.MethodConfigProto) Method(com.google.api.codegen.discovery.Method) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with MethodConfigProto

use of com.google.api.codegen.MethodConfigProto in project toolkit by googleapis.

the class GapicInterfaceConfig method createMethodConfigMap.

private static ImmutableMap<String, GapicMethodConfig> createMethodConfigMap(DiagCollector diagCollector, TargetLanguage language, TransportProtocol transportProtocol, String defaultPackageName, Map<Method, MethodConfigProto> methodsToGenerate, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, RetryCodesConfig retryCodesConfig, ImmutableSet<String> retryParamsConfigNames, ProtoParser protoParser, GrpcGapicRetryMapping retryMapping, String gapicInterfaceName) {
    Map<String, GapicMethodConfig> methodConfigMapBuilder = new LinkedHashMap<>();
    for (Entry<Method, MethodConfigProto> methodEntry : methodsToGenerate.entrySet()) {
        MethodConfigProto methodConfigProto = methodEntry.getValue();
        Method method = methodEntry.getKey();
        GapicMethodConfig methodConfig;
        if (protoParser.isProtoAnnotationsEnabled()) {
            methodConfig = GapicMethodConfig.createGapicMethodConfigFromProto(diagCollector, language, transportProtocol, defaultPackageName, methodConfigProto, method, messageConfigs, resourceNameConfigs, retryCodesConfig, retryParamsConfigNames, protoParser, retryMapping, gapicInterfaceName);
        } else {
            methodConfig = GapicMethodConfig.createGapicMethodConfigFromGapicYaml(diagCollector, language, methodConfigProto, method, messageConfigs, resourceNameConfigs, retryCodesConfig, retryParamsConfigNames);
        }
        if (methodConfig == null) {
            continue;
        }
        methodConfigMapBuilder.put(method.getSimpleName(), methodConfig);
    }
    if (diagCollector.getErrorCount() > 0) {
        return null;
    } else {
        return ImmutableMap.copyOf(methodConfigMapBuilder);
    }
}
Also used : MethodConfigProto(com.google.api.codegen.MethodConfigProto) Method(com.google.api.tools.framework.model.Method) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with MethodConfigProto

use of com.google.api.codegen.MethodConfigProto in project toolkit by googleapis.

the class SampleSpecTest method valueSetsMatching.

@Test
public void valueSetsMatching() {
    SampleValueSet valueSetAlice = SampleValueSet.newBuilder().setId("alice").setParameters(SampleParameters.newBuilder().addDefaults("apple").build()).build();
    SampleValueSet valueSetBob = SampleValueSet.newBuilder().setId("bob").setParameters(SampleParameters.newBuilder().addDefaults("banana").build()).build();
    SampleValueSet valueSetAlison = SampleValueSet.newBuilder().setId("alison").setParameters(SampleParameters.newBuilder().addDefaults("apricot").build()).build();
    final MethodConfigProto methodConfigProto = MethodConfigProto.newBuilder().addSampleValueSets(valueSetAlice).addSampleValueSets(valueSetBob).addSampleValueSets(valueSetAlison).setSamples(SampleConfiguration.newBuilder().addStandalone(SampleTypeConfiguration.newBuilder().addValueSets("ali.*").addCallingForms(".*")).addStandalone(SampleTypeConfiguration.newBuilder().addValueSets("be.*").addCallingForms(".*"))).build();
    SampleSpec sampleSpec = new SampleSpec(methodConfigProto);
    final List<SampleValueSet> matchingValues = sampleSpec.getSampleConfigs(Collections.singletonList(CallingForm.Request), CallingForm.Request, null, SampleType.STANDALONE).stream().map(config -> config.valueSet()).collect(Collectors.toList());
    assertThat(matchingValues).containsExactly(valueSetAlice, valueSetAlison).inOrder();
}
Also used : SampleTypeConfiguration(com.google.api.codegen.SampleConfiguration.SampleTypeConfiguration) SampleConfiguration(com.google.api.codegen.SampleConfiguration) List(java.util.List) MethodConfigProto(com.google.api.codegen.MethodConfigProto) SampleParameters(com.google.api.codegen.SampleParameters) SampleValueSet(com.google.api.codegen.SampleValueSet) CallingForm(com.google.api.codegen.viewmodel.CallingForm) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) SampleType(com.google.api.codegen.config.SampleSpec.SampleType) MethodConfigProto(com.google.api.codegen.MethodConfigProto) SampleValueSet(com.google.api.codegen.SampleValueSet) Test(org.junit.Test)

Example 5 with MethodConfigProto

use of com.google.api.codegen.MethodConfigProto in project toolkit by googleapis.

the class SampleSpecTest method storingDuplicateValueSets.

@Test(expected = IllegalArgumentException.class)
public void storingDuplicateValueSets() {
    final MethodConfigProto methodConfigProto = MethodConfigProto.newBuilder().addSampleValueSets(SampleValueSet.newBuilder().setId("alice")).addSampleValueSets(SampleValueSet.newBuilder().setId("bob")).addSampleValueSets(SampleValueSet.newBuilder().setId("alice")).setSamples(SampleConfiguration.newBuilder().addStandalone(SampleTypeConfiguration.newBuilder().addValueSets("alice").addCallingForms(".*")).addStandalone(SampleTypeConfiguration.newBuilder().addValueSets("bob").addCallingForms(".*"))).build();
    SampleSpec sampleSpec = new SampleSpec(methodConfigProto);
}
Also used : MethodConfigProto(com.google.api.codegen.MethodConfigProto) Test(org.junit.Test)

Aggregations

MethodConfigProto (com.google.api.codegen.MethodConfigProto)11 Method (com.google.api.tools.framework.model.Method)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Test (org.junit.Test)4 InterfaceConfigProto (com.google.api.codegen.InterfaceConfigProto)3 Interface (com.google.api.tools.framework.model.Interface)3 CollectionConfigProto (com.google.api.codegen.CollectionConfigProto)2 Method (com.google.api.codegen.discovery.Method)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ResourceDescriptor (com.google.api.ResourceDescriptor)1 ResourceReference (com.google.api.ResourceReference)1 CollectionOneofProto (com.google.api.codegen.CollectionOneofProto)1 ConfigProto (com.google.api.codegen.ConfigProto)1 DeprecatedCollectionConfigProto (com.google.api.codegen.DeprecatedCollectionConfigProto)1