Strange required property in JsonResource #1222
Unanswered
apasquini95
asked this question in
Q&A
Replies: 1 comment 5 replies
|
@apasquini95 this is because you have overwritten the type of that property using var annotation |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone, I'm facing a strange issue regarding required properties in JsonResources even if they are loaded using the Laravel syntax
$this->when(...). I have a resource which wraps a class that has a super generic property that accepts all kinds of items:The resource simply adds the corresponding keys only when the original dto has that key:
I do not expect Scramble to know the type of data this array
$propscould contain, that's why I specified explicitly the type, but whyconditional_prophas been considered required in the openapi specification?{ "openapi": "3.1.0", "info": { "title": "Laravel", "version": "0.0.1" }, "servers": [ { "url": "http://localhost/api" } ], "paths": { "/": { "get": { "operationId": "test_route", "tags": [ "My" ], "responses": { "200": { "description": "`MyResource`", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/MyResource" } }, "required": [ "data" ] } } } } } } } }, "components": { "schemas": { "MyResource": { "type": "object", "properties": { "required_prop": { "type": "integer" }, "conditional_prop": { "type": "boolean" } }, "required": [ "required_prop", "conditional_prop" // Why is it required? ], "title": "MyResource" } } } }Am I missing something or maybe I could write the resource differently?
You can reproduce it in this public repository
https://github.com/apasquini95/demo_scramble/tree/bug_required_when
All reactions