cebe / cebe/php-openapi

Add support for empty Security Requirement Object (`{}`) in security requirement

Open
#238 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
500
Forks
99
PR merge metrics
No merged PRs in 30d

Description

From https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#security-requirement-object

An empty Security Requirement Object (`{}`) indicates anonymous access is supported.

This is used in https://raw.githubusercontent.com/cloudflare/api-schemas/refs/heads/main/openapi.yaml L164315

![Image](https://github.com/user-attachments/assets/233bc76b-28db-486f-b549-c4c929903e5e)

With current lib and above Cloudflare spec we get error:

```
There was 1 error:

1) IssueTest::test224FailsOnLargeDefinitions
Undefined offset: 0

/app/src/spec/SecurityRequirements.php:29
/app/src/SpecBaseObject.php:168
/app/src/SpecBaseObject.php:140
/app/src/SpecBaseObject.php:168
/app/src/SpecBaseObject.php:140
/app/src/spec/PathItem.php:81
/app/src/spec/Paths.php:62
/app/src/SpecBaseObject.php:168
/app/src/SpecBaseObject.php:140
/app/src/Reader.php:57
/app/src/Reader.php:138
/app/tests/IssueTest.php:17
phpvfscomposer:///app/vendor/phpunit/phpunit/phpunit:106

```

Observed this issue while fixing https://github.com/cebe/php-openapi/issues/224

So adding implementation for empty Security Requirement Object (`{}`) in security requirement is required.

More info about security schemes and security requirements can be obtained at https://swagger.io/docs/specification/v3_0/authentication/

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in spec/SecurityRequirements.php, where the reported Undefined offset occurs, and review tests/IssueTest.php, including test224FailsOnLargeDefinitions. Reproduce the Cloudflare OpenAPI case and confirm that an empty Security Requirement Object is accepted without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.