62 lines
2.6 KiB
Go
62 lines
2.6 KiB
Go
package api
|
|
|
|
import "git.threesix.ai/jordan/slack5-1770606136/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 the preferences-api service - manages user preferences").
|
|
WithTag("Health", "Service health endpoints").
|
|
WithTag("Preferences", "User preference endpoints")
|
|
|
|
// Define reusable schemas
|
|
spec.WithSchema("UserPreferences", openapi.Object(map[string]openapi.Schema{
|
|
"user_id": openapi.UUID().WithDescription("User identifier"),
|
|
"preferences": openapi.Object(map[string]openapi.Schema{}).WithDescription("Key-value preference pairs"),
|
|
"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{}).WithDescription("Key-value preference pairs to set"),
|
|
}, "preferences"))
|
|
|
|
// 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. Returns empty preferences object if user has none.",
|
|
"tags": []string{"Preferences"},
|
|
"parameters": []any{openapi.PathParam("user_id", "User UUID")},
|
|
"responses": map[string]any{
|
|
"200": openapi.OpResponse("Success", openapi.ResponseSchema(openapi.Ref("UserPreferences"))),
|
|
"400": openapi.OpResponse("Invalid user_id format", openapi.ErrorResponseSchema()),
|
|
},
|
|
})
|
|
|
|
// Update preferences
|
|
spec.AddPath("/api/preferences-api/preferences/{user_id}", "put", map[string]any{
|
|
"summary": "Update user preferences",
|
|
"description": "Creates or updates preferences for a user. Merges with existing preferences.",
|
|
"tags": []string{"Preferences"},
|
|
"parameters": []any{openapi.PathParam("user_id", "User UUID")},
|
|
"requestBody": openapi.RequestBody(openapi.Ref("UpdatePreferencesRequest"), true),
|
|
"responses": map[string]any{
|
|
"200": openapi.OpResponse("Updated", openapi.ResponseSchema(openapi.Ref("UserPreferences"))),
|
|
"400": openapi.OpResponse("Validation error", openapi.ErrorResponseSchema()),
|
|
},
|
|
})
|
|
|
|
return spec
|
|
}
|