Skip to content

Commit

Permalink
feat: (REST) Generate ApiVersion overrides on a per method basis
Browse files Browse the repository at this point in the history
The change to the Translate Discovery doc is manual; there are no public Discovery docs that include API versions yet.
  • Loading branch information
jskeet committed Apr 17, 2024
1 parent 503c1e5 commit 184bfe2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ protected override void InitParameters()
{
base.InitParameters();
}

/// <inheritdoc/>
public override string ApiVersion => "testversion";
}

/// <summary>Detects the language of text within a request.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"detections": {
"methods": {
"detect": {
"apiVersion": "testversion",
"description": "Detects the language of text within a request.",
"httpMethod": "POST",
"id": "language.detections.detect",
Expand Down
12 changes: 10 additions & 2 deletions Google.Api.Generator.Rest/Models/MethodModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class MethodModel
private bool SupportsMediaDownload => _restMethod.SupportsMediaDownload ?? false;
private bool SupportsMediaUpload => _restMethod.SupportsMediaUpload ?? false;

public string ApiVersion => _restMethod.ApiVersion;

public MethodModel(PackageModel package, ResourceModel resource, string name, RestMethod restMethod)
{
Package = GaxPreconditions.CheckNotNull(package, nameof(package));
Expand Down Expand Up @@ -194,13 +196,19 @@ private ClassDeclarationSyntax GenerateRequestType(SourceFileContext ctx)
parameters.Select(p => p.GenerateInitializer(ctx)).ToArray())
.WithXmlDoc(XmlDoc.Summary($"Initializes {PascalCasedName} parameter list."));

// TODO: Media downloader members

cls = cls.AddMembers(ctor);
cls = cls.AddMembers(parameters.SelectMany(p => p.GenerateDeclarations(ctx)).ToArray());
cls = cls.AddMembers(bodyDeclarations);
cls = cls.AddMembers(methodName, httpMethod, restPath, initParameters);

if (ApiVersion is string apiVersion)
{
var apiVersionProperty = Property(Modifier.Public | Modifier.Override, ctx.Type<string>(), "ApiVersion")
.WithGetBody(ApiVersion)
.WithXmlDoc(XmlDoc.InheritDoc);
cls = cls.AddMembers(apiVersionProperty);
}

if (SupportsMediaDownload)
{
cls = cls.AddMembers(mediaDownloaderProperty);
Expand Down

0 comments on commit 184bfe2

Please sign in to comment.