protected function JsonApiGenerator::getRouteMethodDescription in OpenAPI for JSON:API 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php \Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator\JsonApiGenerator::getRouteMethodDescription()
Gets description of a method on a route.
Parameters
\Symfony\Component\Routing\Route $route: The route.
string $route_name: The route name.
string $method: The method.
string $resource_type_name: The resource type name
Return value
string The method description.
1 call to JsonApiGenerator::getRouteMethodDescription()
- JsonApiGenerator::getPaths in src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php
File
- src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php, line 353
Class
- JsonApiGenerator
- Defines an OpenApi Schema Generator for the JsonApi module.
Namespace
Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGeneratorCode
protected function getRouteMethodDescription($route, $route_name, $method, $resource_type_name) {
$route_type = $this
->getRoutTypeFromName($route_name);
if (!$route_type || $method !== 'get') {
return NULL;
}
if ($route_type === 'collection') {
$message = '%link_co for the @name resource type. Collections are a list';
$message .= ' of %link_ro for a particular resource type. In the JSON ';
$message .= 'API module for Drupal all collections are homogeneous, ';
$message .= 'which means that all the items in a collection are of the ';
$message .= 'same type.';
return $this
->t($message, [
'%link_co' => Link::fromTextAndUrl($this
->t('Collection endpoint'), Url::fromUri('http://jsonapi.org/format/#fetching'))
->toString(),
'@name' => $resource_type_name,
'%link_ro' => Link::fromTextAndUrl($this
->t('resource objects'), Url::fromUri('http://jsonapi.org/format/#document-resource-objects'))
->toString(),
]);
}
elseif ($route_type === 'individual') {
$message = '%link_in for the @name resource type. The individual ';
$message .= 'endpoint contains a %link_ro with the data for a particular';
$message .= ' resource or entity.';
return $this
->t($message, [
'%link_in' => Link::fromTextAndUrl($this
->t('Individual endpoint'), Url::fromUri('http://jsonapi.org/format/#fetching'))
->toString(),
'@name' => $resource_type_name,
'%link_ro' => Link::fromTextAndUrl($this
->t('resource object'), Url::fromUri('http://jsonapi.org/format/#document-resource-objects'))
->toString(),
]);
}
elseif ($route_type === 'related') {
$message = '%link_related for the @target_name resource type through the';
$message .= ' %field_name relationship. The related endpoint contains a ';
$message .= '%link_ro with the data for a particular related resource or';
$message .= ' entity.';
$target_resource_type = $this
->relatedResourceType($route_name, $route);
return $this
->t($message, [
'%link_related' => Link::fromTextAndUrl($this
->t('Related endpoint'), Url::fromUri('http://jsonapi.org/format/#fetching'))
->toString(),
'@target_name' => $target_resource_type
->getTypeName(),
'%field_name' => explode('.', $route_name)[2],
'%link_ro' => Link::fromTextAndUrl($this
->t('resource object'), Url::fromUri('http://jsonapi.org/format/#document-resource-objects'))
->toString(),
]);
}
elseif ($route_type === 'relationship') {
$message = '%link_rel for the @target_name resource type through the';
$message .= ' %field_name relationship. The relationship endpoint ';
$message .= 'contains a %link_ri with the data for a particular ';
$message .= 'relationship.';
$target_resource_type = $this
->relatedResourceType($route_name, $route);
return $this
->t($message, [
'%link_rel' => Link::fromTextAndUrl($this
->t('Relationship endpoint'), Url::fromUri('https://jsonapi.org/format/#fetching-relationships'))
->toString(),
'@target_name' => $target_resource_type
->getTypeName(),
'%field_name' => explode('.', $route_name)[2],
'%link_ri' => Link::fromTextAndUrl($this
->t('resource identifier object'), Url::fromUri('https://jsonapi.org/format/#document-resource-identifier-objects'))
->toString(),
]);
}
return NULL;
}