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

863 adding swagger annotation support for enum and nested objects #865

Merged
merged 9 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions examples/browser/a_bit_of_everything_service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('ABitOfEverythingService', function() {
enum_value: "ONE",
path_enum_value: "DEF",
nested_path_enum_value: "JKL",
enum_value_annotation: "ONE",
};

beforeEach(function(done) {
Expand Down
24 changes: 21 additions & 3 deletions examples/clients/abe/a_bit_of_everything_service_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ func NewABitOfEverythingServiceApiWithBasePath(basePath string) *ABitOfEverythin
* @param enumValue
* @param pathEnumValue
* @param nestedPathEnumValue
* @param enumValueAnnotation Numeric enum description.
* @return *ExamplepbABitOfEverything
*/
func (a ABitOfEverythingServiceApi) Create(floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string, enumValue string, pathEnumValue string, nestedPathEnumValue string) (*ExamplepbABitOfEverything, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) Create(floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string, enumValue string, pathEnumValue string, nestedPathEnumValue string, enumValueAnnotation string) (*ExamplepbABitOfEverything, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Post")
// create path and map variables
localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}/{nonConventionalNameValue}/{enum_value}/{path_enum_value}/{nested_path_enum_value}"
localVarPath := a.Configuration.BasePath + "/v1/example/a_bit_of_everything/{float_value}/{double_value}/{int64_value}/separator/{uint64_value}/{int32_value}/{fixed64_value}/{fixed32_value}/{bool_value}/{string_value}/{uint32_value}/{sfixed32_value}/{sfixed64_value}/{sint32_value}/{sint64_value}/{nonConventionalNameValue}/{enum_value}/{path_enum_value}/{nested_path_enum_value}/{enum_value_annotation}"
localVarPath = strings.Replace(localVarPath, "{"+"float_value"+"}", fmt.Sprintf("%v", floatValue), -1)
localVarPath = strings.Replace(localVarPath, "{"+"double_value"+"}", fmt.Sprintf("%v", doubleValue), -1)
localVarPath = strings.Replace(localVarPath, "{"+"int64_value"+"}", fmt.Sprintf("%v", int64Value), -1)
Expand All @@ -85,6 +86,7 @@ func (a ABitOfEverythingServiceApi) Create(floatValue float32, doubleValue float
localVarPath = strings.Replace(localVarPath, "{"+"enum_value"+"}", fmt.Sprintf("%v", enumValue), -1)
localVarPath = strings.Replace(localVarPath, "{"+"path_enum_value"+"}", fmt.Sprintf("%v", pathEnumValue), -1)
localVarPath = strings.Replace(localVarPath, "{"+"nested_path_enum_value"+"}", fmt.Sprintf("%v", nestedPathEnumValue), -1)
localVarPath = strings.Replace(localVarPath, "{"+"enum_value_annotation"+"}", fmt.Sprintf("%v", enumValueAnnotation), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
Expand Down Expand Up @@ -547,9 +549,15 @@ func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body Examplepb
* @param nonConventionalNameValue
* @param timestampValue
* @param repeatedEnumValue repeated enum value. it is comma-separated in query. - ZERO: ZERO means 0 - ONE: ONE means 1
* @param repeatedEnumAnnotation Repeated numeric enum title. Repeated numeric enum description. - ZERO: ZERO means 0 - ONE: ONE means 1
* @param enumValueAnnotation Numeric enum title. Numeric enum description. - ZERO: ZERO means 0 - ONE: ONE means 1
* @param repeatedStringAnnotation Repeated string title. Repeated string description.
* @param nestedAnnotationName name is nested field.
* @param nestedAnnotationAmount
* @param nestedAnnotationOk - FALSE: FALSE is false. - TRUE: TRUE is true.
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) GetQuery(uuid string, floatValue float32, singleNestedName string, singleNestedAmount int64, singleNestedOk string, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, bytesValue string, uint32Value int64, enumValue string, pathEnumValue string, nestedPathEnumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string) (*interface{}, *APIResponse, error) {
func (a ABitOfEverythingServiceApi) GetQuery(uuid string, floatValue float32, singleNestedName string, singleNestedAmount int64, singleNestedOk string, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, bytesValue string, uint32Value int64, enumValue string, pathEnumValue string, nestedPathEnumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string, repeatedEnumAnnotation []string, enumValueAnnotation string, repeatedStringAnnotation []string, nestedAnnotationName string, nestedAnnotationAmount int64, nestedAnnotationOk string) (*interface{}, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand Down Expand Up @@ -596,6 +604,16 @@ func (a ABitOfEverythingServiceApi) GetQuery(uuid string, floatValue float32, si
var repeatedEnumValueCollectionFormat = "csv"
localVarQueryParams.Add("repeated_enum_value", a.Configuration.APIClient.ParameterToString(repeatedEnumValue, repeatedEnumValueCollectionFormat))

var repeatedEnumAnnotationCollectionFormat = "csv"
localVarQueryParams.Add("repeated_enum_annotation", a.Configuration.APIClient.ParameterToString(repeatedEnumAnnotation, repeatedEnumAnnotationCollectionFormat))

localVarQueryParams.Add("enum_value_annotation", a.Configuration.APIClient.ParameterToString(enumValueAnnotation, ""))
var repeatedStringAnnotationCollectionFormat = "csv"
localVarQueryParams.Add("repeated_string_annotation", a.Configuration.APIClient.ParameterToString(repeatedStringAnnotation, repeatedStringAnnotationCollectionFormat))

localVarQueryParams.Add("nested_annotation.name", a.Configuration.APIClient.ParameterToString(nestedAnnotationName, ""))
localVarQueryParams.Add("nested_annotation.amount", a.Configuration.APIClient.ParameterToString(nestedAnnotationAmount, ""))
localVarQueryParams.Add("nested_annotation.ok", a.Configuration.APIClient.ParameterToString(nestedAnnotationOk, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{ "application/json", "application/x-foo-mime", }
Expand Down
15 changes: 15 additions & 0 deletions examples/clients/abe/examplepb_a_bit_of_everything.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,19 @@ type ExamplepbABitOfEverything struct {
TimestampValue time.Time `json:"timestamp_value,omitempty"`

RepeatedEnumValue []ExamplepbNumericEnum `json:"repeated_enum_value,omitempty"`

// Repeated numeric enum description.
RepeatedEnumAnnotation []ExamplepbNumericEnum `json:"repeated_enum_annotation,omitempty"`

// Numeric enum description.
EnumValueAnnotation ExamplepbNumericEnum `json:"enum_value_annotation,omitempty"`

// Repeated string description.
RepeatedStringAnnotation []string `json:"repeated_string_annotation,omitempty"`

// Repeated nested object description.
RepeatedNestedAnnotation []ABitOfEverythingNested `json:"repeated_nested_annotation,omitempty"`

// Nested object description.
NestedAnnotation ABitOfEverythingNested `json:"nested_annotation,omitempty"`
}
2 changes: 2 additions & 0 deletions examples/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
EnumValue: abe.ExamplepbNumericEnum{},
PathEnumValue: abe.PathenumPathEnum{},
NestedPathEnumValue: abe.MessagePathEnumNestedPathEnum{},
EnumValueAnnotation: abe.ExamplepbNumericEnum{},
}
resp, _, err := cl.Create(
want.FloatValue,
Expand All @@ -96,6 +97,7 @@ func testABEClientCreate(t *testing.T, cl *abe.ABitOfEverythingServiceApi) {
want.EnumValue.String(),
want.PathEnumValue.String(),
want.NestedPathEnumValue.String(),
want.EnumValueAnnotation.String(),
)
if err != nil {
t.Errorf("cl.Create(%#v) failed with %v; want success", want, err)
Expand Down
49 changes: 48 additions & 1 deletion examples/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ func testABECreate(t *testing.T, port int) {
EnumValue: gw.NumericEnum_ZERO,
PathEnumValue: pathenum.PathEnum_DEF,
NestedPathEnumValue: pathenum.MessagePathEnum_JKL,
EnumValueAnnotation: gw.NumericEnum_ONE,
}
url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/%f/%f/%d/separator/%d/%d/%d/%d/%v/%s/%d/%d/%d/%d/%d/%s/%s/%s/%s", port, want.FloatValue, want.DoubleValue, want.Int64Value, want.Uint64Value, want.Int32Value, want.Fixed64Value, want.Fixed32Value, want.BoolValue, want.StringValue, want.Uint32Value, want.Sfixed32Value, want.Sfixed64Value, want.Sint32Value, want.Sint64Value, want.NonConventionalNameValue, want.EnumValue, want.PathEnumValue, want.NestedPathEnumValue)
url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/%f/%f/%d/separator/%d/%d/%d/%d/%v/%s/%d/%d/%d/%d/%d/%s/%s/%s/%s/%s", port, want.FloatValue, want.DoubleValue, want.Int64Value, want.Uint64Value, want.Int32Value, want.Fixed64Value, want.Fixed32Value, want.BoolValue, want.StringValue, want.Uint32Value, want.Sfixed32Value, want.Sfixed64Value, want.Sint32Value, want.Sint64Value, want.NonConventionalNameValue, want.EnumValue, want.PathEnumValue, want.NestedPathEnumValue, want.EnumValueAnnotation)

resp, err := http.Post(url, "application/json", strings.NewReader("{}"))
if err != nil {
Expand Down Expand Up @@ -372,6 +373,29 @@ func testABECreateBody(t *testing.T, port int) {
"a": {Name: "x", Amount: 1},
"b": {Name: "y", Amount: 2},
},
RepeatedEnumAnnotation: []gw.NumericEnum{
gw.NumericEnum_ONE,
gw.NumericEnum_ZERO,
},
EnumValueAnnotation: gw.NumericEnum_ONE,
RepeatedStringAnnotation: []string{
"a",
"b",
},
RepeatedNestedAnnotation: []*gw.ABitOfEverything_Nested{
{
Name: "hoge",
Amount: 10,
},
{
Name: "fuga",
Amount: 20,
},
},
NestedAnnotation: &gw.ABitOfEverything_Nested{
Name: "hoge",
Amount: 10,
},
}
url := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything", port)
var m jsonpb.Marshaler
Expand Down Expand Up @@ -453,6 +477,29 @@ func testABEBulkCreate(t *testing.T, port int) {
Amount: 20,
},
},
RepeatedEnumAnnotation: []gw.NumericEnum{
gw.NumericEnum_ONE,
gw.NumericEnum_ZERO,
},
EnumValueAnnotation: gw.NumericEnum_ONE,
RepeatedStringAnnotation: []string{
"a",
"b",
},
RepeatedNestedAnnotation: []*gw.ABitOfEverything_Nested{
{
Name: "hoge",
Amount: 10,
},
{
Name: "fuga",
Amount: 20,
},
},
NestedAnnotation: &gw.ABitOfEverything_Nested{
Name: "hoge",
Amount: 10,
},
}
var m jsonpb.Marshaler
if err := m.Marshal(w, &want); err != nil {
Expand Down
Loading