Skip to content

Commit cc49074

Browse files
authored
fix: set default operation description if empty (#75)
closes #60
1 parent 8ad9884 commit cc49074

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

openapi/generator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ func (g *Generator) setOperationResponse(op *Operation, t reflect.Type, code, mt
379379
if ci < 100 || ci > 599 {
380380
return fmt.Errorf("response code out of range: %s", code)
381381
}
382-
desc = http.StatusText(ci)
382+
if desc == "" {
383+
desc = http.StatusText(ci)
384+
}
383385
}
384386
}
385387
r := &Response{
@@ -712,7 +714,7 @@ func (g *Generator) paramLocation(f reflect.StructField, in reflect.Type) (strin
712714
// Count the number of keys that represents
713715
// a parameter location from the tag of the
714716
// struct field.
715-
var parameterLocations = []string{
717+
parameterLocations := []string{
716718
g.config.PathLocationTag,
717719
g.config.QueryLocationTag,
718720
g.config.HeaderLocationTag,

openapi/generator_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ func TestSetOperationResponseError(t *testing.T) {
571571
}
572572
err := g.setOperationResponse(op, reflect.TypeOf(new(string)), "200", "application/json", "", nil, nil, nil)
573573
assert.Nil(t, err)
574+
assert.Equal(t, "OK", op.Responses["200"].Description)
575+
576+
err = g.setOperationResponse(op, reflect.TypeOf(new(string)), "429", "application/json", "testDesc", nil, nil, nil)
577+
assert.Nil(t, err)
578+
assert.Equal(t, "testDesc", op.Responses["429"].Description)
574579

575580
// Add another response with same code.
576581
err = g.setOperationResponse(op, reflect.TypeOf(new(int)), "200", "application/xml", "", nil, nil, nil)
@@ -727,7 +732,8 @@ func TestSetServers(t *testing.T) {
727732
},
728733
Default: "v2",
729734
},
730-
}},
735+
},
736+
},
731737
}
732738
g.SetServers(servers)
733739

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

758764
// TestGenerator_parseExampleValue tests the parsing of example values.
759765
func TestGenerator_parseExampleValue(t *testing.T) {
760-
var testCases = []struct {
766+
testCases := []struct {
761767
testName string
762768
typ reflect.Type
763769
inputValue string

0 commit comments

Comments
 (0)