OpenAPI规范

返回 Glue2 网关的 OpenAPI 规范。

描述

此端点提供 OpenAPI 3.0 规范文档,描述网关暴露的所有路由、请求格式和响应模式。该规范从路由定义自动生成。

身份验证

无。此端点为公开端点。

请求

无需请求体。

示例

curl -X GET "https://api.hola.cloud/openapi.json"
GET /openapi.json HTTP/1.1
Host: api.hola.cloud
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	req, err := http.NewRequest("GET", "https://api.hola.cloud/openapi.json", nil)
	if err != nil {
		panic(err)
	}

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/openapi.json',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

response = requests.request(
    "GET",
    "https://api.hola.cloud/openapi.json"
)

print(response.text)
const response = await fetch("https://api.hola.cloud/openapi.json", {
  method: "GET"
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/openapi.json", {
  method: "GET"
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/openapi.json"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

响应

 1{
 2  "openapi": "3.0.3",
 3  "info": {
 4    "title": "Glue2 API Gateway",
 5    "version": "2.3.1",
 6    "description": "HolaCloud 服务的中央 API 网关"
 7  },
 8  "paths": {
 9    "/version": {
10      "get": {
11        "summary": "获取网关版本",
12        "responses": {
13          "200": {
14            "description": "版本信息"
15          }
16        }
17      }
18    },
19    "/v0/virtualhosts": {
20      "get": {
21        "summary": "列出虚拟主机",
22        "responses": {
23          "200": {
24            "description": "路由表"
25          }
26        }
27      }
28    },
29    "/v0/stats": {
30      "get": {
31        "summary": "获取流量统计",
32        "responses": {
33          "200": {
34            "description": "流量统计信息"
35          }
36        }
37      }
38    },
39    "/v0/status": {
40      "get": {
41        "summary": "后端健康状态",
42        "responses": {
43          "200": {
44            "description": "服务状态"
45          }
46        }
47      }
48    }
49  }
50}

错误码

状态码 描述
200 成功返回 OpenAPI 规范

评论

发表评论