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();
}
}
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();
}
}
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);
}
}
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();
}
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);
}
Aggregations