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

add empty check for properties #712

Merged
merged 2 commits into from
Aug 19, 2023

Conversation

rpmccarter
Copy link
Contributor

Objects with empty properties are being serialized as [] in the resulting openapi.yaml, which is invalid OpenAPI. This was already being handled in a couple places, just missed a few. I also replaced the $EMPTY class prop with a function that also performs the empty check.

Luckily, TheSideProjectAPI actually has an example of this bug! I tested with that repo and the fix seemed to work.

First time working in php, pointers welcome!

@@ -241,6 +233,9 @@ protected function generateEndpointRequestBodySpec(OutputEndpointData $endpoint)
$schema['properties'][$name] = $fieldData;
}

if (array_key_exists('properties', $schema)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

'properties' gets erased when an array is encountered, so we need to check if it's still there

Copy link
Contributor

@shalvah shalvah left a comment

Choose a reason for hiding this comment

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

Nice! The function solution is indeed cleaner!

src/Writing/OpenAPISpecWriter.php Show resolved Hide resolved
@shalvah shalvah merged commit 1f94ac5 into knuckleswtf:master Aug 19, 2023
@rpmccarter rpmccarter deleted the serialize-properties-as-object branch August 21, 2023 07:00
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