use of com.google.api.codegen.transformer.DiscoGapicInterfaceContext in project toolkit by googleapis.
the class JavaDiscoGapicResourceNameToViewTransformer method transform.
@Override
public List<ViewModel> transform(DiscoApiModel apiModel, GapicProductConfig productConfig) {
List<ViewModel> surfaceRequests = new ArrayList<>();
String packageName = productConfig.getPackageName();
SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(apiModel, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.newBuilder().enableStringFormatFunctions(true).build());
// Keep track of which name patterns have been generated to avoid duplicate classes.
Set<String> namePatterns = new HashSet<>();
for (String interfaceName : productConfig.getInterfaceConfigMap().keySet()) {
SchemaTransformationContext requestContext = SchemaTransformationContext.create(interfaceName, context.getSchemaTypeTable(), context);
// Maps a canonical resource name pattern to any method that uses that pattern.
Map<String, Method> namePatternsToMethod = new HashMap<>();
for (MethodConfig methodConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getMethodConfigs()) {
Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
namePatternsToMethod.put(DiscoGapicParser.getCanonicalPath(method), method);
}
for (SingleResourceNameConfig nameConfig : productConfig.getInterfaceConfigMap().get(interfaceName).getSingleResourceNameConfigs()) {
String namePattern = nameConfig.getNamePattern();
if (namePatterns.contains(namePattern)) {
continue;
}
Method method = namePatternsToMethod.get(namePattern);
StaticLangApiResourceNameView resourceNameView = generateResourceNameClass(requestContext, method, nameConfig);
surfaceRequests.add(generateResourceNameFile(requestContext, resourceNameView));
namePatterns.add(nameConfig.getNamePattern());
}
}
Collections.sort(surfaceRequests, new Comparator<ViewModel>() {
@Override
public int compare(ViewModel o1, ViewModel o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
}
});
return surfaceRequests;
}
use of com.google.api.codegen.transformer.DiscoGapicInterfaceContext in project toolkit by googleapis.
the class JavaDiscoGapicSchemaToViewTransformer method transform.
@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceSchemas = new ArrayList<>();
String packageName = productConfig.getPackageName();
JavaSurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
DiscoGapicInterfaceContext context = DiscoGapicInterfaceContext.createWithoutInterface(model, productConfig, createTypeTable(productConfig.getPackageName(), surfaceNamer), surfaceNamer, JavaFeatureConfig.newBuilder().enableStringFormatFunctions(true).build());
for (Schema schema : context.getDocument().schemas().values()) {
Map<SchemaTransformationContext, StaticLangApiMessageView> contextViews = new TreeMap<>(SchemaTransformationContext.comparator);
generateSchemaClasses(contextViews, context, schema);
for (Map.Entry<SchemaTransformationContext, StaticLangApiMessageView> contextView : contextViews.entrySet()) {
surfaceSchemas.add(generateSchemaFile(contextView.getKey(), contextView.getValue()));
}
}
Collections.sort(surfaceSchemas, new Comparator<ViewModel>() {
@Override
public int compare(ViewModel o1, ViewModel o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
}
});
return surfaceSchemas;
}
use of com.google.api.codegen.transformer.DiscoGapicInterfaceContext in project toolkit by googleapis.
the class JavaDiscoGapicRequestToViewTransformer method transform.
@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceRequests = new ArrayList<>();
String packageName = productConfig.getPackageName();
SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
for (InterfaceModel apiInterface : model.getInterfaces()) {
boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
DiscoGapicInterfaceContext context = JavaDiscoGapicSurfaceTransformer.newInterfaceContext(apiInterface, productConfig, surfaceNamer, createTypeTable(productConfig.getPackageName()), enableStringFormatFunctions);
for (MethodModel method : context.getSupportedMethods()) {
RequestObjectParamView params = getRequestObjectParams(context, method);
SchemaTransformationContext requestContext = SchemaTransformationContext.create(method.getFullName(), context.getSchemaTypeTable(), context);
StaticLangApiMessageView requestView = generateRequestClass(requestContext, method, params);
surfaceRequests.add(generateRequestFile(requestContext, requestView));
}
}
Collections.sort(surfaceRequests, new Comparator<ViewModel>() {
@Override
public int compare(ViewModel o1, ViewModel o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
}
});
return surfaceRequests;
}
Aggregations