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

oneOf support #126

Open
lifenautjoe opened this issue Feb 17, 2024 · 1 comment
Open

oneOf support #126

lifenautjoe opened this issue Feb 17, 2024 · 1 comment

Comments

@lifenautjoe
Copy link

Is there a way to use the oneOf attribute on the response specification?

Like this:

export class PreviewLink extends OpenAPIRoute {
  static schema: OpenAPIRouteSchema = {
    tags: ["Link Preview"],
    summary: "Previews the contents of a given link",
    requestBody: {
      description: "Preview request options",
      required: true,
      content: {
        "application/json": {
          schema: PreviewLinkRequestData,
        },
        "application/x-www-form-urlencoded": {
          schema: PreviewLinkRequestData,
        },
        "multipart/form-data": {
          schema: PreviewLinkRequestData,
        },
      },
    },
    responses: {
      "200": {
        description: "Returns the link preview",
        schema: {
          oneOf: [
            ResponseDocLink,
            ResponseXUserLink,
            ResponseXPostLink,
            ResponseYoutubeChannelLink,
            ResponseYoutubeVideoLink,
            ResponseHtmlLink,
            ResponseImageLink,
            ResponseVideoLink,
            ResponseAudioLink,
            ResponseInstagramUserLink,
            ResponseInstagramPostLink,
          ],
        },
      },
    },
  };
@goblinfactory
Copy link

goblinfactory commented Feb 19, 2024

@lifenautjoe I was just browsing this repo for the first time and stumbled across your question.
Have you tested this? do you know that anyOf, oneOf or allOf do not work for a fact?
It's mentioned briefly here in the readme talking about zod schemas;
https://github.com/cloudflare/itty-router-openapi/blob/89255c154a0421f7efb68b7d83d97b1964b8bc6a/docs/pages/types.md?plain=1#L221-L225

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

No branches or pull requests

2 participants