diff --git a/api.php b/api.php
index a47868f..cf428ef 100644
--- a/api.php
+++ b/api.php
@@ -2,28 +2,32 @@
require_once(__DIR__ . '/global.php');
if (!array_key_exists('call', $_GET) && array_key_exists('swagger-spec', $_GET)) {
- $swagger_spec = array(
- 'swagger' => '2.0',
+ $openapi_spec = array(
+ 'openapi' => '3.1.0',
'info' => array(
'contact' => array(
'email' => UserConfig::$supportEmailFromEmail
),
'version' => UserConfig::$apiSpecVersion
),
- 'basePath' => UserConfig::$USERSROOTURL . '/api.php'
+ 'servers' => array(
+ array(
+ "url" => UserConfig::$USERSROOTURL . '/api.php'
+ )
+ )
);
if (UserConfig::$appName) {
- $swagger_spec['info']['title'] = UserConfig::$appName;
+ $openapi_spec['info']['title'] = UserConfig::$appName . " API";
}
if (UserConfig::$termsOfServiceFullURL) {
- $swagger_spec['info']['termsOfService'] = UserConfig::$termsOfServiceFullURL;
+ $openapi_spec['info']['termsOfService'] = UserConfig::$termsOfServiceFullURL;
}
// Swagger tags, e.g. API namespaces
foreach (\StartupAPI\API\Endpoint::getNamespaces() as $namespace) {
- $swagger_spec['tags'][] = array(
+ $openapi_spec['tags'][] = array(
'name' => $namespace->getSlug(),
'description' => $namespace->getName()
);
@@ -43,39 +47,65 @@
'operationId' => get_class($endpoint),
'responses' => array(
'200' => array(
- 'description' => 'success'
+ 'description' => 'success',
+ 'content' => array(
+ 'application/json' => array(
+ 'schema' => array(
+ 'type' => 'object'
+ )
+ )
+ )
),
'400' => array(
'description' => 'invalid input'
)
- )
+ ),
);
- $params = $endpoint->getParams();
+ $request_body_properties = array();
+ $query_parameters = array();
+ $params = $endpoint->getParams();
foreach ($params as $name => $param) {
- $param_spec = array(
+ $property = array(
'name' => $name,
'description' => $param->getDescription(),
'required' => !$param->isOptional()
);
if ($method === 'GET') {
- $param_spec['in'] = 'query';
+ $property['in'] = 'query';
+ $property['schema'] = array(
+ 'type' => $param->getType()
+ );
+ $query_parameters[] = $property;
} else {
- $param_spec['in'] = 'formData';
+ if ($param->allowsMultipleValues()) {
+ $property['type'] = 'array';
+ // $param_spec['collectionFormat'] = 'multi';
+ } else {
+ $property['type'] = $param->getType();
+ }
+ $request_body_properties[$name] = $property;
}
+ }
- if ($param->allowsMultipleValues()) {
- $param_spec['type'] = 'array';
- $param_spec['collectionFormat'] = 'multi';
- } else {
- $param_spec['type'] = $param->getType();
- }
- $operation['parameters'][] = $param_spec;
+ if ($method === 'GET') {
+ $operation["parameters"] = $query_parameters;
+ } else {
+ $operation["requestBody"] = array (
+ 'content' => array(
+ "application/x-www-form-urlencoded" => array(
+ 'schema' => array(
+ "type" => "object",
+ "properties" => $request_body_properties
+ )
+ )
+ )
+ );
}
- $swagger_spec['paths']
+ $openapi_spec['paths']
["/api.php?call=/$namespace_slug$endpoint_slug"]
[strtolower($method)] = $operation;
}
@@ -83,7 +113,7 @@
}
header('Content-type: application/json');
- echo json_encode($swagger_spec);
+ echo json_encode($openapi_spec);
if (json_last_error() !== JSON_ERROR_NONE) {
header('HTTP/1.1 400 Bad Request');
diff --git a/swagger-ui b/swagger-ui
index 4b0e8a8..8eeb77f 160000
--- a/swagger-ui
+++ b/swagger-ui
@@ -1 +1 @@
-Subproject commit 4b0e8a860909499a5b6fc2ad54e99f5e41a1dbfb
+Subproject commit 8eeb77fc82001d7e9f8e07c8dcdc9415a6c129bb
diff --git a/themes/awesome/templates/swagger-ui.html.twig b/themes/awesome/templates/swagger-ui.html.twig
index 24e2252..440a0e1 100644
--- a/themes/awesome/templates/swagger-ui.html.twig
+++ b/themes/awesome/templates/swagger-ui.html.twig
@@ -10,7 +10,7 @@
-
+