ReDoc.php in ReDoc for OpenAPI UI 8
File
src/Plugin/openapi_ui/OpenApiUi/ReDoc.php
View source
<?php
namespace Drupal\openapi_ui_redoc\Plugin\openapi_ui\OpenApiUi;
use Drupal\Core\Url;
use Drupal\Component\Serialization\Json;
use Drupal\openapi_ui\Plugin\openapi_ui\OpenApiUi;
class ReDoc extends OpenApiUi {
public function build(array $render_element) {
$schema = $render_element['#openapi_schema'];
$build = [
'#type' => 'html_tag',
'#tag' => 'redoc',
'#attributes' => [
'id' => 'redoc-ui',
'no-auto-auth' => TRUE,
],
'#attached' => [
'library' => [
'openapi_ui_redoc/redoc',
],
],
];
if ($schema instanceof Url) {
$build['#attributes']['spec-url'] = $schema
->toString();
}
else {
$build['#attributes']['spec'] = Json::encode($schema);
$build['#attached']['library'][] = 'openapi_ui_redoc/redoc_attr';
}
return $build;
}
}
Classes
Name |
Description |
ReDoc |
Implements openapi_ui plugin for the swagger-ui library. |