use of com.google.api.codegen.config.InterfaceModel in project toolkit by googleapis.
the class GrpcStubTransformer method generateGrpcStubs.
public List<GrpcStubView> generateGrpcStubs(InterfaceContext context) {
List<GrpcStubView> stubs = new ArrayList<>();
Map<String, InterfaceModel> interfaces = new TreeMap<>();
Map<String, List<MethodModel>> methods = new TreeMap<>();
for (MethodModel method : context.getSupportedMethods()) {
InterfaceModel targetInterface = context.asRequestMethodContext(method).getTargetInterface();
interfaces.put(targetInterface.getFullName(), targetInterface);
if (methods.containsKey(targetInterface.getFullName())) {
methods.get(targetInterface.getFullName()).add(method);
} else {
methods.put(targetInterface.getFullName(), new ArrayList<>(Arrays.asList(method)));
}
}
for (Map.Entry<String, InterfaceModel> entry : interfaces.entrySet()) {
InterfaceModel apiInterface = entry.getValue();
stubs.add(generateGrpcStub(context, apiInterface, methods.get(entry.getKey())));
}
return stubs;
}
use of com.google.api.codegen.config.InterfaceModel in project toolkit by googleapis.
the class MockServiceTransformer method getGrpcInterfacesForService.
public Map<String, InterfaceModel> getGrpcInterfacesForService(ApiModel model, GapicProductConfig productConfig, InterfaceModel apiInterface) {
if (!productConfig.getTransportProtocol().equals(TransportProtocol.GRPC)) {
return ImmutableMap.of();
}
Map<String, InterfaceModel> interfaces = new LinkedHashMap<>();
interfaces.put(apiInterface.getFullName(), apiInterface);
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
String reroute = methodConfig.getRerouteToGrpcInterface();
if (!Strings.isNullOrEmpty(reroute)) {
InterfaceModel targetInterface = model.getInterface(reroute);
interfaces.put(reroute, targetInterface);
}
}
return interfaces;
}
use of com.google.api.codegen.config.InterfaceModel in project toolkit by googleapis.
the class CSharpGapicSmokeTestTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getPackageName()), namer, new CSharpFeatureConfig());
csharpCommonTransformer.addCommonImports(context);
SmokeTestClassView smokeTests = generateSmokeTest(context);
if (smokeTests != null) {
surfaceDocs.add(smokeTests);
surfaceDocs.add(generateSmokeTestCsproj(context));
}
}
return surfaceDocs;
}
use of com.google.api.codegen.config.InterfaceModel in project toolkit by googleapis.
the class CSharpGapicSnippetsTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getExamplePackageName()), namer, new CSharpFeatureConfig());
csharpCommonTransformer.addCommonImports(context);
context.getImportTypeTable().saveNicknameFor("Google.Protobuf.Bytestring");
context.getImportTypeTable().saveNicknameFor("System.Linq.__import__");
SnippetsFileView snippets = generateSnippets(context);
surfaceDocs.add(snippets);
}
return surfaceDocs;
}
use of com.google.api.codegen.config.InterfaceModel in project toolkit by googleapis.
the class CSharpGapicUnitTestTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getPackageName()), namer, new CSharpFeatureConfig());
csharpCommonTransformer.addCommonImports(context);
ModelTypeTable typeTable = context.getImportTypeTable();
typeTable.saveNicknameFor("Xunit.FactAttribute");
typeTable.saveNicknameFor("Moq.Mock");
if (context.getLongRunningMethods().iterator().hasNext()) {
typeTable.saveNicknameFor("Google.LongRunning.Operations");
}
surfaceDocs.add(generateUnitTest(context));
surfaceDocs.add(generateUnitTestCsproj(context));
}
return surfaceDocs;
}
Aggregations