Skip to content

Commit

Permalink
Fix malformed Schema Reference during field_behavior generation (#1944)
Browse files Browse the repository at this point in the history
* Fix malformed Schema Reference during field_behavior generation

* remove unnecessary third_party proto files

bump third_part proto files to same revision

* add context for not adding field_behavior if schema is a reference

* correct typo: Referene -> Reference

:facepalm:

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
  • Loading branch information
Gregory Ganley and johanbrandhorst authored Feb 5, 2021
1 parent 69552d6 commit b700e0d
Show file tree
Hide file tree
Showing 13 changed files with 1,360 additions and 642 deletions.
62 changes: 62 additions & 0 deletions examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,68 @@ paths:
description: "An unexpected error response."
schema:
$ref: "#/definitions/rpcStatus"
/v1/{book.name=publishers/*/books/*}:
patch:
tags:
- "ABitOfEverythingService"
operationId: "ABitOfEverythingService_UpdateBook"
parameters:
- name: "book.name"
in: "path"
description: "The resource name of the book.\n\nFormat: `publishers/{publisher}/books/{book}`\n\
\nExample: `publishers/1257894000000000000/books/my-book`"
required: true
type: "string"
x-exportParamName: "BookName"
- in: "body"
name: "body"
description: "The book to update.\n\nThe book's `name` field is used to identify\
\ the book to be updated.\nFormat: publishers/{publisher}/books/{book}"
required: true
schema:
$ref: "#/definitions/examplepbBook"
x-exportParamName: "Body"
- name: "updateMask"
in: "query"
description: "The list of fields to be updated."
required: false
type: "string"
x-exportParamName: "UpdateMask"
x-optionalDataType: "String"
- name: "allowMissing"
in: "query"
description: "If set to true, and the book is not found, a new book will be\
\ created.\nIn this situation, `update_mask` is ignored."
required: false
type: "boolean"
x-exportParamName: "AllowMissing"
x-optionalDataType: "Bool"
responses:
200:
description: "A successful response."
schema:
$ref: "#/definitions/examplepbBook"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
schema: {}
404:
description: "Returned when the resource does not exist."
schema:
type: "string"
format: "string"
418:
description: "I'm a teapot."
schema:
$ref: "#/definitions/examplepbNumericEnum"
500:
description: "Server error"
schema:
$ref: "#/definitions/examplepbErrorResponse"
default:
description: "An unexpected error response."
schema:
$ref: "#/definitions/rpcStatus"
/v1/{parent=publishers/*}/books:
post:
tags:
Expand Down
174 changes: 174 additions & 0 deletions examples/internal/clients/abe/api_a_bit_of_everything_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3785,6 +3785,180 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdate(ctx co
return localVarReturnValue, localVarHttpResponse, nil
}

/*
ABitOfEverythingServiceApiService
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param bookName The resource name of the book. Format: &#x60;publishers/{publisher}/books/{book}&#x60; Example: &#x60;publishers/1257894000000000000/books/my-book&#x60;
* @param body The book to update. The book&#39;s &#x60;name&#x60; field is used to identify the book to be updated. Format: publishers/{publisher}/books/{book}
* @param optional nil or *ABitOfEverythingServiceUpdateBookOpts - Optional Parameters:
* @param "UpdateMask" (optional.String) - The list of fields to be updated.
* @param "AllowMissing" (optional.Bool) - If set to true, and the book is not found, a new book will be created. In this situation, &#x60;update_mask&#x60; is ignored.
@return ExamplepbBook
*/

type ABitOfEverythingServiceUpdateBookOpts struct {
UpdateMask optional.String
AllowMissing optional.Bool
}

func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateBook(ctx context.Context, bookName string, body ExamplepbBook, localVarOptionals *ABitOfEverythingServiceUpdateBookOpts) (ExamplepbBook, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Patch")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
localVarReturnValue ExamplepbBook
)

// create path and map variables
localVarPath := a.client.cfg.BasePath + "/v1/{book.name=publishers/*/books/*}"
localVarPath = strings.Replace(localVarPath, "{"+"book.name"+"}", fmt.Sprintf("%v", bookName), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}

if localVarOptionals != nil && localVarOptionals.UpdateMask.IsSet() {
localVarQueryParams.Add("updateMask", parameterToString(localVarOptionals.UpdateMask.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.AllowMissing.IsSet() {
localVarQueryParams.Add("allowMissing", parameterToString(localVarOptionals.AllowMissing.Value(), ""))
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json", "application/x-foo-mime"}

// set Content-Type header
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHttpContentType
}

// to determine the Accept header
localVarHttpHeaderAccepts := []string{"application/json", "application/x-foo-mime"}

// set Accept header
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
// body params
localVarPostBody = &body
if ctx != nil {
// API Key Authentication
if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
var key string
if auth.Prefix != "" {
key = auth.Prefix + " " + auth.Key
} else {
key = auth.Key
}
localVarHeaderParams["X-API-Key"] = key

}
}
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
return localVarReturnValue, nil, err
}

localVarHttpResponse, err := a.client.callAPI(r)
if err != nil || localVarHttpResponse == nil {
return localVarReturnValue, localVarHttpResponse, err
}

localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
localVarHttpResponse.Body.Close()
if err != nil {
return localVarReturnValue, localVarHttpResponse, err
}

if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
}

if localVarHttpResponse.StatusCode >= 300 {
newErr := GenericSwaggerError{
body: localVarBody,
error: localVarHttpResponse.Status,
}

if localVarHttpResponse.StatusCode == 200 {
var v ExamplepbBook
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}

if localVarHttpResponse.StatusCode == 403 {
var v interface{}
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}

if localVarHttpResponse.StatusCode == 404 {
var v string
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}

if localVarHttpResponse.StatusCode == 418 {
var v ExamplepbNumericEnum
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}

if localVarHttpResponse.StatusCode == 500 {
var v ExamplepbErrorResponse
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}

if localVarHttpResponse.StatusCode == 0 {
var v RpcStatus
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}

return localVarReturnValue, localVarHttpResponse, newErr
}

return localVarReturnValue, localVarHttpResponse, nil
}

/*
ABitOfEverythingServiceApiService
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
Expand Down
Loading

0 comments on commit b700e0d

Please sign in to comment.