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

OAS 3.1: Declaring type as array results in TypeError (for nullable types) #759

Open
marcovtwout opened this issue Oct 4, 2023 · 2 comments
Labels

Comments

@marcovtwout
Copy link

Jane version(s) affected: 7

Description
OpenAPI 3.1 is now fully compatible with JSON Schema 2020-12. In contrast to 3.0, the type keyword now allows for multiple types defined as an array. This commonly applies to nullable properties, but in general it could apply to any element where multiple types are allowed.

Attempting to generate client code containing a definition like this results in the following exception:

TypeError: Jane\Component\OpenApi3\JsonSchema\Model\Schema::setType(): Argument #1 ($type) must be of type ?string, array given, called in C:\example\vendor\jane-php\open-api-3\JsonSchema\Norma
lizer\SchemaNormalizer.php on line 174 in C:\example\vendor\jane-php\open-api-3\JsonSchema\Model\Schema.php on line 569

How to reproduce

  • Use any OAS 3.1 schema and create a property like this:
example_property:
  type:
  - string
  - 'null'
  • Attempt to generate client code.

Possible Solution
Jane-PHP should be able to deal with the official specification and allow arrays.

A workaround is to manually modify the schema and apply oneOf instead:

example_property:
  oneOf:
  - type: string
  - type: 'null'

Additional context

@marcovtwout marcovtwout added the bug label Oct 4, 2023
@AlexOstrovsky
Copy link

any update on this?

@Fahl-Design
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants