Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Fields does not handle Arrays in the .swaggo file #1318

Closed
johan-lejdung opened this issue Sep 6, 2022 · 3 comments
Closed

Generic Fields does not handle Arrays in the .swaggo file #1318

johan-lejdung opened this issue Sep 6, 2022 · 3 comments

Comments

@johan-lejdung
Copy link

Describe the bug
Generic fields containing arrays are not replaceable with a .swaggo file even after #1311

To Reproduce
Have a look at the following repo https://github.com/chaintraced/swaggo-issue-repo
On the main branch's latest commit you will see that it is not working as intended.

It's outputting

2022/09/06 14:50:40 Using overrides from .swaggo
2022/09/06 14:50:40 Generate swagger docs....
2022/09/06 14:50:40 Generate general API Info, search dir:./
2022/09/06 14:50:40 Generating movie.CreateMovie
2022/09/06 14:50:40 Override detected for field.Field[actor.Actor]: using actor.Actor instead
2022/09/06 14:50:40 Generating actor.Actor
2022/09/06 14:50:40 Override detected for field.Field[[]actor.Actor]: using []actor.Actor instead
2022/09/06 14:50:40 ParseComment error in file /Users/chaintraced/localdev/swaggo-issue-repo/main.go :cannot find type definition: []actor.Actor

You can see that it's not able to handle array replacements in the .swaggo file where the overrides look like this:

replace field.Field[Person] Person
replace field.Field[[]Person] []Person
replace field.Field[actor.Actor] actor.Actor
replace field.Field[[]actor.Actor] []actor.Actor

Expected behavior
I expect the generic field to be properly replaced

Your swag version
I forked the repo to be able to release a version including the latest generic code changes https://github.com/chaintraced/swag

Your go version
e.g. 1.18.0

@johan-lejdung
Copy link
Author

johan-lejdung commented Sep 6, 2022

@FabianMartin You must be hating me by this point 😂, but this seems adjacent to the fixes you already provided and I though you might be interested in this

@Vishvajeet590
Copy link

Vishvajeet590 commented Sep 6, 2022

replace pq.StringArray []string

this also not working in .swaggo.
Error :

:cannot find type definition: []string

@johan-lejdung
Copy link
Author

Seems it might not be limited to generics in that case 👍

FabianMartin added a commit to FabianMartin/swag that referenced this issue Sep 12, 2022
- Detect array type and transform schema into spec.ArrayProperty if needed

fixes swaggo#1318, swaggo#1320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants