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

Support openapiV3 oneOf for fields/responses #1671

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

kkkiio
Copy link
Contributor

@kkkiio kkkiio commented Sep 16, 2023

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
Copy link
Contributor

ubogdan commented Nov 7, 2023

@kkkiio Thanks for your contribution

@nhtuan0700
Copy link

nhtuan0700 commented Aug 13, 2024

Hi @kkkiio
I did like that but it returns:

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

instead of oneOf


swaggo version: v1.16.3

@kkkiio
Copy link
Contributor Author

kkkiio commented Aug 13, 2024

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