From 2150271c063c9f79faa11d5780d342355c6256de Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 13 Sep 2022 17:28:21 +0200 Subject: [PATCH] Configuring Sphinx --- docs/Makefile | 20 +++++ docs/conf.py | 54 ++++++++++++++ docs/index.rst | 82 +++++++++++++++++++++ docs/make.bat | 35 +++++++++ enunciate.xml | 2 +- pom.xml | 4 +- src/main/java/org/gcube/gcat/rest/Docs.java | 7 +- 7 files changed, 198 insertions(+), 6 deletions(-) create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..e85e51b --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,54 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'gCube Catalogue Service: gCat' +copyright = '2022, Luca Frosini (ISTI-CNR)' +author = 'Luca Frosini (ISTI-CNR)' + +# The full version, including alpha/beta/rc tags +release = '2.4.1-SNAPSHOT' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..8249786 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,82 @@ +.. Social Service Client documentation master file, created by + sphinx-quickstart on Tue Aug 2 16:11:12 2022. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + + +Welcome to gCat documentation! +================================================= +gCat is a RESTful application which exposes operations ... + +See the available REST-API on `its API docs <../api-docs/index.html>`_. + +Base URL +================== + +.. replace your base URL on production. + +In the production environment, its current value is https://api.d4science.org/ + + +Authorization +================== + +D4Science adopts state-of-the-art industry standards for authentication and authorization. +Specifically, the implementation fully adopts `OIDC (OpenID Connect) `_ for authentication and UMA 2 (User Managed Authorization) for authorization flows. +`JSON Web Token (JWT) Access token `_ are used for both authentication and authorization. + +Obtain your Bearer token here: https://dev.d4science.org/how-to-access-resources + +Java Client +================== + +The methods of the Web Service can be called by writing your own REST client application or by using already existing REST client plugins. We provide the following Java Client out-of-the-box. + + + .. TIP:: + If you're coding in Java it is recommended that you use this Java Client. + +**Maven Coordinates** + +.. code:: xml + + org.gcube.data-catalogue + gcat-client + (2.2.0, 3.0.0-SNAPSHOT) + +**Methods Result** + +The service exposes `its methods <../api/index.html>`_ using a standard naming approach. Moreover, they accept (in case of http POST/PUT methods) JSON objects. + + .. IMPORTANT:: + The result of all methods is always a JSON object as per below: + +.. code:: javascript + + { + "success": false/true, + "message": ..., + "result": ..., + } + +Where + - success reports if the request succeeded or failed; + - message is a status/error message that can be checked in case of errors (success equals false); + - result is the current result object (it can be a list, a single object and so on depending on the invoked method). + +*Inputs are automatically validated before the request is served.* + + +**Usage examples** + +- Example 1 + +.. code:: java + + import org.gcube.gcat.client.Item; + + // count item number +Item item = new Item(); +int count = item.count(); + ... + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..153be5e --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/enunciate.xml b/enunciate.xml index 4f38725..99d416a 100644 --- a/enunciate.xml +++ b/enunciate.xml @@ -13,7 +13,7 @@ - + target - ${project.build.directory}/${project.artifactId}-${project.version}/api - ${project.build.directory}/api + ${project.build.directory}/${project.artifactId}-${project.version}/api-docs + ${project.build.directory}/api-docs true diff --git a/src/main/java/org/gcube/gcat/rest/Docs.java b/src/main/java/org/gcube/gcat/rest/Docs.java index 769681d..075201d 100644 --- a/src/main/java/org/gcube/gcat/rest/Docs.java +++ b/src/main/java/org/gcube/gcat/rest/Docs.java @@ -18,7 +18,7 @@ import org.slf4j.LoggerFactory; * @author Francesco Mangiacrapa (ISTI-CNR) * @author Luca Frosini (ISTI-CNR) */ -@Path("docs") +@Path("api-docs") public class Docs { private static Logger logger = LoggerFactory.getLogger(Docs.class); @@ -26,15 +26,16 @@ public class Docs { @GET @Path("{any: .*}") public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException { + logger.trace("Called method to redirect to api-docs/index.html"); String pathInfo = req.getPathInfo(); try { - if (pathInfo.endsWith("/docs")) { + if (pathInfo.endsWith("/api-docs")) { pathInfo += "/index.html"; } - if (pathInfo.endsWith("/docs/")) { + if (pathInfo.endsWith("/api-docs/")) { pathInfo += "index.html"; }