Search in sources :

Example 16 with InterfaceModel

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

the class PythonPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// This currently generates a list of methods that have smoke test configuration. In the future,
// the example methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
            FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
            GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
            exampleMethods.add(createExampleApiMethodView(flattenedMethodContext));
        }
    }
    return exampleMethods.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 17 with InterfaceModel

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

the class RubyGapicSurfaceTransformer method generateVersionIndexView.

private ViewModel generateVersionIndexView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
    Iterable<? extends InterfaceModel> interfaces = model.getInterfaces();
    for (InterfaceModel apiInterface : interfaces) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        requireViews.add(VersionIndexRequireView.newBuilder().clientName(namer.getFullyQualifiedApiWrapperClassName(interfaceConfig)).fileName(namer.getServiceFileName(interfaceConfig)).serviceName(namer.getPackageServiceName(context.getInterfaceConfig())).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
    }
    // append any additional types
    Set<String> requireTypes = new HashSet<>();
    for (TypeModel type : model.getAdditionalTypes()) {
        if (type instanceof ProtoTypeRef) {
            ProtoTypeRef t = (ProtoTypeRef) type;
            String name = namer.getVersionIndexFileImportName() + "/" + namer.getProtoFileImportName(t.getProtoType().getMessageType().getFile().getSimpleName());
            requireTypes.add(name);
        }
    }
    return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).requireTypes(ImmutableList.copyOf(requireTypes)).templateFileName(VERSION_INDEX_TEMPLATE_FILE).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.RUBY).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + versionPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, true)).type(VersionIndexType.VersionIndex).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) TypeModel(com.google.api.codegen.config.TypeModel) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) HashSet(java.util.HashSet)

Example 18 with InterfaceModel

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

the class MockServiceTransformer method createMockServices.

public List<MockServiceUsageView> createMockServices(SurfaceNamer namer, ApiModel model, GapicProductConfig productConfig) {
    List<MockServiceUsageView> mockServices = new ArrayList<>();
    for (InterfaceModel apiInterface : getGrpcInterfacesToMock(model, productConfig)) {
        MockServiceUsageView mockService = MockServiceUsageView.newBuilder().className(namer.getMockServiceClassName(apiInterface)).varName(namer.getMockServiceVarName(apiInterface)).implName(namer.getMockGrpcServiceImplName(apiInterface)).registerFunctionName(namer.getServerRegisterFunctionName(apiInterface)).build();
        mockServices.add(mockService);
    }
    return mockServices;
}
Also used : MockServiceUsageView(com.google.api.codegen.viewmodel.testing.MockServiceUsageView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList)

Example 19 with InterfaceModel

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

the class CSharpGapicClientTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
    CSharpFeatureConfig featureConfig = new CSharpFeatureConfig();
    InterfaceModel lastApiInterface = null;
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
        surfaceDocs.add(generateApiAndSettingsView(context));
        lastApiInterface = apiInterface;
    }
    GapicInterfaceContext context = GapicInterfaceContext.create(lastApiInterface, productConfig, createTypeTable(productConfig.getPackageName()), namer, featureConfig);
    surfaceDocs.add(generateResourceNamesView(context));
    surfaceDocs.add(generateCsProjView(context));
    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)

Example 20 with InterfaceModel

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

the class GoGapicSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
    List<ViewModel> models = new ArrayList<ViewModel>();
    models.add(generateMockServiceView(model, productConfig, namer));
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, GoGapicSurfaceTransformer.createTypeTable(), namer, featureConfig);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            models.add(createSmokeTestClassView(context));
        }
    }
    return models;
}
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)

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