Skip to content

fix to accept multitype param for nullable #51

Open
HajimeMat-AVAP wants to merge 3 commits intoreinfi:mainfrom
HajimeMat-AVAP:main
Open

fix to accept multitype param for nullable #51
HajimeMat-AVAP wants to merge 3 commits intoreinfi:mainfrom
HajimeMat-AVAP:main

Conversation

@HajimeMat-AVAP
Copy link
Copy Markdown

To Accept openapi type like

- string
- null

becouse API DOG generate like this if i allow null to params.

logic is like

if type is array and just have a 2 choice and 1 is "null" that means the type is the onather nullable.

so I changed

To Accept  openapi type like

```
- string
- null
```

becouse API DOG generate like this if i allow null to params.

logic is like

if type is array and just have a 2 choice and 1 is "null" that means the type is the onather  nullable.

so I changed
@reinfi
Copy link
Copy Markdown
Owner

reinfi commented Aug 8, 2024

Could you please add a test case to TypeResolverTest and also in the acceptance.yml one test object.

$type = match ($schema->type) {
$schemaType = $schema->type;
if (is_array($schema->type) && count($schema->type) == 2 && in_array("null", $schema->type)) {
$schemaType = current( array_filter($schema->type, fn ($x) => $x !== 'null'));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add typings to inner function, because $x can only be string

and also please to use short variable names like $x, $type would be suitable

$type = match ($schema->type) {
$schemaType = $schema->type;
if (is_array($schema->type) && count($schema->type) == 2 && in_array("null", $schema->type)) {
$schemaType = current( array_filter($schema->type, fn ($x) => $x !== 'null'));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But does that mean, that the nullable type is not detected correctly because in the PropertyResolver you do not check again for the nullable type?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I wanted to check the property if it's nullable. but I could not found the way to check again.

@HajimeMat-AVAP
Copy link
Copy Markdown
Author

I'm tring to write a test code but currentry facing this error

  PHP Fatal error:  Non-readonly class PHPUnit\Framework\TestStatus\Known cannot extend readonly class PHPUnit\Framework\TestStatus\TestStatus in /home/kurari/Repos/github.com/reinfi/openapi-models/vendor/phpunit/phpunit/src/Framework/TestStatus/Known.php
  on line 19

I will work on later.
thank you

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

Successfully merging this pull request may close these issues.

2 participants