From 97f485af50be78b1f38096ca2f07c6ac951f103b Mon Sep 17 00:00:00 2001 From: Karthik Kumar D K <17042-heykarthikwithu@users.noreply.drupalcode.org> Date: Fri, 28 Jul 2023 13:03:45 +0530 Subject: [PATCH] Issue #3377625 by heykarthikwithu: New features for API Docs module --- README.md | 32 ++++++++++++++ README.txt | 1 - api_docs.info.yml | 2 +- api_docs.module | 42 +++++++++++++++++-- config/install/views.view.api_docs.yml | 2 +- .../OpenApiDocFieldFormatter.php | 6 +-- 6 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 README.md delete mode 100644 README.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b5ebd1 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +User Registration Limit +------------ +This module will provides API Docs to your Developer Portal, It is powered by Drupal content type, custom field formatters & views. + +### Features covered +1. API Docs module will provide API Docs Content type, Redoc & Swagger UI Field Formatters & API Docs View. +2. Admins can create API Docs with the help of API Docs content type, by filling out the API Doc Name, Description, Status & Open API Spec. +3. Users can see the List the published API Docs with the help of API Docs View. + +Installation +------------ +* Install as you would normally install a contributed Drupal module. For further information, see [Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules). + +Configuration +------------- +* After enabling the module, navigate to **Add API Docs** `/node/add/api_docs`. + * Fill the API Doc _Name_, _Description_, _Status_ & _Open API Specification_, Save the content by clicking _Save_. + * Similarly, Admin will be able to create as many API Docs. +* Navigate to **API Docs** via `/api-docs` + * Users can see list of API Docs published in the site, with filter by _API Doc Status_, with minimal details of the API Doc. + * Each API Doc in this list will have _View Redoc UI_ & _View Swagger UI_, users will be able to navigate to respective API Doc pages. + +Customizations +-------------- +* API Docs is providing a **Field Formatter**, **Open API** Field Formatter. + * Open API field formatter can be used in for any **file** field type within your site. + * Open API field formatter, can render the file in two possible ways + * One with **Redoc UI** format. + * Other with **Swagger UI** format. + * Admin will have the flexibility to change this configuration of the Open API field formatter. +* API Docs is providing two **View modes**, they are **Redoc UI** & **Swagger UI**, these View modes are used in the API Docs content typs displays & API Docs View. If needed these can be customized at API Docs display level. + diff --git a/README.txt b/README.txt deleted file mode 100644 index 6c4eebc..0000000 --- a/README.txt +++ /dev/null @@ -1 +0,0 @@ -API Docs diff --git a/api_docs.info.yml b/api_docs.info.yml index 53a865d..59c52d8 100644 --- a/api_docs.info.yml +++ b/api_docs.info.yml @@ -1,4 +1,4 @@ name: 'API Docs' type: module -description: 'This module will provides API Docs to your Developer Portal, It is powered by Drupal content type & custom field formatters.' +description: 'This module will provides API Docs to your Developer Portal, It is powered by Drupal content type, custom field formatters & views.' core_version_requirement: '>=8.9 <11.0.0-stable' diff --git a/api_docs.module b/api_docs.module index b8f19f6..434c982 100644 --- a/api_docs.module +++ b/api_docs.module @@ -12,15 +12,49 @@ use Drupal\Core\Routing\RouteMatchInterface; */ function api_docs_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { - // Main module help for the api_docs module. case 'help.page.api_docs': - $output = '<p>' . t('This module will provides API Docs to your Developer Portal, It is powered by Drupal content type & custom field formatters.') . '</p>'; + $output = '<p>' . t('This module will provides API Docs to your Developer Portal, It is powered by Drupal content type, custom field formatters & views.') . '</p>'; $output .= '<h6>' . t('Features covered') . '</h6>'; $output .= '<ul>'; - $output .= '<li>' . t('API Docs Content type.') . '</li>'; - $output .= '<li>' . t('Redoc & Swagger UI Field Formatters.') . '</li>'; + $output .= '<li>' . t('API Docs module will provide API Docs Content type, Redoc & Swagger UI Field Formatters & API Docs View.') . '</li>'; + $output .= '<li>' . t('Admins can create API Docs with the help of API Docs content type, by filling out the API Doc Name, Description, Status & Open API Spec.') . '</li>'; + $output .= '<li>' . t('Users can see the List the published API Docs with the help of API Docs View.') . '</li>'; + $output .= '</ul>'; + $output .= '<h6>' . t('Installation') . '</h6>'; + $output .= '<p>' . t('Install as you would normally install a contributed Drupal module. For further information, see <a href="https://www.drupal.org/docs/extending-drupal/installing-drupal-modules" target="_blank">Installing Drupal Modules.</a>') . '</p>'; + $output .= '<h6>' . t('Configuration') . '</h6>'; + $output .= '<ul>'; + $output .= '<li>' . t('After enabling the module, navigate to Add API Docs <a href="/node/add/api_docs" target="_blank">/node/add/api_docs</a>.') . '</li>'; + $output .= '<ul>'; + $output .= '<li>' . t('Fill the API Doc Name, Description, Status & Open API Specification, Save the content by clicking Save.') . '</li>'; + $output .= '<li>' . t('Similarly, Admin will be able to create as many API Docs.') . '</li>'; + $output .= '</ul>'; + $output .= '</ul>'; + $output .= '<ul>'; + $output .= '<li>' . t('Navigate to API Docs via <a href="/api-docs" target="_blank">/api-docs</a>.') . '</li>'; + $output .= '<ul>'; + $output .= '<li>' . t('Users can see list of API Docs published in the site, with filter by API Doc Status, with minimal details of the API Doc.') . '</li>'; + $output .= '<li>' . t('Each API Doc in this list will have View Redoc UI & View Swagger UI, users will be able to navigate to respective API Doc pages.') . '</li>'; + $output .= '</ul>'; + $output .= '</ul>'; + $output .= '<h6>' . t('Customizations') . '</h6>'; + $output .= '<ul>'; + $output .= '<li>' . t('API Docs is providing a field formatters, Open API Field Formatter.') . '</li>'; + $output .= '<ul>'; + $output .= '<li>' . t('Open API field formatter can be used in for any file field type within your site') . '</li>'; + $output .= '<li>' . t('Open API field formatter, can render the file in two possible ways') . '</li>'; + $output .= '<ul>'; + $output .= '<li>' . t('One with Redoc UI format.') . '</li>'; + $output .= '<li>' . t('Other with Swagger UI format.') . '</li>'; + $output .= '</ul>'; + $output .= '</ul>'; + $output .= '<ul>'; + $output .= '<li>' . t('Admin will have the flexibility to change this configuration of the Open API field formatter.') . '</li>'; + $output .= '</ul>'; + $output .= '<li>' . t('API Docs is providing two View modes, they are Redoc UI & Swagger UI, these View modes are used in the API Docs content typs displays & API Docs View. If needed these can be customized at API Docs display level.') . '</li>'; $output .= '</ul>'; return $output; + default: } } diff --git a/config/install/views.view.api_docs.yml b/config/install/views.view.api_docs.yml index e70273f..58cb9ec 100644 --- a/config/install/views.view.api_docs.yml +++ b/config/install/views.view.api_docs.yml @@ -120,7 +120,7 @@ display: plugin_id: text empty: true content: - value: 'No API Docs found on this query.' + value: 'No API Docs found.' format: basic_html tokenize: false sorts: diff --git a/src/Plugin/Field/FieldFormatter/OpenApiDocFieldFormatter.php b/src/Plugin/Field/FieldFormatter/OpenApiDocFieldFormatter.php index 4244c3d..490b232 100644 --- a/src/Plugin/Field/FieldFormatter/OpenApiDocFieldFormatter.php +++ b/src/Plugin/Field/FieldFormatter/OpenApiDocFieldFormatter.php @@ -2,13 +2,13 @@ namespace Drupal\api_docs\Plugin\Field\FieldFormatter; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\File\FileUrlGeneratorInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'open_api_doc_field_formatter'. -- GitLab