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

Support RAML 1.0 resource types declaration #159

Merged
merged 3 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,16 @@ private function parseResourceTypes($ramlData)
{
if (isset($ramlData['resourceTypes'])) {
$keyedResourceTypes = [];
foreach ($ramlData['resourceTypes'] as $resourceType) {
foreach ($resourceType as $k => $t) {
$keyedResourceTypes[$k] = $t;

foreach ($ramlData['resourceTypes'] as $key => $value) {
if ($this->isRaml08($key)) {
foreach ($value as $k => $t) {
$keyedResourceTypes[$k] = $t;
}

continue;
}
$keyedResourceTypes[$key] = $value;
}

foreach ($ramlData as $key => $value) {
Expand All @@ -429,6 +435,15 @@ private function parseResourceTypes($ramlData)
return $ramlData;
}

/**
* @param string|int $key
* @return bool
*/
private function isRaml08($key)
{
return \is_int($key);
}

/**
* @param string $rootDir
* @return array
Expand Down
39 changes: 39 additions & 0 deletions tests/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,4 +1187,43 @@ traits:
$this->assertCount(1, $simpleRaml->getResourceByPath('/users')->getTraits());
$this->assertCount(2, $simpleRaml->getResourceByPath('/users')->getMethod('get')->getTraits());
}

/**
* @test
*/
public function shouldParseResourceTypesAndTraits()
{
$traitsAndTypes = $this->parser->parse(__DIR__ . '/fixture/raml-1.0/traitsAndTypes.raml');

$resource = $traitsAndTypes->getResourceByUri('/test');
$method = $resource->getMethod('get');
$queryParameters = $method->getQueryParameters();
$headers = $method->getHeaders();

$this->assertArrayHasKey('title', $queryParameters);
$this->assertArrayHasKey('numPages', $queryParameters);
$this->assertArrayHasKey('access_token', $headers);

$this->assertEquals(
'Return values that have their title matching the given value',
$queryParameters['title']->getDescription()
);
$this->assertEquals('The number of pages to return', $queryParameters['numPages']->getDescription());
$this->assertEquals(
[
'access_token' => NamedParameter::createFromArray(
'access_token',
[
'displayName' => null,
'description' => 'A valid access_token is required',
'examples' => [
'5757gh76',
],
'required' => 'true',
]
),
],
$headers
);
}
}