package api import "git.threesix.ai/jordan/slack5-1770574304/pkg/openapi" // NewServiceSpec builds the OpenAPI specification for the preferences-api service. func NewServiceSpec() *openapi.OpenAPISpec { spec := openapi.NewOpenAPISpec("preferences-api API", "1.0.0"). WithDescription("REST API for user preferences management"). WithBearerSecurity("bearer", "JWT authentication token"). WithTag("Health", "Service health endpoints"). WithTag("Preferences", "User preference endpoints") // Define reusable schemas spec.WithSchema("NotificationPreferences", openapi.Object(map[string]openapi.Schema{ "email": openapi.Bool().WithDescription("Email notifications enabled"), "push": openapi.Bool().WithDescription("Push notifications enabled"), "digest": openapi.StringEnum("none", "daily", "weekly").WithDescription("Digest frequency"), }, "email", "push", "digest")) spec.WithSchema("UserPreferences", openapi.Object(map[string]openapi.Schema{ "user_id": openapi.String().WithDescription("User identifier"), "theme": openapi.StringEnum("light", "dark", "system").WithDescription("UI theme"), "language": openapi.StringEnum("en", "fr", "es", "de", "ja").WithDescription("Language (BCP-47)"), "notifications": openapi.Ref("NotificationPreferences"), "updated_at": openapi.DateTime().WithDescription("Last update timestamp"), }, "user_id", "theme", "language", "notifications")) spec.WithSchema("UpdatePreferencesRequest", openapi.Object(map[string]openapi.Schema{ "theme": openapi.StringEnum("light", "dark", "system").WithDescription("UI theme"), "language": openapi.StringEnum("en", "fr", "es", "de", "ja").WithDescription("Language (BCP-47)"), "notifications": openapi.Ref("NotificationPreferences"), }, "theme", "language", "notifications")) // Health spec.AddPath("/api/preferences-api/health", "get", map[string]any{ "summary": "Health check", "tags": []string{"Health"}, "responses": map[string]any{ "200": openapi.OpResponse("Service is healthy", openapi.Object(map[string]openapi.Schema{ "service": openapi.String(), "status": openapi.String(), })), }, }) userIDParam := openapi.PathParam("user_id", "User identifier") // Get preferences spec.AddPath("/api/preferences-api/preferences/{user_id}", "get", map[string]any{ "summary": "Get user preferences", "description": "Returns preferences for the specified user. Returns defaults if none are saved. Admins may read any user's preferences.", "tags": []string{"Preferences"}, "security": []map[string][]string{{"bearer": {}}}, "parameters": []any{userIDParam}, "responses": map[string]any{ "200": openapi.OpResponse("Success", openapi.ResponseSchema(openapi.Ref("UserPreferences"))), "401": openapi.OpResponse("Unauthorized", openapi.ErrorResponseSchema()), "403": openapi.OpResponse("Forbidden", openapi.ErrorResponseSchema()), }, }) // Update preferences spec.AddPath("/api/preferences-api/preferences/{user_id}", "put", map[string]any{ "summary": "Update user preferences", "description": "Creates or fully replaces preferences for the specified user (upsert). Self-access only.", "tags": []string{"Preferences"}, "security": []map[string][]string{{"bearer": {}}}, "parameters": []any{userIDParam}, "requestBody": openapi.RequestBody(openapi.Ref("UpdatePreferencesRequest"), true), "responses": map[string]any{ "200": openapi.OpResponse("Updated", openapi.ResponseSchema(openapi.Ref("UserPreferences"))), "400": openapi.OpResponse("Bad request", openapi.ErrorResponseSchema()), "401": openapi.OpResponse("Unauthorized", openapi.ErrorResponseSchema()), "403": openapi.OpResponse("Forbidden", openapi.ErrorResponseSchema()), }, }) return spec }