Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
g-easy committed Aug 1, 2019
2 parents 572fcfb + 2b20acc commit 382b1f1
Show file tree
Hide file tree
Showing 23 changed files with 1,352 additions and 724 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ public static List<CodeGenerator<?>> create(
GapicCodePathMapper samplePathMapper = newCodePathMapper.apply(".Samples");
generators.add(
newCsharpGenerator.apply(new CSharpStandaloneSampleTransformer(samplePathMapper)));
if (artifactFlags.packagingFilesEnabled()) {
generators.add(
newCsharpGenerator.apply(CSharpBasicPackageTransformer.forSamples(samplePathMapper)));
}
}

} else if (language.equals(GO)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class CSharpBasicPackageTransformer implements ModelToViewTransformer<Pro
"csharp/gapic_snippets_csproj.snip";
private static final String UNITTEST_CSPROJ_TEMPLATE_FILENAME =
"csharp/gapic_unittest_csproj.snip";
private static final String SAMPLE_CSPROJ_TEMPLATE_FILENAME = "csharp/gapic_samples_csproj.snip";

private static final CSharpAliasMode ALIAS_MODE = CSharpAliasMode.MessagesOnly;

Expand All @@ -63,6 +64,11 @@ private CSharpBasicPackageTransformer(
this.shouldGenerateFn = shouldGenerateFn;
}

public static CSharpBasicPackageTransformer forSamples(GapicCodePathMapper pathMapper) {
return new CSharpBasicPackageTransformer(
pathMapper, SAMPLE_CSPROJ_TEMPLATE_FILENAME, ".Samples.csproj", shouldGenSamplePackage());
}

public static CSharpBasicPackageTransformer forSmokeTests(GapicCodePathMapper pathMapper) {
return new CSharpBasicPackageTransformer(
pathMapper,
Expand All @@ -85,6 +91,22 @@ private static Predicate<GapicInterfaceContext> shouldGenSmokeTestPackage() {
return parameter -> parameter.getInterfaceConfig().getSmokeTestConfig() != null;
}

private static Predicate<GapicInterfaceContext> shouldGenSamplePackage() {
return CSharpBasicPackageTransformer::shouldGenerateSamplePackage;
}

private static boolean shouldGenerateSamplePackage(GapicInterfaceContext interfaceContext) {
boolean fromSampleConfigs =
!interfaceContext.getProductConfig().getSampleConfigTable().cellSet().isEmpty();
boolean fromGapicConfigs =
interfaceContext
.getInterfaceConfig()
.getMethodConfigs()
.stream()
.anyMatch(config -> config.getSampleSpec().isConfigured());
return fromSampleConfigs || fromGapicConfigs;
}

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ private List<ParamDocView> generateOptionsParamDocs() {
retryParamDoc.lines(
ImmutableList.of(
" A retry object used",
"to retry requests. If ``None`` is specified, requests will not",
"be retried."));
"to retry requests. If ``None`` is specified, requests will",
"be retried using a default configuration."));

SimpleParamDocView.Builder timeoutParamDoc = SimpleParamDocView.newBuilder();
timeoutParamDoc.paramName("timeout");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private List<PackageDependencyView> generateAdditionalDependencies() {
ImmutableList.Builder<PackageDependencyView> dependencies = ImmutableList.builder();
dependencies.add(
PackageDependencyView.create(
"google-api-core[grpc]", VersionBound.create("1.4.1", "2.0.0dev")));
"google-api-core[grpc]", VersionBound.create("1.14.0", "2.0.0dev")));
return dependencies.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
}
@end

@snippet processCliArguments(sample)
@snippet processCliArguments(sample, sampleClassName)
@if sample.sampleInitCode.argDefaultParams
@if sample.usesAsyncAwaitPattern
new Parser(with => with.CaseInsensitiveEnumValues = true).ParseArguments<Options>(args)
.WithParsed<Options>(opts =>
{@sample.sampleFunctionName}Async({@commaSeparatedOpts(sample.sampleInitCode.argDefaultParams)}).Wait());
{@sampleClassName}.{@sample.sampleFunctionName}Async({@commaSeparatedOpts(sample.sampleInitCode.argDefaultParams)}).Wait());
@else
new Parser(with => with.CaseInsensitiveEnumValues = true).ParseArguments<Options>(args)
.WithParsed<Options>(opts =>
{@sample.sampleFunctionName}({@commaSeparatedOpts(sample.sampleInitCode.argDefaultParams)}));
{@sampleClassName}.{@sample.sampleFunctionName}({@commaSeparatedOpts(sample.sampleInitCode.argDefaultParams)}));
@end
@else
@if sample.usesAsyncAwaitPattern
{@sample.sampleFunctionName}Async().Wait();
{@sampleClassName}.{@sample.sampleFunctionName}Async().Wait();
@else
{@sample.sampleFunctionName}();
{@sampleClassName}.{@sample.sampleFunctionName}();
@end
@end
@end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@snippet generate(sample)
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../{@sample.fileHeader.packageName}/{@sample.fileHeader.packageName}.csproj" />
<PackageReference Include="CommandLineParser" Version="2.5.0" />
</ItemGroup>

</Project>

@end
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

using CommandLine;

// [START {@sample.regionTag}]
namespace {@sampleFile.fileHeader.packageName}.Samples
{
// [START {@sample.regionTag}]
@if sample.sampleImports.appImports
{@imports(sample.sampleImports)}

Expand Down Expand Up @@ -100,11 +100,14 @@
@default
Unrecognized callingForm: {@sample.callingForm}
@end
// [END {@sample.regionTag}]
}

// [END {@sample.regionTag}]

public class {@sampleClass.name}Main {
public static void Main(string[] args)
{
{@processCliArguments(sample)}
{@processCliArguments(sample, @sampleClass.name)}
}
@if sample.sampleInitCode.argDefaultParams

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/com/google/api/codegen/nodejs/main.snip
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* your project ID will be detected automatically.
* @@param {function} [options.promise] - Custom promise module to use instead
* of native Promises.
* @@param {string} [options.servicePath] - The domain name of the
* @@param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
*/
constructor(opts) {
Expand Down Expand Up @@ -432,6 +432,9 @@
{@handleCallback()}
@case "NonStreaming"
{@handleCallback()}
request = request || {};
@case "ServerStreaming"
request = request || {};
@default
@end
options = options || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
'google-gax': ('https://gax-python.readthedocs.io/en/latest/', None),
'google.api_core': ('https://googleapis.github.io/google-cloud-python/latest', None),
'grpc': ('https://grpc.io/grpc/python/', None),
'requests': ('http://docs.python-requests.org/en/master/', None),
'requests': ('https://2.python-requests.org/en/master/', None),
'fastavro': ('https://fastavro.readthedocs.io/en/stable/', None),
'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
}
Expand Down
Loading

0 comments on commit 382b1f1

Please sign in to comment.