Skip to content

Commit 52b7bf6

Browse files
authored
Fix path params being in the body (#2078)
* Fix path params being in the body * Return an error when trying to add an empty body * Change the example of a bit of everything * Reverted changes to allow empty body with post again
1 parent 7db4bb7 commit 52b7bf6

File tree

12 files changed

+1177
-667
lines changed

12 files changed

+1177
-667
lines changed

examples/internal/clients/abe/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go_library(
1111
"client.go",
1212
"configuration.go",
1313
"enum_helper.go",
14+
"model_a_bit_of_everything.go",
1415
"model_a_bit_of_everything_nested.go",
1516
"model_examplepb_a_bit_of_everything.go",
1617
"model_examplepb_a_bit_of_everything_repeated.go",

examples/internal/clients/abe/api/swagger.yaml

Lines changed: 148 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ paths:
15911591
name: "body"
15921592
required: true
15931593
schema:
1594-
$ref: "#/definitions/examplepbABitOfEverything"
1594+
$ref: "#/definitions/A bit of everything"
15951595
x-exportParamName: "Body"
15961596
responses:
15971597
200:
@@ -2353,7 +2353,7 @@ paths:
23532353
name: "body"
23542354
required: true
23552355
schema:
2356-
$ref: "#/definitions/examplepbBody"
2356+
type: "object"
23572357
x-exportParamName: "Body"
23582358
responses:
23592359
200:
@@ -2731,7 +2731,8 @@ definitions:
27312731
description: "Intentionaly complicated message type to cover many features of\
27322732
\ Protobuf."
27332733
example:
2734-
uuid: "0cf361e1-4b44-483d-a159-54dabdf7e814"
2734+
int64_value: 12
2735+
double_value: 12.3
27352736
examplepbABitOfEverythingRepeated:
27362737
type: "object"
27372738
properties:
@@ -3013,6 +3014,150 @@ definitions:
30133014
properties:
30143015
value:
30153016
type: "string"
3017+
A bit of everything:
3018+
type: "object"
3019+
required:
3020+
- "doubleValue"
3021+
- "floatValue"
3022+
- "int64Value"
3023+
- "requiredStringViaFieldBehaviorAnnotation"
3024+
properties:
3025+
singleNested:
3026+
$ref: "#/definitions/ABitOfEverythingNested"
3027+
nested:
3028+
type: "array"
3029+
items:
3030+
$ref: "#/definitions/ABitOfEverythingNested"
3031+
floatValue:
3032+
type: "number"
3033+
format: "float"
3034+
description: "Float value field"
3035+
default: 0.2
3036+
doubleValue:
3037+
type: "number"
3038+
format: "double"
3039+
int64Value:
3040+
type: "string"
3041+
format: "int64"
3042+
uint64Value:
3043+
type: "string"
3044+
format: "uint64"
3045+
int32Value:
3046+
type: "integer"
3047+
format: "int32"
3048+
fixed64Value:
3049+
type: "string"
3050+
format: "uint64"
3051+
fixed32Value:
3052+
type: "integer"
3053+
format: "int64"
3054+
boolValue:
3055+
type: "boolean"
3056+
stringValue:
3057+
type: "string"
3058+
bytesValue:
3059+
type: "string"
3060+
format: "byte"
3061+
pattern: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
3062+
uint32Value:
3063+
type: "integer"
3064+
format: "int64"
3065+
enumValue:
3066+
$ref: "#/definitions/examplepbNumericEnum"
3067+
pathEnumValue:
3068+
$ref: "#/definitions/pathenumPathEnum"
3069+
nestedPathEnumValue:
3070+
$ref: "#/definitions/MessagePathEnumNestedPathEnum"
3071+
sfixed32Value:
3072+
type: "integer"
3073+
format: "int32"
3074+
sfixed64Value:
3075+
type: "string"
3076+
format: "int64"
3077+
sint32Value:
3078+
type: "integer"
3079+
format: "int32"
3080+
sint64Value:
3081+
type: "string"
3082+
format: "int64"
3083+
repeatedStringValue:
3084+
type: "array"
3085+
items:
3086+
type: "string"
3087+
oneofEmpty:
3088+
type: "object"
3089+
properties: {}
3090+
oneofString:
3091+
type: "string"
3092+
mapValue:
3093+
type: "object"
3094+
additionalProperties:
3095+
$ref: "#/definitions/examplepbNumericEnum"
3096+
mappedStringValue:
3097+
type: "object"
3098+
additionalProperties:
3099+
type: "string"
3100+
mappedNestedValue:
3101+
type: "object"
3102+
additionalProperties:
3103+
$ref: "#/definitions/ABitOfEverythingNested"
3104+
nonConventionalNameValue:
3105+
type: "string"
3106+
timestampValue:
3107+
type: "string"
3108+
format: "date-time"
3109+
repeatedEnumValue:
3110+
type: "array"
3111+
title: "repeated enum value. it is comma-separated in query"
3112+
items:
3113+
$ref: "#/definitions/examplepbNumericEnum"
3114+
repeatedEnumAnnotation:
3115+
type: "array"
3116+
description: "Repeated numeric enum description."
3117+
title: "Repeated numeric enum title"
3118+
items:
3119+
$ref: "#/definitions/examplepbNumericEnum"
3120+
enumValueAnnotation:
3121+
description: "Numeric enum description."
3122+
title: "Numeric enum title"
3123+
$ref: "#/definitions/examplepbNumericEnum"
3124+
repeatedStringAnnotation:
3125+
type: "array"
3126+
description: "Repeated string description."
3127+
title: "Repeated string title"
3128+
items:
3129+
type: "string"
3130+
repeatedNestedAnnotation:
3131+
type: "array"
3132+
description: "Repeated nested object description."
3133+
title: "Repeated nested object title"
3134+
items:
3135+
$ref: "#/definitions/ABitOfEverythingNested"
3136+
nestedAnnotation:
3137+
description: "Nested object description."
3138+
title: "Nested object title"
3139+
$ref: "#/definitions/ABitOfEverythingNested"
3140+
int64OverrideType:
3141+
type: "integer"
3142+
format: "int64"
3143+
requiredStringViaFieldBehaviorAnnotation:
3144+
type: "string"
3145+
title: "mark a field as required in Open API definition"
3146+
outputOnlyStringViaFieldBehaviorAnnotation:
3147+
type: "string"
3148+
title: "mark a field as readonly in Open API definition"
3149+
readOnly: true
3150+
optionalStringValue:
3151+
type: "string"
3152+
externalDocs:
3153+
description: "Find out more about ABitOfEverything"
3154+
url: "https://github.com/grpc-ecosystem/grpc-gateway"
3155+
title: "A bit of everything"
3156+
description: "Intentionaly complicated message type to cover many features of\
3157+
\ Protobuf."
3158+
example:
3159+
int64_value: 12
3160+
double_value: 12.3
30163161
externalDocs:
30173162
description: "More about gRPC-Gateway"
30183163
url: "https://github.com/grpc-ecosystem/grpc-gateway"

examples/internal/clients/abe/api_a_bit_of_everything_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,7 +3341,7 @@ ABitOfEverythingServiceApiService
33413341
33423342
@return interface{}
33433343
*/
3344-
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServicePostWithEmptyBody(ctx context.Context, name string, body ExamplepbBody) (interface{}, *http.Response, error) {
3344+
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServicePostWithEmptyBody(ctx context.Context, name string, body interface{}) (interface{}, *http.Response, error) {
33453345
var (
33463346
localVarHttpMethod = strings.ToUpper("Post")
33473347
localVarPostBody interface{}
@@ -3654,7 +3654,7 @@ ABitOfEverythingServiceApiService
36543654
36553655
@return interface{}
36563656
*/
3657-
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdate(ctx context.Context, uuid string, body ExamplepbABitOfEverything) (interface{}, *http.Response, error) {
3657+
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdate(ctx context.Context, uuid string, body ABitOfEverything) (interface{}, *http.Response, error) {
36583658
var (
36593659
localVarHttpMethod = strings.ToUpper("Put")
36603660
localVarPostBody interface{}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* A Bit of Everything
3+
*
4+
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5+
*
6+
* API version: 1.0
7+
* Contact: [email protected]
8+
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
9+
*/
10+
11+
package abe
12+
13+
import (
14+
"time"
15+
)
16+
17+
// Intentionaly complicated message type to cover many features of Protobuf.
18+
type ABitOfEverything struct {
19+
SingleNested *ABitOfEverythingNested `json:"singleNested,omitempty"`
20+
Nested []ABitOfEverythingNested `json:"nested,omitempty"`
21+
// Float value field
22+
FloatValue float32 `json:"floatValue"`
23+
DoubleValue float64 `json:"doubleValue"`
24+
Int64Value string `json:"int64Value"`
25+
Uint64Value string `json:"uint64Value,omitempty"`
26+
Int32Value int32 `json:"int32Value,omitempty"`
27+
Fixed64Value string `json:"fixed64Value,omitempty"`
28+
Fixed32Value int64 `json:"fixed32Value,omitempty"`
29+
BoolValue bool `json:"boolValue,omitempty"`
30+
StringValue string `json:"stringValue,omitempty"`
31+
BytesValue string `json:"bytesValue,omitempty"`
32+
Uint32Value int64 `json:"uint32Value,omitempty"`
33+
EnumValue *ExamplepbNumericEnum `json:"enumValue,omitempty"`
34+
PathEnumValue *PathenumPathEnum `json:"pathEnumValue,omitempty"`
35+
NestedPathEnumValue *MessagePathEnumNestedPathEnum `json:"nestedPathEnumValue,omitempty"`
36+
Sfixed32Value int32 `json:"sfixed32Value,omitempty"`
37+
Sfixed64Value string `json:"sfixed64Value,omitempty"`
38+
Sint32Value int32 `json:"sint32Value,omitempty"`
39+
Sint64Value string `json:"sint64Value,omitempty"`
40+
RepeatedStringValue []string `json:"repeatedStringValue,omitempty"`
41+
OneofEmpty *interface{} `json:"oneofEmpty,omitempty"`
42+
OneofString string `json:"oneofString,omitempty"`
43+
MapValue map[string]ExamplepbNumericEnum `json:"mapValue,omitempty"`
44+
MappedStringValue map[string]string `json:"mappedStringValue,omitempty"`
45+
MappedNestedValue map[string]ABitOfEverythingNested `json:"mappedNestedValue,omitempty"`
46+
NonConventionalNameValue string `json:"nonConventionalNameValue,omitempty"`
47+
TimestampValue time.Time `json:"timestampValue,omitempty"`
48+
RepeatedEnumValue []ExamplepbNumericEnum `json:"repeatedEnumValue,omitempty"`
49+
// Repeated numeric enum description.
50+
RepeatedEnumAnnotation []ExamplepbNumericEnum `json:"repeatedEnumAnnotation,omitempty"`
51+
// Numeric enum description.
52+
EnumValueAnnotation *ExamplepbNumericEnum `json:"enumValueAnnotation,omitempty"`
53+
// Repeated string description.
54+
RepeatedStringAnnotation []string `json:"repeatedStringAnnotation,omitempty"`
55+
// Repeated nested object description.
56+
RepeatedNestedAnnotation []ABitOfEverythingNested `json:"repeatedNestedAnnotation,omitempty"`
57+
// Nested object description.
58+
NestedAnnotation *ABitOfEverythingNested `json:"nestedAnnotation,omitempty"`
59+
Int64OverrideType int64 `json:"int64OverrideType,omitempty"`
60+
RequiredStringViaFieldBehaviorAnnotation string `json:"requiredStringViaFieldBehaviorAnnotation"`
61+
OutputOnlyStringViaFieldBehaviorAnnotation string `json:"outputOnlyStringViaFieldBehaviorAnnotation,omitempty"`
62+
OptionalStringValue string `json:"optionalStringValue,omitempty"`
63+
}

0 commit comments

Comments
 (0)