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

Combiners (anyOf, allOf, oneOf) + nullable #76

Open
toomuchdesign opened this issue Oct 2, 2024 · 0 comments
Open

Combiners (anyOf, allOf, oneOf) + nullable #76

toomuchdesign opened this issue Oct 2, 2024 · 0 comments

Comments

@toomuchdesign
Copy link

Good afternoon!
I'm writing to ask feedback about a possible conversion case that could be not handled by this library: combiners + nullable.

const schema = {
  nullable: true,
  allOf: [
    {
      type: "object",
      required: ["foo"],
      properties: {
        foo: {
          type: "integer",
        },
      },
    },
  ],
};

Currently the output strips nullable: true out, but it doesn't seem right.
The most plausible solution I can think of is the following, but I'd like to hear your thoughts about it.

const schema = {
  oneOf: [
    {
      type: "null",
    },
    {
      allOf: [
        {
          type: "object",
          required: ["foo"],
          properties: {
            foo: {
              type: "integer",
            },
          },
        },
      ],
    },
  ],
};

The approach above, beside being a valid OAS definition, seems to be a legit OAS 3.0.0 workaround to define nullable $ref properties.

// This is OAS invalid since you can't extend `$ref` definitions
const schema = {
  type: "object"
  properties: {
    foo: {
      $ref: '#/components/schemas/MyReferencedComponent'
      nullable: true
    }
  }
}

// This seems to be a valid workaround
const schema = {
  type: "object",
  properties: {
    foo: {
      allOf: [{ $ref: "#/components/schemas/MyReferencedComponent" }],
      nullable: true,
    },
  },
};

Happy to open a PR if the described use case seems legit.
Cheers!

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

1 participant