Skip to content

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

Open
@toomuchdesign

Description

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!

Activity

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions