Skip to content

fix: allow required fields list to be specified as empty (#651) #1149

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

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

benweint
Copy link
Contributor

@benweint benweint commented Oct 27, 2024

Resolves #651

From that issue:

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 benweint force-pushed the allow-empty-list-required branch 2 times, most recently from 6a8b192 to c8d9604 Compare October 27, 2024 18:03
…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.
@benweint benweint force-pushed the allow-empty-list-required branch from c8d9604 to 7b17573 Compare October 27, 2024 18:06
@benweint benweint changed the title Allow required fields list to be specified as empty (resolves #651) fix: allow required fields list to be specified as empty (#651) Oct 27, 2024
@dbanty
Copy link
Collaborator

dbanty commented Oct 27, 2024

Thanks for both the detailed explanation and the PR!

@dbanty dbanty enabled auto-merge October 27, 2024 18:46
@dbanty dbanty added this pull request to the merge queue Oct 27, 2024
Merged via the queue into openapi-generators:main with commit 674ae4b Oct 27, 2024
22 checks passed
@knope-bot knope-bot bot mentioned this pull request Oct 27, 2024
github-merge-queue bot pushed a commit that referenced this pull request 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why required: [] generates an error
2 participants