Search in sources :

Example 1 with InterfaceModel

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;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GrpcStubView(com.google.api.codegen.viewmodel.GrpcStubView) TreeMap(java.util.TreeMap) InterfaceModel(com.google.api.codegen.config.InterfaceModel) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with InterfaceModel

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;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with InterfaceModel

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;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 4 with InterfaceModel

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;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) SnippetsFileView(com.google.api.codegen.viewmodel.SnippetsFileView)

Example 5 with InterfaceModel

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;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

InterfaceModel (com.google.api.codegen.config.InterfaceModel)33 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)23 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)17 ViewModel (com.google.api.codegen.viewmodel.ViewModel)17 ArrayList (java.util.ArrayList)16 ImmutableList (com.google.common.collect.ImmutableList)12 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)8 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)6 MethodModel (com.google.api.codegen.config.MethodModel)5 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)4 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)4 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)4 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)3 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)3 VersionIndexRequireView (com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)3 MockServiceUsageView (com.google.api.codegen.viewmodel.testing.MockServiceUsageView)3 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)2 FeatureConfig (com.google.api.codegen.transformer.FeatureConfig)2 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)2 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)2