Skip to content

Commit

Permalink
add support for empty response (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubogdan authored Aug 31, 2021
1 parent 0bbefcf commit eef90d0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ var combinedPattern = regexp.MustCompile(`^([\w\-\.\/\[\]]+)\{(.*)\}$`)

func (operation *Operation) parseObjectSchema(refType string, astFile *ast.File) (*spec.Schema, error) {
switch {
case refType == NIL:
return nil, nil
case refType == "interface{}":
return PrimitiveSchema(OBJECT), nil
case IsGolangPrimitiveType(refType):
Expand Down
45 changes: 45 additions & 0 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,51 @@ func TestParseRouterCommentMethodMissingErr(t *testing.T) {
assert.Error(t, err)
}

func TestParseResponseSuccessCommentWithEmptyResponse(t *testing.T) {
t.Parallel()

comment := `@Success 200 {object} nil "An empty response"`
operation := NewOperation(nil)

err := operation.ParseComment(comment, nil)
assert.NoError(t, err)

response := operation.Responses.StatusCodeResponses[200]
assert.Equal(t, `An empty response`, response.Description)

b, _ := json.MarshalIndent(operation, "", " ")
expected := `{
"responses": {
"200": {
"description": "An empty response"
}
}
}`
assert.Equal(t, expected, string(b))

}

func TestParseResponseFailureCommentWithEmptyResponse(t *testing.T) {
t.Parallel()

comment := `@Failure 500 {object} nil`
operation := NewOperation(nil)

err := operation.ParseComment(comment, nil)
assert.NoError(t, err)

b, _ := json.MarshalIndent(operation, "", " ")
expected := `{
"responses": {
"500": {
"description": "Internal Server Error"
}
}
}`
assert.Equal(t, expected, string(b))

}

func TestParseResponseCommentWithObjectType(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 2 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
STRING = "string"
// FUNC func.
FUNC = "func"
// NIL nil
NIL = "nil"
)

// CheckSchemaType checks if typeName is not a name of primitive type.
Expand Down

0 comments on commit eef90d0

Please sign in to comment.