From 8dd07fb6d51fdfe6a40f1306839c495eef24aecf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Mar 2021 14:30:47 +0100 Subject: [PATCH] NEW The swagger.json file of API can be included into external sources --- htdocs/api/index.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 2ed7d2e08f8..880d3263aaa 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -55,6 +55,12 @@ if (!empty($_SERVER['HTTP_DOLAPIENTITY'])) { define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); } +// When we request url to get the json file, we accept Cross site so we can include the descriptor into an external tool. +if (preg_match('/\/explorer\/swagger\.json/', $_SERVER["PHP_SELF"])) { + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); + header('Access-Control-Allow-Headers: Content-Type, Authorization, api_key, DOLAPIKEY'); +} $res = 0; if (!$res && file_exists("../main.inc.php")) {