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
Browse files Browse the repository at this point in the history
  • Loading branch information
rgzp committed Sep 26, 2019
1 parent a400e0c commit c5ed880
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,19 @@ private function parseResourceTypes($ramlData)
{
if (isset($ramlData['resourceTypes'])) {
$keyedResourceTypes = [];

foreach ($ramlData['resourceTypes'] as $i => $resourceType) {
if (is_int($i)) {
// In RAML 0.8 is an array of maps; in each map, the keys are resourceType names
foreach ($resourceType as $k => $t) {
$keyedResourceTypes[$k] = $t;
}
} else {
// In RAML 1.0 is a map where keys names become names of resource types
$keyedResourceTypes[$i] = $resourceType;
}
}

foreach ($ramlData['resourceTypes'] as $resourceType) {
foreach ($resourceType as $k => $t) {
$keyedResourceTypes[$k] = $t;
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 c5ed880

Please sign in to comment.