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

any type (generics) #2809

Closed
kbakdev opened this issue Aug 8, 2022 · 8 comments · Fixed by #2808
Closed

any type (generics) #2809

kbakdev opened this issue Aug 8, 2022 · 8 comments · Fixed by #2808

Comments

@kbakdev
Copy link

kbakdev commented Aug 8, 2022

Does swagger will support any type from generics?

@youyuanwu
Copy link
Member

For what use case? example?

@kbakdev
Copy link
Author

kbakdev commented Aug 9, 2022

If, for example, we can get a variety of data from a response, a wrapper that can wrap all such data would be useful. This can replace interface{}, for example, and work better.

Example:

// swagger:model transportErr
type transportErr struct {
   // Message is a human-readable description of the error.
   // Required: true
   Message string `json:"message"`
   // Data is additional data about the error.
   Data any `json:"data,omitempty"` // <- for this use case. Unsupported type "invalid type"
}

@youyuanwu
Copy link
Member

I thought any is an alias for interface{}. Are you asking us to replace interface{} by any in all code and the generated code?

@casualjim
Copy link
Member

I think what is being asked is to support any in the codescan package, to recognize it the same way we recognize interface{} today

@amit-mahendrakar
Copy link

The v0.29.0 generator does not understand any type.

If we try to use fields of type any in query or body, the generator gives error

unsupported type "invalid type"

because it sees any as invalid type

I think this is what @casualjim is asking.

@youyuanwu is there a plan to support it ?

@amit-mahendrakar
Copy link

whereas if we just change the type of parameter from any to interface{}, generation is successful.

@jesse-schneider
Copy link

Also would like to know if there are plans to include this in the future?

casualjim added a commit that referenced this issue Aug 26, 2022
@casualjim
Copy link
Member

I added some tests for where we have the type interface{}, all the tests we have for the codescan package pass.
I've also added the transportErr type from this issue. https://github.com/go-swagger/go-swagger/blob/8edb8ee718461ce941a04a235689f1b83431e0f0/fixtures/goparsing/go118/nomodel.go

I think you may get it to work with previous versions of go swagger by building from source with a newer golang like go 1.18.

casualjim added a commit that referenced this issue Aug 26, 2022
run go 1.19 gofmt on the codebase

reduce use of deprecated constructs

update to yaml.v3 where appropriate

start building on github actions

add tests for `any` type
add type from issue #2809
mbilski pushed a commit to cloudentity/go-swagger that referenced this issue Oct 20, 2022
run go 1.19 gofmt on the codebase

reduce use of deprecated constructs

update to yaml.v3 where appropriate

start building on github actions

add tests for `any` type
add type from issue go-swagger#2809
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

Successfully merging a pull request may close this issue.

5 participants