Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-api-go-client): add x-goog-api-version header #2563

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions google-api-go-generator/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,10 @@ func (meth *Method) generateCode() {
contentType = `"application/json"`
}
pn(`reqHeaders := gensupport.SetHeaders(c.s.userAgent(), %s, c.header_ )`, contentType)
apiVersion := meth.m.APIVersion
codyoss marked this conversation as resolved.
Show resolved Hide resolved
if apiVersion != "" {
pn(`reqHeaders.Set("x-goog-api-version", %q)`, apiVersion)
}
if httpMethod == "GET" {
pn(`if c.ifNoneMatch_ != "" {`)
pn(` reqHeaders.Set("If-None-Match", c.ifNoneMatch_)`)
Expand Down
1 change: 1 addition & 0 deletions google-api-go-generator/internal/disco/disco.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ type Method struct {
Scopes []string
MediaUpload *MediaUpload
SupportsMediaDownload bool
APIVersion string

JSONMap map[string]interface{} `json:"-"`
}
Expand Down
15 changes: 15 additions & 0 deletions google-api-go-generator/testdata/any.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@
"list": {
"id": "logging.projects.logs.list",
"path": "v1beta3/projects/{projectsId}/logs",
"apiVersion": "v1_20240501",
"httpMethod": "GET",
"description": "Lists log resources belonging to the specified project.",
"parameters": {
Expand Down Expand Up @@ -477,6 +478,7 @@
"delete": {
"id": "logging.projects.logs.delete",
"path": "v1beta3/projects/{projectsId}/logs/{logsId}",
"apiVersion": "v1_20240501",
"httpMethod": "DELETE",
"description": "Deletes the specified log resource and all log entries contained in it.",
"parameters": {
Expand Down Expand Up @@ -511,6 +513,7 @@
"write": {
"id": "logging.projects.logs.entries.write",
"path": "v1beta3/projects/{projectsId}/logs/{logsId}/entries:write",
"apiVersion": "v1_20240501",
"httpMethod": "POST",
"description": "Creates one or more log entries in a log. You must supply a list of `LogEntry` objects, named `entries`. Each `LogEntry` object must contain a payload object and a `LogEntryMetadata` object that describes the entry. You must fill in all the fields of the entry, metadata, and payload. You can also supply a map, `commonLabels`, that supplies default (key, value) data for the `entries[].metadata.labels` maps, saving you the trouble of creating identical copies for each entry.",
"parameters": {
Expand Down Expand Up @@ -548,6 +551,7 @@
"list": {
"id": "logging.projects.logs.sinks.list",
"path": "v1beta3/projects/{projectsId}/logs/{logsId}/sinks",
"apiVersion": "v1_20240501",
"httpMethod": "GET",
"description": "Lists log sinks associated with the specified log.",
"parameters": {
Expand Down Expand Up @@ -578,6 +582,7 @@
"get": {
"id": "logging.projects.logs.sinks.get",
"path": "v1beta3/projects/{projectsId}/logs/{logsId}/sinks/{sinksId}",
"apiVersion": "v1_20240501",
"httpMethod": "GET",
"description": "Gets the specified log sink resource.",
"parameters": {
Expand Down Expand Up @@ -615,6 +620,7 @@
"create": {
"id": "logging.projects.logs.sinks.create",
"path": "v1beta3/projects/{projectsId}/logs/{logsId}/sinks",
"apiVersion": "v1_20240501",
"httpMethod": "POST",
"description": "Creates the specified log sink resource.",
"parameters": {
Expand Down Expand Up @@ -648,6 +654,7 @@
"update": {
"id": "logging.projects.logs.sinks.update",
"path": "v1beta3/projects/{projectsId}/logs/{logsId}/sinks/{sinksId}",
"apiVersion": "v1_20240501",
"httpMethod": "PUT",
"description": "Creates or updates the specified log sink resource.",
"parameters": {
Expand Down Expand Up @@ -688,6 +695,7 @@
"delete": {
"id": "logging.projects.logs.sinks.delete",
"path": "v1beta3/projects/{projectsId}/logs/{logsId}/sinks/{sinksId}",
"apiVersion": "v1_20240501",
"httpMethod": "DELETE",
"description": "Deletes the specified log sink resource.",
"parameters": {
Expand Down Expand Up @@ -731,6 +739,7 @@
"list": {
"id": "logging.projects.logServices.list",
"path": "v1beta3/projects/{projectsId}/logServices",
"apiVersion": "v1_20240501",
"httpMethod": "GET",
"description": "Lists log services associated with log entries ingested for a project.",
"parameters": {
Expand Down Expand Up @@ -774,6 +783,7 @@
"list": {
"id": "logging.projects.logServices.indexes.list",
"path": "v1beta3/projects/{projectsId}/logServices/{logServicesId}/indexes",
"apiVersion": "v1_20240501",
"httpMethod": "GET",
"description": "Lists log service indexes associated with a log service.",
"parameters": {
Expand Down Expand Up @@ -835,6 +845,7 @@
"list": {
"id": "logging.projects.logServices.sinks.list",
"path": "v1beta3/projects/{projectsId}/logServices/{logServicesId}/sinks",
"apiVersion": "v1_20240501",
"httpMethod": "GET",
"description": "Lists log service sinks associated with the specified service.",
"parameters": {
Expand Down Expand Up @@ -865,6 +876,7 @@
"get": {
"id": "logging.projects.logServices.sinks.get",
"path": "v1beta3/projects/{projectsId}/logServices/{logServicesId}/sinks/{sinksId}",
"apiVersion": "v1_20240501",
"httpMethod": "GET",
"description": "Gets the specified log service sink resource.",
"parameters": {
Expand Down Expand Up @@ -902,6 +914,7 @@
"create": {
"id": "logging.projects.logServices.sinks.create",
"path": "v1beta3/projects/{projectsId}/logServices/{logServicesId}/sinks",
"apiVersion": "v1_20240501",
"httpMethod": "POST",
"description": "Creates the specified log service sink resource.",
"parameters": {
Expand Down Expand Up @@ -935,6 +948,7 @@
"update": {
"id": "logging.projects.logServices.sinks.update",
"path": "v1beta3/projects/{projectsId}/logServices/{logServicesId}/sinks/{sinksId}",
"apiVersion": "v1_20240501",
"httpMethod": "PUT",
"description": "Creates or update the specified log service sink resource.",
"parameters": {
Expand Down Expand Up @@ -975,6 +989,7 @@
"delete": {
"id": "logging.projects.logServices.sinks.delete",
"path": "v1beta3/projects/{projectsId}/logServices/{logServicesId}/sinks/{sinksId}",
"apiVersion": "v1_20240501",
"httpMethod": "DELETE",
"description": "Deletes the specified log service sink.",
"parameters": {
Expand Down
15 changes: 15 additions & 0 deletions google-api-go-generator/testdata/any.want
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ func (c *ProjectsLogServicesListCall) Header() http.Header {

func (c *ProjectsLogServicesListCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
if c.ifNoneMatch_ != "" {
reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
}
Expand Down Expand Up @@ -933,6 +934,7 @@ func (c *ProjectsLogServicesIndexesListCall) Header() http.Header {

func (c *ProjectsLogServicesIndexesListCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
if c.ifNoneMatch_ != "" {
reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
}
Expand Down Expand Up @@ -1060,6 +1062,7 @@ func (c *ProjectsLogServicesSinksCreateCall) Header() http.Header {

func (c *ProjectsLogServicesSinksCreateCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink)
if err != nil {
Expand Down Expand Up @@ -1166,6 +1169,7 @@ func (c *ProjectsLogServicesSinksDeleteCall) Header() http.Header {

func (c *ProjectsLogServicesSinksDeleteCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
c.urlParams_.Set("alt", alt)
c.urlParams_.Set("prettyPrint", "false")
Expand Down Expand Up @@ -1278,6 +1282,7 @@ func (c *ProjectsLogServicesSinksGetCall) Header() http.Header {

func (c *ProjectsLogServicesSinksGetCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
if c.ifNoneMatch_ != "" {
reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
}
Expand Down Expand Up @@ -1391,6 +1396,7 @@ func (c *ProjectsLogServicesSinksListCall) Header() http.Header {

func (c *ProjectsLogServicesSinksListCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
if c.ifNoneMatch_ != "" {
reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
}
Expand Down Expand Up @@ -1499,6 +1505,7 @@ func (c *ProjectsLogServicesSinksUpdateCall) Header() http.Header {

func (c *ProjectsLogServicesSinksUpdateCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink)
if err != nil {
Expand Down Expand Up @@ -1604,6 +1611,7 @@ func (c *ProjectsLogsDeleteCall) Header() http.Header {

func (c *ProjectsLogsDeleteCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
c.urlParams_.Set("alt", alt)
c.urlParams_.Set("prettyPrint", "false")
Expand Down Expand Up @@ -1750,6 +1758,7 @@ func (c *ProjectsLogsListCall) Header() http.Header {

func (c *ProjectsLogsListCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
if c.ifNoneMatch_ != "" {
reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
}
Expand Down Expand Up @@ -1882,6 +1891,7 @@ func (c *ProjectsLogsEntriesWriteCall) Header() http.Header {

func (c *ProjectsLogsEntriesWriteCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.writelogentriesrequest)
if err != nil {
Expand Down Expand Up @@ -1988,6 +1998,7 @@ func (c *ProjectsLogsSinksCreateCall) Header() http.Header {

func (c *ProjectsLogsSinksCreateCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink)
if err != nil {
Expand Down Expand Up @@ -2094,6 +2105,7 @@ func (c *ProjectsLogsSinksDeleteCall) Header() http.Header {

func (c *ProjectsLogsSinksDeleteCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
c.urlParams_.Set("alt", alt)
c.urlParams_.Set("prettyPrint", "false")
Expand Down Expand Up @@ -2206,6 +2218,7 @@ func (c *ProjectsLogsSinksGetCall) Header() http.Header {

func (c *ProjectsLogsSinksGetCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
if c.ifNoneMatch_ != "" {
reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
}
Expand Down Expand Up @@ -2318,6 +2331,7 @@ func (c *ProjectsLogsSinksListCall) Header() http.Header {

func (c *ProjectsLogsSinksListCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
if c.ifNoneMatch_ != "" {
reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
}
Expand Down Expand Up @@ -2426,6 +2440,7 @@ func (c *ProjectsLogsSinksUpdateCall) Header() http.Header {

func (c *ProjectsLogsSinksUpdateCall) doRequest(alt string) (*http.Response, error) {
reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
reqHeaders.Set("x-goog-api-version", "v1_20240501")
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink)
if err != nil {
Expand Down