diff --git a/src/api/api.c b/src/api/api.c index 2b79796d..8ee73feb 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -38,6 +38,7 @@ static struct { { "/api/ftl/maxhistory", api_ftl_maxhistory, { false, false } }, { "/api/ftl/gateway", api_ftl_gateway, { false, false } }, { "/api/ftl/interfaces", api_ftl_interfaces, { false, false } }, + { "/api/ftl/endpoints", api_endpoints, { false, false } }, { "/api/network", api_network, { false, false } }, { "/api/history/clients", api_history_clients, { false, false } }, { "/api/history", api_history, { false, false } }, @@ -63,7 +64,6 @@ static struct { { "/api/auth", api_auth, { false, false } }, { "/api/settings/web", api_settings_web, { false, false } }, { "/api/docs", api_docs, { false, false } }, - { "/api/endpoints", api_endpoints, { false, false } } }; #define API_ENDPOINTS "/api/endpoints" @@ -135,10 +135,15 @@ static int api_endpoints(struct ftl_conn *api) return send_json_unauthorized(api); } - cJSON *json = JSON_NEW_ARRAY(); + cJSON *json = JSON_NEW_OBJ(); + cJSON *endpoints = JSON_NEW_ARRAY(); + // Add endpoints to JSON array for(unsigned int i = 0; i < sizeof(api_request)/sizeof(api_request[0]); i++) - JSON_ARRAY_REF_STR(json, api_request[i].uri); + JSON_ARRAY_REF_STR(endpoints, api_request[i].uri); + + // Add endpoints to JSON object + JSON_OBJ_ADD_ITEM(json, "endpoints", endpoints); // Send response JSON_SEND_OBJECT_UNLOCK(json); diff --git a/src/api/docs/content/specs/dns.yaml b/src/api/docs/content/specs/dns.yaml index 693c1174..5b3937ad 100644 --- a/src/api/docs/content/specs/dns.yaml +++ b/src/api/docs/content/specs/dns.yaml @@ -103,8 +103,7 @@ components: content: application/json: schema: - allOf: - - $ref: '#/components/schemas/dns_port' + $ref: '#/components/schemas/dns_port' schemas: blocking: type: object diff --git a/src/api/docs/content/specs/ftl.yaml b/src/api/docs/content/specs/ftl.yaml index d0c4e9f0..22411727 100644 --- a/src/api/docs/content/specs/ftl.yaml +++ b/src/api/docs/content/specs/ftl.yaml @@ -92,6 +92,27 @@ components: schema: allOf: - $ref: '#/components/schemas/database' + endpoints: + get: + summary: Get list of available API endpoints + tags: + - "FTL information" + operationId: "get_endpoints" + description: | + This API hook returns the list of all available API endpoints. + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/endpoints' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: 'common.yaml#/components/errors/unauthorized' schemas: client: remote_addr: @@ -389,6 +410,15 @@ components: type: string description: Version of embedded SQLite3 engine example: "3.34.0" + endpoints: + type: object + properties: + endpoints: + type: array + description: Endpoints + items: + type: string + example: ["/api/dns/blocking", "/api/dns/cache", "/api/dns/port", "/api/domains", "/api/groups", "/api/lists"] parameters: logs: diff --git a/src/api/docs/content/specs/main.yaml b/src/api/docs/content/specs/main.yaml index 8aea06be..4d4489b7 100644 --- a/src/api/docs/content/specs/main.yaml +++ b/src/api/docs/content/specs/main.yaml @@ -107,6 +107,9 @@ paths: /ftl/dbinfo: $ref: 'ftl.yaml#/components/paths/dbinfo' + /ftl/endpoints: + $ref: 'ftl.yaml#/components/paths/endpoints' + /version: $ref: 'version.yaml#/components/paths/version'