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

[OpenApi] PropertyGenerator::getType(): Argument #1 ($type) must be of type string, null given #398

Open
feamsr00 opened this issue Nov 5, 2022 · 2 comments

Comments

@feamsr00
Copy link

feamsr00 commented Nov 5, 2022

schema-gen version(s) affected: 5.1.1

Description

Received an exception when processing a json API schema.

How to reproduce
Config

# api/config/schema.yaml
openApi:
    file: './swagger.json'

>schema gen sgen\src schema.yml
schema file is attached swagger.zip

Additional Context

image

PHP Fatal error:  Uncaught TypeError: ApiPlatform\SchemaGenerator\OpenApi\PropertyGenerator\PropertyGenerator::getType(): Argument #1 ($type) must be of type string, null given, called in phar://C:/dev/tools/schema.phar/src/OpenApi/PropertyGenerator/PropertyGenerator.php on line 54 and defined in phar://C:/dev/tools/schema.phar/src/OpenApi/PropertyGenerator/PropertyGenerator.php:73
Stack trace:
#0 phar://C:/dev/tools/schema.phar/src/OpenApi/PropertyGenerator/PropertyGenerator.php(54): ApiPlatform\SchemaGenerator\OpenApi\PropertyGenerator\PropertyGenerator->getType()
#1 phar://C:/dev/tools/schema.phar/src/OpenApi/ClassGenerator.php(232): ApiPlatform\SchemaGenerator\OpenApi\PropertyGenerator\PropertyGenerator->__invoke()
#2 phar://C:/dev/tools/schema.phar/src/OpenApi/ClassGenerator.php(105): ApiPlatform\SchemaGenerator\OpenApi\ClassGenerator->buildClassFromSchema()
#3 phar://C:/dev/tools/schema.phar/src/OpenApi/Generator.php(54): ApiPlatform\SchemaGenerator\OpenApi\ClassGenerator->generate()
#4 phar://C:/dev/tools/schema.phar/src/Command/GenerateCommand.php(139): ApiPlatform\SchemaGenerator\OpenApi\Generator->generate()
#5 phar://C:/dev/tools/schema.phar/vendor/symfony/console/Command/Command.php(308): ApiPlatform\SchemaGenerator\Command\GenerateCommand->execute()
#6 phar://C:/dev/tools/schema.phar/vendor/symfony/console/Application.php(1002): Symfony\Component\Console\Command\Command->run()
#7 phar://C:/dev/tools/schema.phar/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#8 phar://C:/dev/tools/schema.phar/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#9 phar://C:/dev/tools/schema.phar/bin/schema(26): Symfony\Component\Console\Application->run()
#10 C:\dev\tools\schema.phar(17): require('...')
#11 {main}
  thrown in phar://C:/dev/tools/schema.phar/src/OpenApi/PropertyGenerator/PropertyGenerator.php on line 73
@beatgeb
Copy link

beatgeb commented Nov 2, 2023

I have a similar issue with the PropertyGenerator. When I define a properties type as Array in spotlight.io, the generation fails with
Fatal error: Uncaught TypeError: ApiPlatform\SchemaGenerator\OpenApi\Model\Type\PrimitiveType::__construct(): Argument #1 ($name) must be of type string, array given, called in ../vendor/api-platform/schema-generator/src/OpenApi/PropertyGenerator/PropertyGenerator.php on line 116.

It is caused by a type definition in the schema json like:

 "propertyName": {
    "type": [
      "boolean",
      "null"
    ],
    ...

@overgapo
Copy link

overgapo commented Nov 3, 2023

i've got same problem

Looks like the we have to fix openapi, because (in my case), i want to describe nullable field as.

"releasedAt": {
      "type": [
          "string",
          "null"
      ],
      "format": "date-time"
  },

Openapi docs say this way is incorrect:
image

I generated openapi with ApiPlatform's bin/console api:openapi:export --spec-version=3, so the root problem is in openapi generation

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

3 participants