Skip to content

Commit

Permalink
Fix recursive types (#1764) (#1765) (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
konstlepa authored and raphael committed Jun 23, 2018
1 parent d816e93 commit 6600bd7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 15 additions & 4 deletions design/types.go
Expand Up @@ -602,26 +602,37 @@ func UserTypes(dt DataType) map[string]*UserTypeDefinition {

// HasFile returns true if the underlying type has any file attributes.
func HasFile(dt DataType) bool {
return hasFile(dt, nil)
}

func hasFile(dt DataType, traversed []DataType) bool {
if dt == nil {
return false
}
for _, v := range traversed {
if dt == v {
return false
}
}
traversed = append(traversed, dt)

switch {
case dt.IsPrimitive():
return dt.Kind() == FileKind
case dt.IsArray():
if HasFile(dt.ToArray().ElemType.Type) {
if hasFile(dt.ToArray().ElemType.Type, traversed) {
return true
}
case dt.IsHash():
if HasFile(dt.ToHash().KeyType.Type) {
if hasFile(dt.ToHash().KeyType.Type, traversed) {
return true
}
if HasFile(dt.ToHash().ElemType.Type) {
if hasFile(dt.ToHash().ElemType.Type, traversed) {
return true
}
case dt.IsObject():
for _, att := range dt.ToObject() {
if HasFile(att.Type) {
if hasFile(att.Type, traversed) {
return true
}
}
Expand Down
18 changes: 18 additions & 0 deletions goagen/gen_swagger/swagger_test.go
Expand Up @@ -330,6 +330,24 @@ var _ = Describe("New", func() {
It("serializes into valid swagger JSON", func() { validateSwagger(swagger) })
})

Context("with recursive payload", func() {
BeforeEach(func() {
p := Type("RecursivePayload", func() {
Member("m1", "RecursivePayload")
})
Resource("res", func() {
Action("act", func() {
Routing(
PUT("/"),
)
Payload(p)
})
})
})

It("serializes into valid swagger JSON", func() { validateSwagger(swagger) })
})

Context("with zero value validations", func() {
const (
intParam = "intParam"
Expand Down

0 comments on commit 6600bd7

Please sign in to comment.