Skip to content

Feat openapiv3 oneof - #1870

Merged
ubogdan merged 3 commits into
swaggo:v2from
kkkiio:feat-openapiv3-oneof
Oct 21, 2024
Merged

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

Conversation

@kkkiio

@kkkiio kkkiio commented Aug 13, 2024

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
#1363
#1617

Additional context
Unfortunately, the PR #1671 was reverted due to a compile error caused by the use of the maps package.
The maps package was introduced in Go 1.21, but the project is currently using Go 1.18.

@ubogdan

ubogdan commented Oct 20, 2024

Copy link
Copy Markdown
Contributor

Please rebase from V2, we updated the go version and it's very likely to work now.

@ubogdan ubogdan added the v2 Used for all v2 related issues label Oct 20, 2024
@kkkiio kkkiio closed this Oct 21, 2024
@kkkiio
kkkiio force-pushed the feat-openapiv3-oneof branch from 6cc8177 to 2fa63cf Compare October 21, 2024 14:28
@kkkiio kkkiio reopened this Oct 21, 2024

@ubogdan ubogdan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ubogdan
ubogdan merged commit 6700370 into swaggo:v2 Oct 21, 2024
@codingcn

Copy link
Copy Markdown

Thank you very much for your contribution. However, currently only response is supported. It is hoped that oneof will also be supported for requestBody

https://swagger.io/docs/specification/v3_0/data-models/oneof-anyof-allof-not/

@lahdekorpi

Copy link
Copy Markdown

This seems to introduce a new issue to all request bodies, making them oneOf regardless of what input they have

// @Summary      Restore a configuration rule from history
// @Description  Restores a previous version of a rule based on a history ID. This creates a new rule with the old value.
// @Tags         Secret
// @Accept       json
// @Produce      json
// @Param        historyID  path      string             true  "ID of the history entry to restore"
// @Param        restore    body      restoreRuleRequest true  "Restore rule payload"
// @Success      201        {object}  ruleResponse
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
              - type: object # This should not be
              - $ref: '#/components/schemas/secret.restoreRuleRequest'
                description: Restore rule payload
                summary: restore

I think it is getting confused with the @Accept and @Produce. If I remove the @Accept it starts working.

Should I create a new issue about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Used for all v2 related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

⌂ 换网址