The client API described in OpenAPI, and both APIs in Swagger UI
/v1/openapi.json is the API clients use — OpenAI's endpoints, Anthropic's, and what llmgw adds — in OpenAPI 3.1, generated from internal/clientapi's route table by the generator the admin API's document comes from, now told each document's title, server, token and error. A test reads the router's mux.HandleFunc calls and refuses a route described and not mounted, or mounted and not described. Asked for before there is a key, so it needs none. /docs/api shows it in Swagger UI 5.33.1 (Apache 2.0, served from the gateway as the page's policy requires): Authorize takes a key, Try it out sends to this gateway. Staff are offered the admin API's document too, from /docs/api/admin.json, which nobody else is given. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
41601bc5ef
commit
fd3c7bda32
26 files changed
+3956
-48
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/clientapi"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
|
||||
)
|
||||
|
||||
@@ -161,3 +162,39 @@ func TestAPathParameterWithNoDescriptionIsAnError(t *testing.T) {
|
||||
t.Error("a parameter nobody described was let through")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheClientAPIDocumentIsNotStaleAndDescribesWhatClientsSend(t *testing.T) {
|
||||
want, err := GenerateDoc(repoRoot(t), Client, clientapi.Routes, clientapi.PathParams)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := os.ReadFile(filepath.Join(repoRoot(t), "docs", "client-api.openapi.json"))
|
||||
if err != nil || string(got) != string(want) {
|
||||
t.Fatal("docs/client-api.openapi.json no longer matches the client API's routes and types.\n" +
|
||||
"Run: go generate ./internal/docgen")
|
||||
}
|
||||
var doc map[string]any
|
||||
if err := json.Unmarshal(want, &doc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
chat := at(t, doc, "paths", "/v1/chat/completions", "post")
|
||||
if at(t, chat, "requestBody", "content", "application/json", "schema", "$ref") != "#/components/schemas/ChatCompletionRequest" {
|
||||
t.Error("chat's body is not its request type")
|
||||
}
|
||||
if _, ok := at(t, chat, "responses", "200", "content").(map[string]any)["text/event-stream"]; !ok {
|
||||
t.Error("chat does not say it may stream")
|
||||
}
|
||||
if _, ok := at(t, doc, "paths", "/v1/files", "post", "requestBody", "content").(map[string]any)["multipart/form-data"]; !ok {
|
||||
t.Error("an upload is not a form")
|
||||
}
|
||||
if at(t, doc, "paths", "/v1/3d/generations", "post", "responses", "202", "description") == nil {
|
||||
t.Error("a 3D job is not answered 202")
|
||||
}
|
||||
if _, ok := at(t, doc, "components", "securitySchemes").(map[string]any)["apiKey"]; !ok {
|
||||
t.Error("no API key scheme")
|
||||
}
|
||||
// The admin API's actor header is the admin API's.
|
||||
if _, ok := at(t, doc, "components").(map[string]any)["parameters"]; ok {
|
||||
t.Error("the client API takes the admin API's X-Llmgw-Actor")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user