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 type OpenAPI generation seems not supported #332

Closed
satoufuyuki opened this issue Jan 5, 2025 · 8 comments · Fixed by #338
Closed

Generic type OpenAPI generation seems not supported #332

satoufuyuki opened this issue Jan 5, 2025 · 8 comments · Fixed by #338
Assignees
Labels
bug Something isn't working

Comments

@satoufuyuki
Copy link

satoufuyuki commented Jan 5, 2025

To Reproduce
Steps to reproduce the behavior:

  1. Make a struct that has generic type like this:
type BareSuccessResponse[Res any] struct {
	StatusCode int    `json:"statusCode"`
	Result     Res    `json:"result"`
	Message    string `json:"message"`
}
  1. Use the struct as return type like BareSuccessResponse[ExpectedResultStruct]
  2. Open swagger

Expected behavior
It should generate the proper extended types for the response

Screenshots
image

Framework version (please check if it happens with the last
Fuego version before posting):
0.17.0

Go version (please check if it happens with the last Go version before posting): 1.23.4

Additional context
My current workaround is explicitly specify the response type using OptionAddResponse. But that actually removes the BareSuccessResponse structure.

@satoufuyuki satoufuyuki added the bug Something isn't working label Jan 5, 2025
@EwenQuim
Copy link
Member

EwenQuim commented Jan 5, 2025

Well spotted! It's probably related to the Kin dependency, I'll have a look this week.

@EwenQuim
Copy link
Member

EwenQuim commented Jan 6, 2025

For information, this doesn't impact running code, just OpenAPI description.

@rizerkrof rizerkrof self-assigned this Jan 7, 2025
@EwenQuim
Copy link
Member

EwenQuim commented Jan 7, 2025

@rizerkrof identified it as a regression, it was available on previous versions. It'll be fixed for the next release :)

@rizerkrof
Copy link
Collaborator

rizerkrof commented Jan 7, 2025

@rizerkrof identified it as a regression, it was available on previous versions. It'll be fixed for the next release :)

Yes, regression was introduced by this commit.

@EwenQuim
Copy link
Member

EwenQuim commented Jan 7, 2025

Oops my bad, I'll fix and add a test for generics args to make sure it won't happen again

@EwenQuim
Copy link
Member

EwenQuim commented Jan 8, 2025

I've identified the bug. It seems unrelated to 72a07362.

It seems that the generic names are not supported by OpenAPI specification:

schema \"BareSuccessResponse[github.com/go-fuego/fuego/examples/petstore/models.Pets]\": identifier \"BareSuccessResponse[github.com/go-fuego/fuego/examples/petstore/models.Pets]\" is not supported by OpenAPIv3 standard (charset: [\"a-zA-Z0-9._-\"])"

@ccoVeille @dylanhitt I'll add a function to replace invalid characters and strip module name except last path, are you ok with this?

BareSuccessResponse[github.com/go-fuego/fuego/examples/petstore/models.Pets] -> BareSuccessResponse_models.Pets

@EwenQuim
Copy link
Member

EwenQuim commented Jan 8, 2025

Here's a proof that a simple renaming works

image

@EwenQuim
Copy link
Member

EwenQuim commented Jan 8, 2025

It'll be available in the next release. In the meantime, you can work with the @main version of Fuego instead of the @latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants