You are here

class ReDoc in ReDoc for OpenAPI UI 8

Implements openapi_ui plugin for the swagger-ui library.

Plugin annotation


@OpenApiUi(
  id = "redoc",
  label = @Translation("ReDoc"),
)

Hierarchy

Expanded class hierarchy of ReDoc

File

src/Plugin/openapi_ui/OpenApiUi/ReDoc.php, line 18

Namespace

Drupal\openapi_ui_redoc\Plugin\openapi_ui\OpenApiUi
View source
class ReDoc extends OpenApiUi {

  /**
   * {@inheritdoc}
   */
  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);

      // We need to shim the redoc library to load from the spec attribute.
      $build['#attached']['library'][] = 'openapi_ui_redoc/redoc_attr';
    }
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
ReDoc::build public function Render the tree for an openapi doc library. Overrides OpenApiUi::build