Skip to content

Commit

Permalink
PR(ADHERE-REVIEW): Fix the open api schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Oct 3, 2024
1 parent 42d4dd4 commit 046882d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
43 changes: 32 additions & 11 deletions http/handler_acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,53 +105,74 @@ 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,
}

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,
}

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,
Expand Down
47 changes: 26 additions & 21 deletions http/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 046882d

Please sign in to comment.