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

Commit

Permalink
Support RAML 1.0 resource types declaration (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgzp authored and martin-georgiev committed Oct 1, 2019
1 parent a400e0c commit 3eec4c2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
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
);
}
}

0 comments on commit 3eec4c2

Please sign in to comment.