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

Why required: [] generates an error #651

Closed
erdnax123 opened this issue Aug 11, 2022 · 3 comments · Fixed by #1149
Closed

Why required: [] generates an error #651

erdnax123 opened this issue Aug 11, 2022 · 3 comments · Fixed by #1149
Labels
🐞bug Something isn't working

Comments

@erdnax123
Copy link

{
    ...
    "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

@erdnax123 erdnax123 added the 🐞bug Something isn't working label Aug 11, 2022
@dbanty
Copy link
Collaborator

dbanty commented Aug 11, 2022

Sure sounds like a bug 🐛. Thanks for reporting!

@joaonc
Copy link

joaonc commented Sep 3, 2024

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.

@benweint
Copy link
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.

benweint added a commit to benweint/openapi-python-client that referenced this issue Oct 27, 2024
benweint added a commit to benweint/openapi-python-client that referenced this issue Oct 27, 2024
benweint added a commit to benweint/openapi-python-client that referenced this issue Oct 27, 2024
benweint added a commit to benweint/openapi-python-client that referenced this issue Oct 27, 2024
…erators#651)

The Pydantic model for OpenAPI schemas in this tool was more stringent about the required key than the OpenAPI / JSON Schema specs themselves, requiring a min_length of 1, when neither of those schemas actually do. This change just removes the min_length constraint on the required field, so that 'required: []' is allowed in inputs to this tool.
github-merge-queue bot pushed a commit that referenced this issue Oct 27, 2024
Resolves #651 

From that issue:

The OpenAPI spec [section](https://swagger.io/specification/) 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](https://tools.ietf.org/html/draft-bhutton-json-schema-00).
> 
> For more information about the properties, see [JSON Schema
Core](https://tools.ietf.org/html/draft-bhutton-json-schema-00) and
[JSON Schema
Validation](https://tools.ietf.org/html/draft-bhutton-json-schema-validation-00).

The JSON Schema Validation spec
[says](https://json-schema.org/draft/2020-12/json-schema-validation#name-required)
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.
@knope-bot knope-bot bot mentioned this issue Oct 27, 2024
github-merge-queue bot pushed a commit that referenced this issue Nov 23, 2024
> [!IMPORTANT]
> Merging this pull request will create this release

## Fixes

- allow required fields list to be specified as empty (#651) (#1149)
- import cast for required const properties, since it's used in the
template (#1153)

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants