Skip to content

Commit

Permalink
fix: ref objects cannot have nullable property
Browse files Browse the repository at this point in the history
  • Loading branch information
denouche committed Oct 12, 2020
1 parent 7751ca1 commit b8b3c4d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docparser/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *composedSchema) SetCustomName(customName string) {

type schema struct {
metadata `yaml:"-"`
Nullable bool `yaml:"nullable,omitempty"`
Nullable *bool `yaml:"nullable,omitempty"`
Required []string `yaml:"required,omitempty"`
Type string `yaml:",omitempty"`
Items map[string]interface{} `yaml:",omitempty"`
Expand Down
6 changes: 5 additions & 1 deletion docparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func parseNamedType(gofile *ast.File, expr ast.Expr, sel *ast.Ident) (*schema, e
if err != nil {
return nil, err
}
t.Nullable = true
if t.Ref == "" {
// if ref, cannot have other properties
tBool := true
t.Nullable = &tBool
}
return t, nil
case *ast.ArrayType: // slice type
cp, err := parseNamedType(gofile, ftpe.Elt, sel)
Expand Down
3 changes: 2 additions & 1 deletion docparser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestParseFile(t *testing.T) {
}

func TestParseNamedType(t *testing.T) {
tBool := true
testCases := []parseNamedTypeTestCase{
{
description: "Should parse *ast.Ident with unknown name",
Expand All @@ -107,7 +108,7 @@ func TestParseNamedType(t *testing.T) {
{
description: "Should parse *ast.StarExpr and set Nullable",
expr: &ast.StarExpr{X: &ast.Ident{Name: "time"}},
expectedSchema: &schema{Type: "string", Format: "date-time", Nullable: true},
expectedSchema: &schema{Type: "string", Format: "date-time", Nullable: &tBool},
},
{
description: "Should parse *ast.ArrayType with known type",
Expand Down

0 comments on commit b8b3c4d

Please sign in to comment.