-
Notifications
You must be signed in to change notification settings - Fork 933
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
Allow a ref to be nullable #1391
Conversation
the test fails, because it looks like by default "category" on Pet is nullable, but it contains this /**
* @OA\Property(
* title="Category",
* )
*
* @var Category
*/
private $category; by default, properties are nullable ? With the PR, it generates Pet:
title: 'Pet model'
description: 'Pet model'
required:
- name
- photoUrls
properties:
id:
title: ID
description: ID
type: integer
format: int64
category:
nullable: true
oneOf:
-
$ref: '#/components/schemas/Category'
name:
title: 'Pet name'
description: 'Pet name'
type: integer
format: int64
photoUrls:
title: 'Photo urls'
description: 'Photo urls'
type: array
items:
type: string
default: images/image-1.png
xml:
name: photoUrl
wrapped: true
tags:
title: 'Pet tags'
description: 'Pet tags'
type: array
items:
$ref: '#/components/schemas/Tag'
xml:
name: tag
wrapped: true
type: object
xml:
name: Pet |
Fixes the issue mentioned on zircote#1391 (comment)
requires #1397 to pass tests |
Fixes the issue mentioned on #1391 (comment)
i have no idea what are those errors on the tests, they seems unrelevant |
Yeah, there is another pr with the same... |
I update master so a new rebase/merge should fix the remaining build issues. |
I rebased and the build is successful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good I think. I don't think there is any way of oneOf
already being set...
It would be cool if you could add a scratch test (file +spec) that tests this incl. handling of summary
and description
so should I also support summary and description the same as I support nullable or should I make a test that test my nullable thing and also test if summary and description are added on version 3.1.0 ? |
Both, kinda. A test for both 3.0 and 3.1 would be great. |
So for < 3.1 I must add the possibility to add description and summary beside nullable too ? Not sure if I understood correctly |
I just merged #1405 which adds a scratch test for refs in combination with
schema:
$ref: '#/components/schemas/repository'
description: 'The repository' |
is it possible that something have a if ($this->_context->version == OpenApi::VERSION_3_1_0) {
if (isset($data->nullable)) {
if (true === $data->nullable) {
$data->type = (array) $data->type;
$data->type[] = 'null';
}
unset($data->nullable);
}
} Shouldn't I add something like if ($this->_context->version == OpenApi::VERSION_3_1_0) {
if (isset($data->nullable) && isset($data->type)) {
if (true === $data->nullable) {
$data->type = (array) $data->type;
$data->type[] = 'null';
}
unset($data->nullable);
}
} or maybe or if ($this->_context->version == OpenApi::VERSION_3_1_0) {
if (isset($data->nullable)) {
if (true === $data->nullable) {
if (isset($data->type)) {
$data->type = [$data->type];
} else {
$data->type = [];
}
$data->type[] = 'null';
}
unset($data->nullable);
}
} |
Good point. I think unsetting In addition there are two more things that should change:
OptionalAddress:
oneOf:
- type: 'null'
- $ref: "#/definitions/Address" |
OptionalAddress: |
I do not believe having |
i need it on 3.0 as I can't upgrade until swagger ui support it :/ |
i updated the code for both 3.0 and 3.1. |
You can fix code style issues by running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple questions to clean up, otherwise looking good. I wonder if we could add a non-ref element to the scratch test and make it nullable - to see what happens when $ref
is not set.
Good stuff otherwise - looking forward to merging as this seems to be a major pain point.... |
thanks for your review. I updated the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @momala454 , thanks a lot.
thank you. |
Yeah, but I checked - I do not think that can happen. At least not how I thought the code is working. |
Thank you. |
Fixes the issue mentioned on zircote/swagger-php#1391 (comment)
Fixes #1338
It creates a oneOf with a single ref, and with nullable true