...

Text file src/google.golang.org/api/google-api-go-generator/testdata/unfortunatedefaults.want

Documentation: google.golang.org/api/google-api-go-generator/testdata

     1// Copyright YEAR Google LLC.
     2// Use of this source code is governed by a BSD-style
     3// license that can be found in the LICENSE file.
     4
     5// Code generated file. DO NOT EDIT.
     6
     7// Package wrapnewlines provides access to the Example API.
     8//
     9// # Library status
    10//
    11// These client libraries are officially supported by Google. However, this
    12// library is considered complete and is in maintenance mode. This means
    13// that we will address critical bugs and security issues but will not add
    14// any new features.
    15//
    16// When possible, we recommend using our newer
    17// [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
    18// that are still actively being worked and iterated on.
    19//
    20// # Creating a client
    21//
    22// Usage example:
    23//
    24//	import "google.golang.org/api/wrapnewlines/v1"
    25//	...
    26//	ctx := context.Background()
    27//	wrapnewlinesService, err := wrapnewlines.NewService(ctx)
    28//
    29// In this example, Google Application Default Credentials are used for
    30// authentication. For information on how to create and obtain Application
    31// Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    32//
    33// # Other authentication options
    34//
    35// To use an API key for authentication (note: some APIs do not support API
    36// keys), use [google.golang.org/api/option.WithAPIKey]:
    37//
    38//	wrapnewlinesService, err := wrapnewlines.NewService(ctx, option.WithAPIKey("AIza..."))
    39//
    40// To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
    41// flow, use [google.golang.org/api/option.WithTokenSource]:
    42//
    43//	config := &oauth2.Config{...}
    44//	// ...
    45//	token, err := config.Exchange(ctx, ...)
    46//	wrapnewlinesService, err := wrapnewlines.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    47//
    48// See [google.golang.org/api/option.ClientOption] for details on options.
    49package wrapnewlines // import "google.golang.org/api/wrapnewlines/v1"
    50
    51import (
    52	"bytes"
    53	"context"
    54	"encoding/json"
    55	"errors"
    56	"fmt"
    57	"io"
    58	"net/http"
    59	"net/url"
    60	"strconv"
    61	"strings"
    62
    63	googleapi "google.golang.org/api/googleapi"
    64	internal "google.golang.org/api/internal"
    65	gensupport "google.golang.org/api/internal/gensupport"
    66	option "google.golang.org/api/option"
    67	internaloption "google.golang.org/api/option/internaloption"
    68	htransport "google.golang.org/api/transport/http"
    69)
    70
    71// Always reference these packages, just in case the auto-generated code
    72// below doesn't.
    73var _ = bytes.NewBuffer
    74var _ = strconv.Itoa
    75var _ = fmt.Sprintf
    76var _ = json.NewDecoder
    77var _ = io.Copy
    78var _ = url.Parse
    79var _ = gensupport.MarshalJSON
    80var _ = googleapi.Version
    81var _ = errors.New
    82var _ = strings.Replace
    83var _ = context.Canceled
    84var _ = internaloption.WithDefaultEndpoint
    85var _ = internal.Version
    86
    87const apiId = "wrapnewlines:v1"
    88const apiName = "wrapnewlines"
    89const apiVersion = "v1"
    90const basePath = "https://www.googleapis.com/discovery/v1/apis"
    91const basePathTemplate = "https://www.UNIVERSE_DOMAIN/discovery/v1/apis"
    92
    93// NewService creates a new Service.
    94func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
    95	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
    96	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
    97	opts = append(opts, internaloption.EnableNewAuthLibrary())
    98	client, endpoint, err := htransport.NewClient(ctx, opts...)
    99	if err != nil {
   100		return nil, err
   101	}
   102	s, err := New(client)
   103	if err != nil {
   104		return nil, err
   105	}
   106	if endpoint != "" {
   107		s.BasePath = endpoint
   108	}
   109	return s, nil
   110}
   111
   112// New creates a new Service. It uses the provided http.Client for requests.
   113//
   114// Deprecated: please use NewService instead.
   115// To provide a custom HTTP client, use option.WithHTTPClient.
   116// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   117func New(client *http.Client) (*Service, error) {
   118	if client == nil {
   119		return nil, errors.New("client is nil")
   120	}
   121	s := &Service{client: client, BasePath: basePath}
   122	return s, nil
   123}
   124
   125type Service struct {
   126	client    *http.Client
   127	BasePath  string // API endpoint base URL
   128	UserAgent string // optional additional User-Agent fragment
   129}
   130
   131func (s *Service) userAgent() string {
   132	if s.UserAgent == "" {
   133		return googleapi.UserAgent
   134	}
   135	return googleapi.UserAgent + " " + s.UserAgent
   136}
   137
   138// Thing: don't care
   139type Thing struct {
   140	// BoolEmptyDefaultA:
   141	// Nonempty default: no
   142	// Unfortunate default: no
   143	BoolEmptyDefaultA bool `json:"bool_empty_default_a,omitempty"`
   144	// BoolEmptyDefaultB:
   145	// Nonempty default: no
   146	// Unfortunate default: no
   147	BoolEmptyDefaultB bool `json:"bool_empty_default_b,omitempty"`
   148	// BoolNonemptyDefault:
   149	// Nonempty default: yes
   150	// Unfortunate default: yes
   151	//
   152	// Default: true
   153	BoolNonemptyDefault *bool `json:"bool_nonempty_default,omitempty"`
   154	// NumericEmptyDefaultA:
   155	// Nonempty default: no
   156	// Unfortunate default: no
   157	NumericEmptyDefaultA int64 `json:"numeric_empty_default_a,omitempty,string"`
   158	// NumericEmptyDefaultB:
   159	// Nonempty default: no
   160	// Unfortunate default: no
   161	NumericEmptyDefaultB int64 `json:"numeric_empty_default_b,omitempty,string"`
   162	// NumericEmptyDefaultC:
   163	// Nonempty default: no
   164	// Unfortunate default: no
   165	NumericEmptyDefaultC int64 `json:"numeric_empty_default_c,omitempty,string"`
   166	// NumericEmptyDefaultD:
   167	// Nonempty default: no
   168	// Unfortunate default: no
   169	NumericEmptyDefaultD float64 `json:"numeric_empty_default_d,omitempty"`
   170	// NumericEmptyDefaultE:
   171	// Nonempty default: no
   172	// Unfortunate default: no
   173	NumericEmptyDefaultE float64 `json:"numeric_empty_default_e,omitempty"`
   174	// NumericNonemptyDefaultA:
   175	// Nonempty default: yes
   176	// Unfortunate default: yes
   177	// string encoded, so will not be represented as pointer.
   178	//
   179	// Default: 1
   180	NumericNonemptyDefaultA *int64 `json:"numeric_nonempty_default_a,omitempty,string"`
   181	// NumericNonemptyDefaultB:
   182	// Nonempty default: yes
   183	// Unfortunate default: yes
   184	//
   185	// Default: 0.001
   186	NumericNonemptyDefaultB *float64 `json:"numeric_nonempty_default_b,omitempty"`
   187	// StringEmptyDefaultDoesntAcceptEmpty:
   188	// Nonempty default: no
   189	// Accepts empty value: no
   190	// Unfortunate default: no
   191	StringEmptyDefaultDoesntAcceptEmpty string `json:"string_empty_default_doesnt_accept_empty,omitempty"`
   192	// StringEmptyDefaultEnumAcceptsEmpty:
   193	// Nonempty default: no
   194	// Accepts empty value: yes (enum)
   195	// Unfortunate default: no
   196	//
   197	// Possible values:
   198	//   "" (default)
   199	//   "value"
   200	StringEmptyDefaultEnumAcceptsEmpty string `json:"string_empty_default_enum_accepts_empty,omitempty"`
   201	// StringEmptyDefaultEnumDoesntAcceptEmpty:
   202	// Nonempty default: no
   203	// Accepts empty value: no (enum)
   204	// Unfortunate default: no
   205	//
   206	// Possible values:
   207	//   "value"
   208	StringEmptyDefaultEnumDoesntAcceptEmpty string `json:"string_empty_default_enum_doesnt_accept_empty,omitempty"`
   209	// StringEmptyDefaultPatternAcceptsEmpty:
   210	// Nonempty default: no
   211	// Accepts empty value: yes (pattern)
   212	// Unfortunate default: no
   213	StringEmptyDefaultPatternAcceptsEmpty string `json:"string_empty_default_pattern_accepts_empty,omitempty"`
   214	// StringEmptyDefaultPatternDoesntAcceptEmpty:
   215	// Nonempty default: no
   216	// Accepts empty value: no (pattern)
   217	// Unfortunate default: no
   218	StringEmptyDefaultPatternDoesntAcceptEmpty string `json:"string_empty_default_pattern_doesnt_accept_empty,omitempty"`
   219	// StringNonemptyDefaultDoesntAcceptEmpty:
   220	// Nonempty default: yes
   221	// Accepts empty value: no
   222	// Unfortunate default: no
   223	StringNonemptyDefaultDoesntAcceptEmpty string `json:"string_nonempty_default_doesnt_accept_empty,omitempty"`
   224	// StringNonemptyDefaultEnumAcceptsEmpty:
   225	// Nonempty default: yes
   226	// Accepts empty value: yes (enum)
   227	// Unfortunate default: yes
   228	//
   229	// Possible values:
   230	//   ""
   231	//   "nonempty" (default)
   232	//   "aaa"
   233	StringNonemptyDefaultEnumAcceptsEmpty *string `json:"string_nonempty_default_enum_accepts_empty,omitempty"`
   234	// StringNonemptyDefaultEnumDoesntAcceptEmpty:
   235	// Nonempty default: yes
   236	// Accepts empty value: no (enum)
   237	// Unfortunate default: no
   238	//
   239	// Possible values:
   240	//   "nonempty" (default)
   241	//   "aaa"
   242	StringNonemptyDefaultEnumDoesntAcceptEmpty string `json:"string_nonempty_default_enum_doesnt_accept_empty,omitempty"`
   243	// StringNonemptyDefaultPatternAcceptsEmpty:
   244	// Nonempty default: yes
   245	// Accepts empty value: yes (pattern)
   246	// Unfortunate default: yes
   247	//
   248	// Default: nonempty
   249	StringNonemptyDefaultPatternAcceptsEmpty *string `json:"string_nonempty_default_pattern_accepts_empty,omitempty"`
   250	// StringNonemptyDefaultPatternDoesntAcceptEmpty:
   251	// Nonempty default: yes
   252	// Accepts empty value: no (pattern)
   253	// Unfortunate default: no
   254	StringNonemptyDefaultPatternDoesntAcceptEmpty string `json:"string_nonempty_default_pattern_doesnt_accept_empty,omitempty"`
   255	// ForceSendFields is a list of field names (e.g. "BoolEmptyDefaultA") to
   256	// unconditionally include in API requests. By default, fields with empty or
   257	// default values are omitted from API requests. See
   258	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   259	// details.
   260	ForceSendFields []string `json:"-"`
   261	// NullFields is a list of field names (e.g. "BoolEmptyDefaultA") to include in
   262	// API requests with the JSON null value. By default, fields with empty values
   263	// are omitted from API requests. See
   264	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   265	NullFields []string `json:"-"`
   266}
   267
   268func (s *Thing) MarshalJSON() ([]byte, error) {
   269	type NoMethod Thing
   270	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   271}
   272
   273func (s *Thing) UnmarshalJSON(data []byte) error {
   274	type NoMethod Thing
   275	var s1 struct {
   276		NumericEmptyDefaultD    gensupport.JSONFloat64  `json:"numeric_empty_default_d"`
   277		NumericEmptyDefaultE    gensupport.JSONFloat64  `json:"numeric_empty_default_e"`
   278		NumericNonemptyDefaultB *gensupport.JSONFloat64 `json:"numeric_nonempty_default_b"`
   279		*NoMethod
   280	}
   281	s1.NoMethod = (*NoMethod)(s)
   282	if err := json.Unmarshal(data, &s1); err != nil {
   283		return err
   284	}
   285	s.NumericEmptyDefaultD = float64(s1.NumericEmptyDefaultD)
   286	s.NumericEmptyDefaultE = float64(s1.NumericEmptyDefaultE)
   287	if s1.NumericNonemptyDefaultB != nil {
   288		s.NumericNonemptyDefaultB = (*float64)(s1.NumericNonemptyDefaultB)
   289	}
   290	return nil
   291}

View as plain text