Fix: Move required from array schema to object schema inside items#1068
Merged
shalvah merged 3 commits intoMay 1, 2026
Merged
Conversation
…PI spec
Within the OpenAPI spec, the required array belongs on the object schema
inside items, not on the parent array schema. Also adds required field
support for unwrapped array-of-object responses, for example, when Laravel APIs return a collection, it's wrapped in a `data` key like `{ "data": [{"name": "foo"}]}` but you can call `JsonResource::withoutWrapping()` to get an array instead: `[{"name": "foo"}]`. So the bug was that the required field logic existed for the wrapped case, but not the unwrapped branch.
Contributor
Author
|
I see this is the same issue as this PR, but I would like to see if the test changes are fixed with this pr |
Contributor
Author
|
CI is fixed by separate this other PR: https://github.com/knuckleswtf/scribe/pull/1071/changes |
Contributor
Author
|
Hi @shalvah! Is there a release schedule? No rush. The package is great, so would like to help improve it with this change :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the openapi spec, the required array belongs on the object schema inside items, not on the parent array schema (see data types)
requiredfield placement in array item schemas. It was being set on the array schema itself instead of insideitems, but it should have been in theobjectschema. The fix for this is in the functiongenerateSchemaForResponseValue.Example:
Incorrect:
requiredobject properties are in the array schemaCorrect:
requiredobject properties are in the object schema:requiredfield support for responses that are arrays of objects. For example, when Laravel APIs return a collection, it's wrapped in adatakey like{ "data": [{"name": "foo"}]}but you can callJsonResource::withoutWrapping()to get an array instead:[{"name": "foo"}]. The fix for this is ingenerateResponseContentSpec.