Skip to content

CLI call to openapi-spec with security in path fails #242

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

Open
dkreuer opened this issue May 15, 2025 · 3 comments
Open

CLI call to openapi-spec with security in path fails #242

dkreuer opened this issue May 15, 2025 · 3 comments

Comments

@dkreuer
Copy link

dkreuer commented May 15, 2025

Type: Bug
Since: 1.8.0

Description:
The CLI call php-openapi validate example.spec.json fails due to the fact that the security in path is transformed to a list of arrays and not a list of objects in

$data[] = [$name => $securityRequirement->getSerializableData()];

Minimal example.spec.json to reproduce:

{
  "openapi": "3.0.0",
  "info": {
    "title": "My API",
    "version": "1, 2"
  },
  "paths": {
    "/v1/users/profile": {
      "get": {
        "operationId": "V1GetUserProfile",
        "summary": "Returns the user profile",
        "responses": {
          "200": {
            "description": "dummy"
          }
        },
        "security": [
          {
            "test_test": ["test:scope:foo"]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "test_test": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://example.com/openid-connect/auth",
            "tokenUrl": "https://example.com/openid-connect/token",
            "scopes": {
              "test:scope:foo": "test_scope"
            }
          }
        }
      }
    }
  }
}

I'll provide a MR with test case and a fix if you like.

SOHELAHMED7 added a commit to SOHELAHMED7/php-openapi that referenced this issue May 15, 2025
@SOHELAHMED7
Copy link
Contributor

Thanks for reporting.

This issue is fixed in PR #239

Commit: SOHELAHMED7@f669fef

Commit containing test: 6d5bde9

@mkorkmaz
Copy link

Hi @SOHELAHMED7

I use this library to verify and merge yaml files into a single openapi yaml file. I have two security schemes as stated in example source below.

In most cases, I expect two of this security schemes to be used together (logical conjunction).

Since v1.8.0 this is broken and in generated yaml file only apiKey is used, ignores second one and bearerAuth is missing completely in endpoint definitions.

Example source yaml:

openapi: 3.0.0
info:
  title: API Documentation
  description: All API endpoints are presented here.
  version: 1.0.0
servers:
  - url: http://127.0.0.1:8080/

paths:

  /endpoint:
    get:
      responses:
        '200':
          description: OK
      security:
        - apiKey: []
          bearerAuth: []
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-APi-Key
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT Authorization header using the Bearer scheme.

Generated output:

openapi: 3.0.0
info:
  title: 'API Documentation'
  description: 'All API endpoints are presented here.'
  version: 1.0.0
servers:
  -
    url: 'http://127.0.0.1:8080/'
paths:
  /endpoint:
    get:
      responses:
        '200':
          description: OK
      security:
        -
          apiKey: []
components:
  securitySchemes:
    apiKey:
      type: apiKey
      name: X-APi-Key
      in: header
    bearerAuth:
      type: http
      description: 'JWT Authorization header using the Bearer scheme.'
      scheme: bearer
      bearerFormat: JWT

SOHELAHMED7 added a commit to SOHELAHMED7/php-openapi that referenced this issue May 17, 2025
@SOHELAHMED7
Copy link
Contributor

@mkorkmaz

Thanks for reporting.

This issue is fixed in 7b5f3da and 19fabbc (PR #239).

I have already added test for above scenario and I will add more of other scenarios

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

No branches or pull requests

3 participants