public function SwaggerUi::build in Swagger UI for OpenAPI UI 8
Render the tree for an openapi doc library.
The callback is trigged to allow the plugin to define the plugin or library specific rendering which needs to happen in order to construct the element.
Parameters
array $render_element: The render array structure for the element which is triggering the build of this plugin's rendering.
Return value
array The processed render array.
Overrides OpenApiUi::build
File
- src/
Plugin/ openapi_ui/ OpenApiUi/ SwaggerUi.php, line 23
Class
- SwaggerUi
- Implements openapi_ui plugin for the swagger-ui library.
Namespace
Drupal\openapi_ui_swagger\Plugin\openapi_ui\OpenApiUiCode
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;
}