You are here

class SwaggerUi in Swagger UI for OpenAPI UI 8

Implements openapi_ui plugin for the swagger-ui library.

Plugin annotation


@OpenApiUi(
  id = "swagger",
  label = @Translation("Swagger UI"),
)

Hierarchy

Expanded class hierarchy of SwaggerUi

File

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

Namespace

Drupal\openapi_ui_swagger\Plugin\openapi_ui\OpenApiUi
View source
class SwaggerUi extends OpenApiUi {

  /**
   * {@inheritdoc}
   */
  public function build(array $render_element) {
    $schema = $render_element['#openapi_schema'];
    $build = [
      '#type' => 'html_tag',
      '#tag' => 'div',
      '#attributes' => [
        'id' => 'swagger-ui',
        'class' => [
          'swagger-ui-wrap',
        ],
      ],
      '#attached' => [
        'library' => [
          'openapi_ui_swagger/swagger_ui_integration',
        ],
      ],
    ];
    if ($schema instanceof Url) {
      $build['#attributes']['data-openapi-ui-url'] = $schema
        ->toString();
    }
    else {
      $build['#attributes']['data-openapi-ui-spec'] = Json::encode($schema);
    }
    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
SwaggerUi::build public function Render the tree for an openapi doc library. Overrides OpenApiUi::build