FAQ

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

    nullable-enum-contains-null


    Formats: Severity:

    When a schema is marked as nullable, and also defines an enum array, the enum must explicitly contain a null value (not the string "null").

    This rule validates both OpenAPI 3.0 (nullable: true) and OpenAPI 3.1 (type: [<type>, "null"]) nullable patterns.

    Why did this violation appear?

    A schema is marked as nullable but its enum array does not contain an actual null value. Simply marking a schema as nullable is not enough when using enums - the null value must be explicitly listed in the enum array.

    Bad example

    OpenAPI 3.0 - nullable enum without null:

    components:
      schemas:
        Status:
          type: string
          nullable: true
          enum: [active, inactive, pending]
          # Missing null in enum array
    

    OpenAPI 3.1 - nullable type enum without null:

    components:
      schemas:
        Priority:
          type: [string, "null"]
          enum: [low, medium, high]
          # Missing null in enum array
    

    Using the string "null" instead of actual null:

    components:
      schemas:
        State:
          type: string
          nullable: true
          enum: [active, inactive, "null"]
          # String "null" is not the same as null
    

    Good Example

    OpenAPI 3.0 with explicit null in enum:

    components:
      schemas:
        Status:
          type: string
          nullable: true
          enum: [active, inactive, pending, null]
    

    OpenAPI 3.1 with explicit null in enum:

    components:
      schemas:
        Priority:
          type: [string, "null"]
          enum: [low, medium, high, null]
    

    Parameter with nullable enum:

    paths:
      /items:
        get:
          parameters:
            - name: filter
              in: query
              schema:
                type: string
                nullable: true
                enum: [recent, popular, trending, null]
    

    How do I fix this violation?

    Add null (unquoted) to your enum array. Make sure it’s an actual null value, not the string "null".

    Important: The null value should not be quoted. Use null, not "null".

    # Correct
    enum: [value1, value2, null]
    
    # Incorrect
    enum: [value1, value2, "null"]
    

    This ensures that API consumers can properly send null values when the enum is used for input, and handle null values correctly when the enum is used for output.