-
Notifications
You must be signed in to change notification settings - Fork 73
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
Definition builder fails reference on generic struct #109
Comments
Thank you for reporting this issue.
It is the first time I learn about someone using generics with this pkg. I
will try to come up with a solution.
On Thu, 20 Jul 2023 at 01:12, tlyons-cs ***@***.***> wrote:
Given a struct created with generics the swagger doc compiles correctly
but will fail to reference the definition correctly.
Example:
type Response[T any] struct{
MetaData MetaData `json:"meta"`
Objects []T `json:"objects"
}
type MyObject struct{
Foo string `json:"foo"`
Bar int `json:"bar"`
}
Passing in a variable of type module.Response[module.MyObject]{} will
yield a definition for module.Response[module.MyObject] as well as
module.MyObject. But the reference to this definition will use the key
#/definitions/module.Response%5Bmodule.MyObject%5D.
The proposed change would be to sanitize the definition keys to be [->%5B
and ] ->%5D
—
Reply to this email directly, view it on GitHub
<#109>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFHRDGZ2TTBK54EDY6NU6LXRBSXDANCNFSM6AAAAAA2QTGDIU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Met vriendelijke groet, Kind regards,
Ernest Micklei
Try out my music project Melrōse <https://melrōse.org>
|
@emicklei Example:
build swagger doc result:
Swagger UI ERROR INFO:
FIX:
can I submit a PR to fix it, and modify the corresponding content when the keyFrom() is parsed. |
thank you for reporting this. Yes, please help get this fixed so that generics are supported too. |
I found that in the library, I can resolve this by customizing the ModelTypeNameHandler method. This is how I addressed it.
The generated swag documents are as follows
|
Given a struct created with generics the swagger doc compiles correctly but will fail to reference the definition correctly.
Example:
Passing in a variable of type
module.Response[module.MyObject]{}
will yield a definition formodule.Response[module.MyObject]
as well asmodule.MyObject
. But the reference to this definition will use the key#/definitions/module.Response%5Bmodule.MyObject%5D
.The proposed change would be to sanitize the definition keys to be
[
->%5B
and]
->%5D
The text was updated successfully, but these errors were encountered: