Skip to content

Why required: [] generates an error #651

Closed

Description

@erdnax123
{
    ...
    "components": {
        "schemas": {
            "ABC": {
                "required": [],
                 ...
             },
             ...
        }
    }
}

this generates an error:

components -> schemas -> ABC -> required
  ensure this value has at least 1 items (type=value_error.list.min_items; limit_value=1)

"required": null do not generates an error

expected:

  • required not set
  • required = null
  • required = []

are the same and not generates an error

Activity

  1. dbanty commented on Aug 11, 2022

    @dbanty
    Collaborator

    Sure sounds like a bug 🐛. Thanks for reporting!

  2. joaonc commented on Sep 3, 2024

    @joaonc

    I don't think this is a bug. The parser in the IDE I use (JetBrains PyCharm) also spits out an error saying the required field needs at least one item.
    If you don't have any required fields, don't add required.

    This ticket can be closed, imo.

  3. benweint commented on Oct 27, 2024

    @benweint
    Contributor

    The OpenAPI spec section on the Schema object says:

    The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is a superset of the JSON Schema Specification Draft 2020-12.

    For more information about the properties, see JSON Schema Core and JSON Schema Validation.

    The JSON Schema Validation spec says of the required property:

    The value of this keyword MUST be an array. Elements of this array, if any, MUST be strings, and MUST be unique.

    An object instance is valid against this keyword if every item in the array is the name of a property in the instance.

    Omitting this keyword has the same behavior as an empty array.

    ... which makes pretty clear that specifying an empty array for required is supported by JSON Schema, and thus by OpenAPI, and thus should be supported by this tool's model of OpenAPI.

  4. added 4 commits that reference this issue on Oct 27, 2024
    62d9c7b
    6a8b192
    c8d9604
    7b17573
  5. added a commit that references this issue on Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions