Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

calling getItems() on ArrayType instance throws exception #122

Open

Description

@imissyouso

Expected Behavior

Method getItems() on ArrayType instance should return any object of TypeInterface
For example for RAML spec like:

...
types:
  Cats:
    type: object[]
    items:
      properties:
        name: string
...

call:

foreach ($apiDef->getTypes() as $type) {
    var_dump($type->getItems());
}

should print dump of StringType object

Actual Behavior

Throws exception:

Exception: No type found for name array 

because

    /**
     * Retrieves a type by name
     *
     * @param string $name Name of the Type to retrieve.
     *
     * @return \Raml\TypeInterface Returns Type matching given name if found.
     * @throws \Exception When no type is found.
     **/
    public function getTypeByName($name)
    {
        foreach ($this->collection as $type) {
            /** @var $type \Raml\TypeInterface */
            if ($type->getName() === $name) {
                return $type;
            }
        }
        throw new \Exception(sprintf('No type found for name %s, list: %s', var_export($name, true), var_export($this->collection, true)));
    }

it tries to find the array type inside the list of already declared complex types instead of create new scalar StringType

Activity

  1. imissyouso commented on May 13, 2018

    @imissyouso
    Author

    similar behaviour is actual for:

    types:
      Cat:
        type: object
        properties:
          owner: Person
          name: string
    

    Pls direct me how to work with such structures? How to get access to owner field? If lib doesn't support structures like this pls assign me to this issue and I'll start working on it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions