swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.62k stars 1.19k forks source link

[Q&A] How can I make an interface{} type oneOf multiple specified structs. Additionally how can I make swagger provide examples for that interface #1900

Open gabegibbturion opened 1 day ago

gabegibbturion commented 1 day ago

Describe the bug I cannot make an interface{} type be generated as oneOf other defined structs. I have image image And I want some way to make the pointing parameters dynamic in swagger docs.

Expected behavior I want to be able to specify for my interface type that is one of multiple possible types. That is in the swagger docs, PointingParameters can be one of the two pointing types below. I don't know if swagger supports this. If that is not possible I would like to be able to specify an example for my interface type that is NOT a string, since swaggertype:"object" does not support examples.

Your swag version e.g. 1.16.3

Your go version e.g. 1.21.1

sdghchj commented 18 hours ago

OpenAPI v2 has no 'oneOf'. As I see, the swag branch v2, which conforms to OpenAPI v3, has not been finished.

gabegibbturion commented 6 hours ago

OpenAPI v2 has no 'oneOf'. As I see, the swag branch v2, which conforms to OpenAPI v3, has not been finished.

Is there some way to specify a custom json example for an interface type with swagger? When doing swaggertype:"object" I got the error that you could not specify examples for them, however I was able to do it via manually editing a swagger.yaml