diff --git a/http/handler_acp.go b/http/handler_acp.go index a78f15bf4a..d359d5085e 100644 --- a/http/handler_acp.go +++ b/http/handler_acp.go @@ -105,23 +105,40 @@ func (s *acpHandler) DeleteDocActorRelationship(rw http.ResponseWriter, req *htt } func (h *acpHandler) bindRoutes(router *Router) { - successResponse := &openapi3.ResponseRef{ - Ref: "#/components/responses/success", - } errorResponse := &openapi3.ResponseRef{ Ref: "#/components/responses/error", } + acpPolicyAddResultSchema := &openapi3.SchemaRef{ + Ref: "#/components/schemas/acp_policy_add_result", + } + + acpRelationshipAddRequestSchema := &openapi3.SchemaRef{ + Ref: "#/components/schemas/acp_relationship_add_request", + } + acpRelationshipAddResultSchema := &openapi3.SchemaRef{ + Ref: "#/components/schemas/acp_relationship_add_result", + } + + acpRelationshipDeleteRequestSchema := &openapi3.SchemaRef{ + Ref: "#/components/schemas/acp_relationship_delete_request", + } + acpRelationshipDeleteResultSchema := &openapi3.SchemaRef{ + Ref: "#/components/schemas/acp_relationship_delete_result", + } + acpAddPolicyRequest := openapi3.NewRequestBody(). WithRequired(true). WithContent(openapi3.NewContentWithSchema(openapi3.NewStringSchema(), []string{"text/plain"})) - + acpPolicyAddResult := openapi3.NewResponse(). + WithDescription("Add acp policy result"). + WithJSONSchemaRef(acpPolicyAddResultSchema) acpAddPolicy := openapi3.NewOperation() acpAddPolicy.OperationID = "add policy" acpAddPolicy.Description = "Add a policy using acp system" acpAddPolicy.Tags = []string{"acp_policy"} acpAddPolicy.Responses = openapi3.NewResponses() - acpAddPolicy.Responses.Set("200", successResponse) + acpAddPolicy.AddResponse(200, acpPolicyAddResult) acpAddPolicy.Responses.Set("400", errorResponse) acpAddPolicy.RequestBody = &openapi3.RequestBodyRef{ Value: acpAddPolicyRequest, @@ -129,14 +146,16 @@ func (h *acpHandler) bindRoutes(router *Router) { acpAddDocActorRelationshipRequest := openapi3.NewRequestBody(). WithRequired(true). - WithContent(openapi3.NewContentWithSchema(openapi3.NewStringSchema(), []string{"text/plain"})) - + WithContent(openapi3.NewContentWithJSONSchemaRef(acpRelationshipAddRequestSchema)) + acpAddDocActorRelationshipResult := openapi3.NewResponse(). + WithDescription("Add acp relationship result"). + WithJSONSchemaRef(acpRelationshipAddResultSchema) acpAddDocActorRelationship := openapi3.NewOperation() acpAddDocActorRelationship.OperationID = "add relationship" acpAddDocActorRelationship.Description = "Add an actor relationship using acp system" acpAddDocActorRelationship.Tags = []string{"acp_relationship"} acpAddDocActorRelationship.Responses = openapi3.NewResponses() - acpAddDocActorRelationship.Responses.Set("200", successResponse) + acpAddDocActorRelationship.AddResponse(200, acpAddDocActorRelationshipResult) acpAddDocActorRelationship.Responses.Set("400", errorResponse) acpAddDocActorRelationship.RequestBody = &openapi3.RequestBodyRef{ Value: acpAddDocActorRelationshipRequest, @@ -144,14 +163,16 @@ func (h *acpHandler) bindRoutes(router *Router) { acpDeleteDocActorRelationshipRequest := openapi3.NewRequestBody(). WithRequired(true). - WithContent(openapi3.NewContentWithSchema(openapi3.NewStringSchema(), []string{"text/plain"})) - + WithContent(openapi3.NewContentWithJSONSchemaRef(acpRelationshipDeleteRequestSchema)) + acpDeleteDocActorRelationshipResult := openapi3.NewResponse(). + WithDescription("Delete acp relationship result"). + WithJSONSchemaRef(acpRelationshipDeleteResultSchema) acpDeleteDocActorRelationship := openapi3.NewOperation() acpDeleteDocActorRelationship.OperationID = "delete relationship" acpDeleteDocActorRelationship.Description = "Delete an actor relationship using acp system" acpDeleteDocActorRelationship.Tags = []string{"acp_relationship"} acpDeleteDocActorRelationship.Responses = openapi3.NewResponses() - acpDeleteDocActorRelationship.Responses.Set("200", successResponse) + acpDeleteDocActorRelationship.AddResponse(200, acpDeleteDocActorRelationshipResult) acpDeleteDocActorRelationship.Responses.Set("400", errorResponse) acpDeleteDocActorRelationship.RequestBody = &openapi3.RequestBodyRef{ Value: acpDeleteDocActorRelationshipRequest, diff --git a/http/openapi.go b/http/openapi.go index 0bb5f71743..0a62b6ebac 100644 --- a/http/openapi.go +++ b/http/openapi.go @@ -20,27 +20,32 @@ import ( // openApiSchemas is a mapping of types to auto generate schemas for. var openApiSchemas = map[string]any{ - "error": &errorResponse{}, - "create_tx": &CreateTxResponse{}, - "collection_update": &CollectionUpdateRequest{}, - "collection_delete": &CollectionDeleteRequest{}, - "peer_info": &peer.AddrInfo{}, - "graphql_request": &GraphQLRequest{}, - "backup_config": &client.BackupConfig{}, - "collection": &client.CollectionDescription{}, - "schema": &client.SchemaDescription{}, - "collection_definition": &client.CollectionDefinition{}, - "index": &client.IndexDescription{}, - "delete_result": &client.DeleteResult{}, - "update_result": &client.UpdateResult{}, - "lens_config": &client.LensConfig{}, - "replicator": &client.Replicator{}, - "ccip_request": &CCIPRequest{}, - "ccip_response": &CCIPResponse{}, - "patch_schema_request": &patchSchemaRequest{}, - "add_view_request": &addViewRequest{}, - "migrate_request": &migrateRequest{}, - "set_migration_request": &setMigrationRequest{}, + "error": &errorResponse{}, + "create_tx": &CreateTxResponse{}, + "collection_update": &CollectionUpdateRequest{}, + "collection_delete": &CollectionDeleteRequest{}, + "peer_info": &peer.AddrInfo{}, + "graphql_request": &GraphQLRequest{}, + "backup_config": &client.BackupConfig{}, + "collection": &client.CollectionDescription{}, + "schema": &client.SchemaDescription{}, + "collection_definition": &client.CollectionDefinition{}, + "index": &client.IndexDescription{}, + "delete_result": &client.DeleteResult{}, + "update_result": &client.UpdateResult{}, + "lens_config": &client.LensConfig{}, + "replicator": &client.Replicator{}, + "ccip_request": &CCIPRequest{}, + "ccip_response": &CCIPResponse{}, + "patch_schema_request": &patchSchemaRequest{}, + "add_view_request": &addViewRequest{}, + "migrate_request": &migrateRequest{}, + "set_migration_request": &setMigrationRequest{}, + "acp_policy_add_result": &client.AddPolicyResult{}, + "acp_relationship_add_request": &addDocActorRelationshipRequest{}, + "acp_relationship_add_result": &client.AddDocActorRelationshipResult{}, + "acp_relationship_delete_request": &deleteDocActorRelationshipRequest{}, + "acp_relationship_delete_result": &client.DeleteDocActorRelationshipResult{}, } func NewOpenAPISpec() (*openapi3.T, error) {