package api import "git.threesix.ai/jordan/slate-v3-1770514618/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 managing user preferences"). WithBearerSecurity("bearer", "JWT authentication token"). WithTag("Health", "Service health endpoints"). WithTag("Preferences", "User preferences endpoints") // Schemas spec.WithSchema("NotificationSettings", openapi.Object(map[string]openapi.Schema{ "email": openapi.Bool().WithDescription("Email notifications enabled"), "push": openapi.Bool().WithDescription("Push notifications enabled"), "digest": openapi.StringEnum("daily", "weekly", "never").WithDescription("Digest frequency"), })) spec.WithSchema("Preferences", openapi.Object(map[string]openapi.Schema{ "user_id": openapi.UUID().WithDescription("User identifier"), "preferences": openapi.Object(map[string]openapi.Schema{ "theme": openapi.StringEnum("light", "dark", "system").WithDescription("UI theme"), "language": openapi.String().WithDescription("ISO 639-1 language code").WithPattern("^[a-z]{2}$").WithExample("en"), "notifications": openapi.Ref("NotificationSettings"), }), "updated_at": openapi.DateTime().WithDescription("Last update timestamp"), }, "user_id", "preferences", "updated_at")) spec.WithSchema("UpdatePreferencesRequest", openapi.Object(map[string]openapi.Schema{ "preferences": openapi.Object(map[string]openapi.Schema{ "theme": openapi.StringEnum("light", "dark", "system").WithDescription("UI theme"), "language": openapi.String().WithDescription("ISO 639-1 language code").WithPattern("^[a-z]{2}$"), "notifications": openapi.Object(map[string]openapi.Schema{ "email": openapi.Bool().WithDescription("Email notifications enabled"), "push": openapi.Bool().WithDescription("Push notifications enabled"), "digest": openapi.StringEnum("daily", "weekly", "never").WithDescription("Digest frequency"), }), }), }, "preferences")) userIDParam := openapi.PathParamWithSchema("user_id", "User identifier (UUID)", openapi.UUID()) // 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(), })), }, }) // Get preferences spec.AddPath("/api/preferences-api/preferences/{user_id}", "get", map[string]any{ "summary": "Get user preferences", "description": "Returns all preferences for a user. Requires authentication.", "tags": []string{"Preferences"}, "security": []map[string][]string{{"bearer": {}}}, "parameters": []any{userIDParam}, "responses": map[string]any{ "200": openapi.OpResponse("Success", openapi.ResponseSchema(openapi.Ref("Preferences"))), "400": openapi.OpResponse("Bad request", openapi.ErrorResponseSchema()), "401": openapi.OpResponse("Unauthorized", openapi.ErrorResponseSchema()), "403": openapi.OpResponse("Forbidden", openapi.ErrorResponseSchema()), "404": openapi.OpResponse("Not found", openapi.ErrorResponseSchema()), }, }) // Update preferences spec.AddPath("/api/preferences-api/preferences/{user_id}", "put", map[string]any{ "summary": "Create or update user preferences", "description": "Creates or updates preferences for a user with merge semantics. Requires authentication.", "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("Success", openapi.ResponseSchema(openapi.Ref("Preferences"))), "400": openapi.OpResponse("Bad request", openapi.ErrorResponseSchema()), "401": openapi.OpResponse("Unauthorized", openapi.ErrorResponseSchema()), "403": openapi.OpResponse("Forbidden", openapi.ErrorResponseSchema()), }, }) return spec }