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

Definitions property is expected to be an object, not an array #162

Open
uuf6429 opened this issue Jul 13, 2024 · 0 comments
Open

Definitions property is expected to be an object, not an array #162

uuf6429 opened this issue Jul 13, 2024 · 0 comments

Comments

@uuf6429
Copy link

uuf6429 commented Jul 13, 2024

When I try creating a schema with an array/hashmap of definitions it complains that definitions was expected to be an object.

JsonSchema\Schema::import((object)[
    'definitions' => [
        'aaa' => JsonSchema\Schema::import((object)['type' => 'object'])
    ]
]);

Swaggest\JsonSchema\Exception\TypeException: Object expected, {"aaa":{"type":"object"}} received at #->properties:definitions

Typecasting that array to an object fixes the problem (it actually shows a different error, but that's irrelevant):

JsonSchema\Schema::import((object)[
    'definitions' => (object)[       //    <------
        'aaa' => JsonSchema\Schema::import((object)['type' => 'object'])
    ]
]);

So I believe the PHPDoc here is wrong:

/** @var JsonSchema[] */

In this case it would have been object<string, JsonSchema>, but that's not a supported syntax. So maybe either \ArrayObject<string, JsonSchema> or simply an \object with an explanatory description.

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

No branches or pull requests

1 participant