FAQ

  • GitHub GitHub Repo stars
  • Discord Discord Server
  • ✨ New! Try the OpenAPI Doctor ✨ The OpenAPI Doctor

    or


    or checks that an object has at least one of the named properties. Two or more properties can be present. Only the property name matters: null, false, 0, an empty string, an empty array, and an empty object all count as defined values. Non-object values are ignored.

    How do I use this function?

    Set properties to an array of at least two property names. Names are case-sensitive and refer to direct properties of the selected object. Use then.field to select a nested object.

    NAME TYPE REQUIRED? DESCRIPTION
    properties []string or string yes At least two property names, as an array or a comma-separated string.

    Vacuum also accepts a comma-separated string, such as "title, description". Spaces around each name and empty segments are removed. At least two names must remain. Use the array form for names that contain commas or leading or trailing spaces. Array names are used exactly as supplied.

    Example ruleset configuration

    rules:
      schema-descriptive-text:
        description: Schemas need a title, summary, or description.
        given: $.components.schemas.*
        severity: warn
        then:
          function: or
          functionOptions:
            properties: [title, summary, description]
    

    This schema passes because description exists:

    type: string
    description: null
    

    This schema fails because none of the three properties exists:

    type: string
    

    The default message is At least one of "title" or "summary" or "description" must be defined. Set the rule’s message to use a custom message.

    Check a nested object

    Use then.field to check properties inside an object selected by given. This rule requires the info.contact object to contain email or url. Both can be present.

    rules:
      contact-email-or-url:
        description: Contact details need an email address or a URL.
        message: Contact must define email or url.
        given: $.info
        severity: warn
        then:
          field: contact
          function: or
          functionOptions:
            properties: "email, url"
    

    This contact object passes because url exists:

    info:
      title: Example API
      version: '1.0'
      contact:
        name: API Support
        url: https://example.com/support
    

    A contact object with only name fails. If contact is absent or is not an object, or skips it. Use a separate defined check if contact must exist.

    Calling from JavaScript

    Custom JavaScript functions can call vacuum_or(input, context). Set properties in the custom rule’s functionOptions, as in the examples above. See Calling core functions.

    For a check that permits exactly one of two properties, use xor.


    View Spectral Equivalent


    View Function Source