Skip to content

Commit

Permalink
fix: set default operation description if empty (#75)
Browse files Browse the repository at this point in the history
closes #60
  • Loading branch information
ipfans committed Mar 31, 2022
1 parent 8ad9884 commit cc49074
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ func (g *Generator) setOperationResponse(op *Operation, t reflect.Type, code, mt
if ci < 100 || ci > 599 {
return fmt.Errorf("response code out of range: %s", code)
}
desc = http.StatusText(ci)
if desc == "" {
desc = http.StatusText(ci)
}
}
}
r := &Response{
Expand Down Expand Up @@ -712,7 +714,7 @@ func (g *Generator) paramLocation(f reflect.StructField, in reflect.Type) (strin
// Count the number of keys that represents
// a parameter location from the tag of the
// struct field.
var parameterLocations = []string{
parameterLocations := []string{
g.config.PathLocationTag,
g.config.QueryLocationTag,
g.config.HeaderLocationTag,
Expand Down
10 changes: 8 additions & 2 deletions openapi/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ func TestSetOperationResponseError(t *testing.T) {
}
err := g.setOperationResponse(op, reflect.TypeOf(new(string)), "200", "application/json", "", nil, nil, nil)
assert.Nil(t, err)
assert.Equal(t, "OK", op.Responses["200"].Description)

err = g.setOperationResponse(op, reflect.TypeOf(new(string)), "429", "application/json", "testDesc", nil, nil, nil)
assert.Nil(t, err)
assert.Equal(t, "testDesc", op.Responses["429"].Description)

// Add another response with same code.
err = g.setOperationResponse(op, reflect.TypeOf(new(int)), "200", "application/xml", "", nil, nil, nil)
Expand Down Expand Up @@ -727,7 +732,8 @@ func TestSetServers(t *testing.T) {
},
Default: "v2",
},
}},
},
},
}
g.SetServers(servers)

Expand Down Expand Up @@ -757,7 +763,7 @@ func (c customTime) ParseExample(v string) (interface{}, error) {

// TestGenerator_parseExampleValue tests the parsing of example values.
func TestGenerator_parseExampleValue(t *testing.T) {
var testCases = []struct {
testCases := []struct {
testName string
typ reflect.Type
inputValue string
Expand Down

0 comments on commit cc49074

Please sign in to comment.