use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(InterfaceContext context) {
SurfaceNamer namer = context.getNamer();
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
MethodContext methodContext = context.asRequestMethodContext(method);
SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.name(namer.getSmokeTestClassName(context.getInterfaceConfig()));
testClass.outputPath(context.getProductConfig().getPackageName() + File.separator + method.getSimpleName() + "_smoke_test.go");
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethodView);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
// The shared code above add imports both for input and output.
// Since we use short decls, we don't need to import anything for output.
context.getImportTypeTable().getImports().clear();
method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testClass.fileHeader(fileHeader);
return testClass.build();
}
use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method createSmokeTestCaseApiMethodView.
private StaticLangApiMethodView createSmokeTestCaseApiMethodView(MethodContext methodContext) {
StaticLangApiMethodView initialApiMethodView;
if (methodContext.getMethodConfig().isPageStreaming()) {
initialApiMethodView = apiMethodTransformer.generatePagedRequestObjectMethod(methodContext);
} else {
initialApiMethodView = apiMethodTransformer.generateRequestObjectMethod(methodContext);
}
StaticLangApiMethodView.Builder apiMethodView = initialApiMethodView.toBuilder();
InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
apiMethodView.initCode(initCodeView);
return apiMethodView.build();
}
use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generateApiMethods.
@VisibleForTesting
List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context, Iterable<MethodModel> methods) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
for (MethodModel method : methods) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext methodContext = context.asRequestMethodContext(method);
if (method.getRequestStreaming() || method.getResponseStreaming()) {
apiMethods.add(apiMethodTransformer.generateGrpcStreamingRequestObjectMethod(methodContext));
} else if (methodConfig.isPageStreaming()) {
apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(methodContext));
} else if (methodConfig.isLongRunningOperation()) {
apiMethods.add(apiMethodTransformer.generateOperationRequestObjectMethod(methodContext));
} else {
apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(methodContext));
}
}
return apiMethods;
}
use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateStubInterface.
private StaticLangStubInterfaceView generateStubInterface(InterfaceContext context, GapicProductConfig productConfig) {
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
addStubInterfaceImports(context);
// Stub class has different default package name from methods classes.
InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName());
List<StaticLangApiMethodView> methods = generateApiMethods(apiMethodsContext);
for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) {
context.getImportTypeTable().getAndSaveNicknameFor(alias);
}
StaticLangStubInterfaceView.Builder stubInterface = StaticLangStubInterfaceView.newBuilder();
stubInterface.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
String name = context.getNamer().getApiStubInterfaceName(context.getInterfaceConfig());
stubInterface.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
stubInterface.name(name);
stubInterface.callableMethods(filterIncludeCallableMethods(methods));
stubInterface.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
return stubInterface.build();
}
use of com.google.api.codegen.viewmodel.StaticLangApiMethodView in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateApiClass.
private StaticLangApiView generateApiClass(InterfaceContext context, GapicProductConfig productConfig) {
SurfaceNamer namer = context.getNamer();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
addApiImports(context);
List<StaticLangApiMethodView> methods = generateApiMethods(context);
StaticLangApiView.Builder xapiClass = StaticLangApiView.newBuilder();
ApiMethodView exampleApiMethod = getExampleApiMethod(methods);
xapiClass.doc(serviceTransformer.generateServiceDoc(context, exampleApiMethod, productConfig));
String name = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig());
xapiClass.releaseLevelAnnotation(namer.getReleaseAnnotation(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
xapiClass.name(name);
xapiClass.settingsClassName(namer.getApiSettingsClassName(interfaceConfig));
xapiClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
xapiClass.stubSettingsClassName(getAndSaveNicknameForStubType(context, namer.getApiStubSettingsClassName(interfaceConfig)));
xapiClass.apiCallableMembers(apiCallableTransformer.generateStaticLangApiCallables(context));
xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
xapiClass.apiMethods(methods);
xapiClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
xapiClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
xapiClass.pagedResponseViews(generatePagedResponseWrappers(context, productConfig, packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
return xapiClass.build();
}
Aggregations