You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to get deep models working? Right now if I have a struct inside another struct, it doesn't recognize the top struct. Similarly bool (type bool) isn't recognized either.
@easonlin404 so I guess I found the issue. In the parser.go:186 you range over the types which have been registered in any route, but not their properties. This means, you don't get the depth, but only the directly referenced classes of the api.
I would solve it by adding a recursive check in parser.go:194 to generate the definitions of the types being used in the referenced model. (see pull request #42)
Problems I encountered:
the package of the nested type must be the same as the owning type -- otherwise exception during parsing. Cross-package model nesting doesn't work
typeTagstruct {
IDstringNamestringTemplateTagTemplateLabelTypeLabelTypeLabel2Type models2.Label2Type// doesn't work
}
getting the models to be generated didn't resolve the referencing issue on the "Example Value | Model" section. Turns out swagger needs to know where to look for them ($ref was missing in the definitions section)
That's it. Models from the same package now get resolved.
Limitation:
Array of structs still not supported
Cross-package models are causing the exception above
@nadilas thank you sorted out the problem and to add supported for cross-package models.
I will add 'Limitation' section to get better understand how to use it. Thanks your contribution. 💯
@easonlin404 how about case with nested struct ?
here is my struct :
type Address struct {
City string `json:"city,omitempty"`
State string `json:"state,omitempty"`
}
// The person Type (more like an object)
type Person struct {
ID string `json:"id,omitempty"`
Firstname string `json:"firstname,omitempty"`
Lastname string `json:"lastname,omitempty"`
Address *Address `json:"address,omitempty"`
}
when i tried to use swag init command, i get this error :
Activity
easonlin404 commentedon Feb 3, 2018
@Sayujya you mean Nested structs (a struct inside another struct) or or Promoted fields ?
Nested structs:
Promoted fields:
Can you post your example?
easonlin404 commentedon Feb 4, 2018
@Sayujya we add support for anonymous fields(promoted fields).#40
Sayujya commentedon Feb 5, 2018
How do you specify that? I just get this
easonlin404 commentedon Feb 15, 2018
@Sayujya where is your type
Userdeclared ?nadilas commentedon Feb 16, 2018
@Sayujya don't you mean like:
I'm facing a similar issue, where the type declared above its usage doesn't get recognized.
easonlin404 commentedon Feb 17, 2018
@nadilas can you post your declarative comments? I can't reproduce this issue.
nadilas commentedon Feb 17, 2018
Sure:
And the result:
easonlin404 commentedon Feb 17, 2018
@nadilas I have created https://github.com/easonlin404/swag-issue using above declarative comments. Can you help to figure out?
nadilas commentedon Feb 18, 2018
@easonlin404 so I guess I found the issue. In the
parser.go:186you range over the types which have been registered in any route, but not their properties. This means, you don't get the depth, but only the directly referenced classes of the api.I would solve it by adding a recursive check in
parser.go:194to generate the definitions of the types being used in the referenced model. (see pull request #42)Problems I encountered:
That's it. Models from the same package now get resolved.
Limitation:
easonlin404 commentedon Feb 19, 2018
@nadilas thank you sorted out the problem and to add supported for cross-package models.
I will add 'Limitation' section to get better understand how to use it. Thanks your contribution. 💯
easonlin404 commentedon Feb 19, 2018
fix via #42
hotarufk commentedon May 30, 2018
@easonlin404 how about case with nested struct ?
here is my struct :
when i tried to use swag init command, i get this error :

pei0804 commentedon Jul 22, 2018
I fix.
#171
Merge pull request swaggo#39 from alexandear/fix-typos-in-comments