Skip to content

Support openapiV3 oneOf for fields/responses - #1671

Merged
ubogdan merged 3 commits into
swaggo:v2from
kkkiio:feat-openapiv3-oneof
Nov 7, 2023
Merged

ubogdan merged 3 commits into
swaggo:v2from
kkkiio:feat-openapiv3-oneof

Conversation

@kkkiio

@kkkiio kkkiio commented Sep 16, 2023 •

Copy link
Copy Markdown
Contributor

Describe the PR
Adds support for the oneOf feature in OpenAPI v3, allowing you to describe a field/response that can have multiple types.

Relation issue
Close #1363
Close #1617

*Additional context
Example:

type Dog struct {
	Bark  bool   `json:"bark"`
	Breed string `json:"breed" enums:"Dingo,Husky,Retriever,Shepherd"`
}

type Cat struct {
	Hunts bool `json:"hunts"`
	Age   int  `json:"age"`
}

type Pet struct {
	PetType string `json:"pet_type" enums:"Cat,Dog"`
	PetDetail any `json:"pet_detail" oneOf:"Cat,Dog"`
}

// @Summary Get pet by ID
// @Param id path string true "ID"
// @Success 200 {object} Cat
// @Success 200 {object} Dog
// @Success 200 "Return Cat or Dog"
// @Router /pets/{id} [get]
func GetPetByID() {

}

@kkkiio kkkiio changed the title Support openapiV3 oneOf in fields Support openapiV3 oneOf for fields/responses Sep 28, 2023
@ubogdan
ubogdan merged commit 8f63cde into swaggo:v2 Nov 7, 2023
@ubogdan

ubogdan commented Nov 7, 2023

Copy link
Copy Markdown
Contributor

@kkkiio Thanks for your contribution

@nhtuan0700

nhtuan0700 commented Aug 13, 2024 •

Copy link
Copy Markdown

Hi @kkkiio
I did like that but it returns:

"200": {
           "description": "Return Cat or Dog"
}

instead of oneOf


swaggo version: v1.16.3

@kkkiio

kkkiio commented Aug 13, 2024

Copy link
Copy Markdown
Contributor Author

Unfortunately, the PR was reverted due to a compile error. I may create a new PR to address this.

Please note that the oneOf feature is supported by OpenAPI v3, which is only available in the v2 branch of the project that hasn't been officially released yet.

@kkkiio kkkiio mentioned this pull request Aug 13, 2024
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 this pull request may close these issues.

3 participants

⌂ 换网址