cebe / php-openapi

Read and write OpenAPI yaml/json files and make the content accessible in PHP objects.
MIT License
466 stars 88 forks source link

Feature Request: Access component schemas by name #9

Closed ramsey closed 5 years ago

ramsey commented 5 years ago

In OAS, I can reference schemas by name: #/components/schemas/MySchema. While playing with cebe/php-openapi, I attempted to access a schema through a similar path, like this:

$openapi->components->schemas->MySchema
// or
$openapi->components->schemas['MySchema']

Unfortunately, neither approach works because schemas is a 0-indexed array and not a hash or object with named properties.

Consider modifying $openapi->components->schemas so that it is an object with properties named according to the named schemas in the path #/components/schemas.

cebe commented 5 years ago

yes, references are not implemented yet. Working on that.

ramsey commented 5 years ago

No worries. I didn’t think of this in terms of references, but rather accessing the schemas by name.

cebe commented 5 years ago

given this schema

components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"

Accessing $openapi->components->schemas['Pet'] should definitively work. This is a bug.

cebe commented 5 years ago

fixed. thanks for reporting!

cebe commented 5 years ago

I released a beta version today, everything should be working as expected now :)