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

Empty schema causes error in Swagger->getArray #495

Closed
cnizzardini opened this issue Dec 8, 2022 · 1 comment
Closed

Empty schema causes error in Swagger->getArray #495

cnizzardini opened this issue Dec 8, 2022 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@cnizzardini
Copy link
Owner

Empty schema causing these errors:

Warning: Warning (2): Invalid argument supplied for foreach() in ... src/Lib/Swagger.php, line 99]
Error: [TypeError] uksort() expects parameter 1 to be array, null given in ... src/Lib/Swagger.php on line 111

Sample YML schema:

components:
    schemas:

foreach ($this->array['components']['schemas'] as $schema) {

Proposed change:

		if (!empty($this->array['components']['schemas'])) {
			foreach ($this->array['components']['schemas'] as $schema) {
				if (!is_array($schema)) {
					$schema->toArray();
				}
			}
			uksort($this->array['components']['schemas'], function ($a, $b) {
				return strcasecmp(
					preg_replace('/\s+/', '', $a),
					preg_replace('/\s+/', '', $b)
				);
			});
		}
@cnizzardini cnizzardini added the bug Something isn't working label Dec 8, 2022
@cnizzardini cnizzardini added this to the v1.7.12 milestone Dec 8, 2022
@cnizzardini
Copy link
Owner Author

Not supporting 1.x anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant