feat(cmd/api): add SSE path spec flags

Wire "--sse-path" through the spec and SDK generators so standalone OpenAPI output can document the SSE endpoint alongside GraphQL.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 01:55:13 +00:00
parent 085c57a06d
commit b4d414b702
3 changed files with 54 additions and 2 deletions

View file

@ -33,6 +33,7 @@ func addSDKCommand(parent *cli.Command) {
description string
version string
graphqlPath string
ssePath string
termsURL string
contactName string
contactURL string
@ -52,7 +53,7 @@ func addSDKCommand(parent *cli.Command) {
// If no spec file provided, generate one to a temp file.
if specFile == "" {
builder := sdkSpecBuilder(title, description, version, graphqlPath, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers)
builder := sdkSpecBuilder(title, description, version, graphqlPath, ssePath, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers)
groups := sdkSpecGroupsIter()
tmpFile, err := os.CreateTemp("", "openapi-*.json")
@ -102,6 +103,7 @@ func addSDKCommand(parent *cli.Command) {
cli.StringFlag(cmd, &description, "description", "d", defaultSDKDescription, "API description in generated spec")
cli.StringFlag(cmd, &version, "version", "V", defaultSDKVersion, "API version in generated spec")
cli.StringFlag(cmd, &graphqlPath, "graphql-path", "", "", "GraphQL endpoint path in generated spec")
cli.StringFlag(cmd, &ssePath, "sse-path", "", "", "SSE endpoint path in generated spec")
cli.StringFlag(cmd, &termsURL, "terms-of-service", "", "", "OpenAPI terms of service URL in generated spec")
cli.StringFlag(cmd, &contactName, "contact-name", "", "", "OpenAPI contact name in generated spec")
cli.StringFlag(cmd, &contactURL, "contact-url", "", "", "OpenAPI contact URL in generated spec")
@ -115,12 +117,13 @@ func addSDKCommand(parent *cli.Command) {
parent.AddCommand(cmd)
}
func sdkSpecBuilder(title, description, version, graphqlPath, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers string) *goapi.SpecBuilder {
func sdkSpecBuilder(title, description, version, graphqlPath, ssePath, termsURL, contactName, contactURL, contactEmail, licenseName, licenseURL, externalDocsDescription, externalDocsURL, servers string) *goapi.SpecBuilder {
return &goapi.SpecBuilder{
Title: title,
Description: description,
Version: version,
GraphQLPath: graphqlPath,
SSEPath: ssePath,
TermsOfService: termsURL,
ContactName: contactName,
ContactURL: contactURL,

View file

@ -19,6 +19,7 @@ func addSpecCommand(parent *cli.Command) {
description string
version string
graphqlPath string
ssePath string
termsURL string
contactName string
contactURL string
@ -37,6 +38,7 @@ func addSpecCommand(parent *cli.Command) {
Description: description,
Version: version,
GraphQLPath: graphqlPath,
SSEPath: ssePath,
TermsOfService: termsURL,
ContactName: contactName,
ContactURL: contactURL,
@ -68,6 +70,7 @@ func addSpecCommand(parent *cli.Command) {
cli.StringFlag(cmd, &description, "description", "d", "Lethean Core API", "API description in spec")
cli.StringFlag(cmd, &version, "version", "V", "1.0.0", "API version in spec")
cli.StringFlag(cmd, &graphqlPath, "graphql-path", "", "", "GraphQL endpoint path in generated spec")
cli.StringFlag(cmd, &ssePath, "sse-path", "", "", "SSE endpoint path in generated spec")
cli.StringFlag(cmd, &termsURL, "terms-of-service", "", "", "OpenAPI terms of service URL in spec")
cli.StringFlag(cmd, &contactName, "contact-name", "", "", "OpenAPI contact name in spec")
cli.StringFlag(cmd, &contactURL, "contact-url", "", "", "OpenAPI contact URL in spec")

View file

@ -85,6 +85,9 @@ func TestAPISpecCmd_Good_JSON(t *testing.T) {
if specCmd.Flag("graphql-path") == nil {
t.Fatal("expected --graphql-path flag on spec command")
}
if specCmd.Flag("sse-path") == nil {
t.Fatal("expected --sse-path flag on spec command")
}
if specCmd.Flag("terms-of-service") == nil {
t.Fatal("expected --terms-of-service flag on spec command")
}
@ -441,6 +444,42 @@ func TestAPISpecCmd_Good_GraphQLPathPopulatesSpec(t *testing.T) {
}
}
func TestAPISpecCmd_Good_SSEPathPopulatesSpec(t *testing.T) {
root := &cli.Command{Use: "root"}
AddAPICommands(root)
outputFile := t.TempDir() + "/spec.json"
root.SetArgs([]string{
"api", "spec",
"--sse-path", "/events",
"--output", outputFile,
})
root.SetErr(new(bytes.Buffer))
if err := root.Execute(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
data, err := os.ReadFile(outputFile)
if err != nil {
t.Fatalf("expected spec file to be written: %v", err)
}
var spec map[string]any
if err := json.Unmarshal(data, &spec); err != nil {
t.Fatalf("expected valid JSON spec, got error: %v", err)
}
paths, ok := spec["paths"].(map[string]any)
if !ok {
t.Fatalf("expected paths object in generated spec, got %T", spec["paths"])
}
if _, ok := paths["/events"]; !ok {
t.Fatal("expected SSE path to be included in generated spec")
}
}
func TestAPISDKCmd_Bad_EmptyLanguages(t *testing.T) {
root := &cli.Command{Use: "root"}
AddAPICommands(root)
@ -510,6 +549,9 @@ func TestAPISDKCmd_Good_ValidatesLanguage(t *testing.T) {
if sdkCmd.Flag("graphql-path") == nil {
t.Fatal("expected --graphql-path flag on sdk command")
}
if sdkCmd.Flag("sse-path") == nil {
t.Fatal("expected --sse-path flag on sdk command")
}
if sdkCmd.Flag("terms-of-service") == nil {
t.Fatal("expected --terms-of-service flag on sdk command")
}
@ -548,6 +590,7 @@ func TestAPISDKCmd_Good_TempSpecUsesMetadataFlags(t *testing.T) {
"Custom SDK description",
"9.9.9",
"/gql",
"/events",
"https://example.com/terms",
"SDK Support",
"https://example.com/support",
@ -596,6 +639,9 @@ func TestAPISDKCmd_Good_TempSpecUsesMetadataFlags(t *testing.T) {
if _, ok := paths["/gql"]; !ok {
t.Fatal("expected GraphQL path to be included in generated spec")
}
if _, ok := paths["/events"]; !ok {
t.Fatal("expected SSE path to be included in generated spec")
}
if info["termsOfService"] != "https://example.com/terms" {
t.Fatalf("expected termsOfService to be preserved, got %v", info["termsOfService"])