Skip to content

Commit

Permalink
fix: required properties of message type are required in OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
gostajonasson committed Oct 13, 2022
1 parent 6b2cf62 commit 61a3894
Show file tree
Hide file tree
Showing 20 changed files with 1,335 additions and 723 deletions.
3 changes: 3 additions & 0 deletions examples/internal/clients/abe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ go_library(
"model_book.go",
"model_examplepb_a_bit_of_everything.go",
"model_examplepb_a_bit_of_everything_repeated.go",
"model_examplepb_bar.go",
"model_examplepb_body.go",
"model_examplepb_book.go",
"model_examplepb_check_status_response.go",
"model_examplepb_error_object.go",
"model_examplepb_error_response.go",
"model_examplepb_foo.go",
"model_examplepb_numeric_enum.go",
"model_examplepb_required_message_type_request.go",
"model_examplepb_snake_enum_response.go",
"model_examplepbsnake_case_0_enum.go",
"model_examplepbsnake_case_enum.go",
Expand Down
89 changes: 63 additions & 26 deletions examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3754,6 +3754,44 @@ paths:
description: "An unexpected error response."
schema:
$ref: "#/definitions/rpcStatus"
/v1/example/requiredmessagetype:
post:
tags:
- "ABitOfEverythingService"
operationId: "ABitOfEverythingService_PostRequiredMessageType"
parameters:
- in: "body"
name: "body"
required: true
schema:
$ref: "#/definitions/examplepbRequiredMessageTypeRequest"
x-exportParamName: "Body"
responses:
200:
description: "A successful response."
schema:
type: "object"
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/example/snake/{who}/{what}/{where}:
get:
tags:
Expand Down Expand Up @@ -4505,7 +4543,6 @@ definitions:
type: "integer"
format: "int64"
ok:
description: "DeepEnum description."
$ref: "#/definitions/NestedDeepEnum"
description: "Nested is nested type."
example:
Expand Down Expand Up @@ -4638,8 +4675,6 @@ definitions:
items:
$ref: "#/definitions/examplepbNumericEnum"
enumValueAnnotation:
description: "Numeric enum description."
title: "Numeric enum title"
$ref: "#/definitions/examplepbNumericEnum"
repeatedStringAnnotation:
type: "array"
Expand All @@ -4654,8 +4689,6 @@ definitions:
items:
$ref: "#/definitions/ABitOfEverythingNested"
nestedAnnotation:
description: "Nested object description."
title: "Nested object title"
$ref: "#/definitions/ABitOfEverythingNested"
int64OverrideType:
type: "integer"
Expand Down Expand Up @@ -4794,6 +4827,13 @@ definitions:
- 1
- 2
- 3
examplepbBar:
type: "object"
required:
- "id"
properties:
id:
type: "string"
examplepbBody:
type: "object"
properties:
Expand Down Expand Up @@ -4858,6 +4898,13 @@ definitions:
pattern: "^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$"
error:
$ref: "#/definitions/examplepbErrorObject"
examplepbFoo:
type: "object"
required:
- "bar"
properties:
bar:
$ref: "#/definitions/examplepbBar"
examplepbNumericEnum:
type: "string"
description: "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE\
Expand All @@ -4866,6 +4913,17 @@ definitions:
- "ZERO"
- "ONE"
default: "ZERO"
examplepbRequiredMessageTypeRequest:
type: "object"
required:
- "foo"
- "id"
properties:
id:
type: "string"
foo:
$ref: "#/definitions/examplepbFoo"
title: "Required message type -> OpenAPI\nhttps://github.com/grpc-ecosystem/grpc-gateway/issues/2837"
examplepbSnakeEnumResponse:
type: "object"
examplepbsnake_case_0_enum:
Expand Down Expand Up @@ -5108,8 +5166,6 @@ definitions:
items:
$ref: "#/definitions/examplepbNumericEnum"
enumValueAnnotation:
description: "Numeric enum description."
title: "Numeric enum title"
$ref: "#/definitions/examplepbNumericEnum"
repeatedStringAnnotation:
type: "array"
Expand All @@ -5124,8 +5180,6 @@ definitions:
items:
$ref: "#/definitions/ABitOfEverythingNested"
nestedAnnotation:
description: "Nested object description."
title: "Nested object title"
$ref: "#/definitions/ABitOfEverythingNested"
int64OverrideType:
type: "integer"
Expand Down Expand Up @@ -5177,7 +5231,6 @@ definitions:
type: "integer"
format: "int64"
ok:
description: "DeepEnum description."
$ref: "#/definitions/NestedDeepEnum"
description: "Nested is nested type."
example: "{\"ok\":\"TRUE\"}"
Expand Down Expand Up @@ -5295,8 +5348,6 @@ definitions:
items:
$ref: "#/definitions/examplepbNumericEnum"
enumValueAnnotation:
description: "Numeric enum description."
title: "Numeric enum title"
$ref: "#/definitions/examplepbNumericEnum"
repeatedStringAnnotation:
type: "array"
Expand All @@ -5311,8 +5362,6 @@ definitions:
items:
$ref: "#/definitions/ABitOfEverythingNested"
nestedAnnotation:
description: "Nested object description."
title: "Nested object title"
$ref: "#/definitions/ABitOfEverythingNested"
int64OverrideType:
type: "integer"
Expand Down Expand Up @@ -5481,8 +5530,6 @@ definitions:
items:
$ref: "#/definitions/examplepbNumericEnum"
enumValueAnnotation:
description: "Numeric enum description."
title: "Numeric enum title"
$ref: "#/definitions/examplepbNumericEnum"
repeatedStringAnnotation:
type: "array"
Expand All @@ -5497,8 +5544,6 @@ definitions:
items:
$ref: "#/definitions/ABitOfEverythingNested"
nestedAnnotation:
description: "Nested object description."
title: "Nested object title"
$ref: "#/definitions/ABitOfEverythingNested"
int64OverrideType:
type: "integer"
Expand Down Expand Up @@ -5652,8 +5697,6 @@ definitions:
items:
$ref: "#/definitions/examplepbNumericEnum"
enumValueAnnotation:
description: "Numeric enum description."
title: "Numeric enum title"
$ref: "#/definitions/examplepbNumericEnum"
repeatedStringAnnotation:
type: "array"
Expand All @@ -5668,8 +5711,6 @@ definitions:
items:
$ref: "#/definitions/ABitOfEverythingNested"
nestedAnnotation:
description: "Nested object description."
title: "Nested object title"
$ref: "#/definitions/ABitOfEverythingNested"
int64OverrideType:
type: "integer"
Expand Down Expand Up @@ -5813,8 +5854,6 @@ definitions:
items:
$ref: "#/definitions/examplepbNumericEnum"
enumValueAnnotation:
description: "Numeric enum description."
title: "Numeric enum title"
$ref: "#/definitions/examplepbNumericEnum"
repeatedStringAnnotation:
type: "array"
Expand All @@ -5829,8 +5868,6 @@ definitions:
items:
$ref: "#/definitions/ABitOfEverythingNested"
nestedAnnotation:
description: "Nested object description."
title: "Nested object title"
$ref: "#/definitions/ABitOfEverythingNested"
int64OverrideType:
type: "integer"
Expand Down
157 changes: 157 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 @@ -5092,6 +5092,163 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServicePostOneofEnum
return localVarReturnValue, localVarHttpResponse, nil
}

/*
ABitOfEverythingServiceApiService
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param body
@return interface{}
*/
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServicePostRequiredMessageType(ctx context.Context, body ExamplepbRequiredMessageTypeRequest) (interface{}, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Post")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
localVarReturnValue interface{}
)

// create path and map variables
localVarPath := a.client.cfg.BasePath + "/v1/example/requiredmessagetype"

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

// 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 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 == 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 61a3894

Please sign in to comment.