diff --git a/internal/apiserver/route_get_identity_by_id.go b/internal/apiserver/route_get_identity_by_id.go index f48968299..14da11e82 100644 --- a/internal/apiserver/route_get_identity_by_id.go +++ b/internal/apiserver/route_get_identity_by_id.go @@ -25,6 +25,13 @@ import ( "github.com/hyperledger/firefly/pkg/core" ) +// @Summary Get identity by ID +// @ID getIdentityByID +// @Tags identities +// @Produce json +// @Param iid path string true "Identity ID" +// @Success 200 {object} core.Identity +// @Router /identities/{iid} [get] var getIdentityByID = &ffapi.Route{ Name: "getIdentityByID", Path: "identities/{iid}", diff --git a/internal/apiserver/route_patch_update_identity.go b/internal/apiserver/route_patch_update_identity.go index 46ec71e84..6767cdb7f 100644 --- a/internal/apiserver/route_patch_update_identity.go +++ b/internal/apiserver/route_patch_update_identity.go @@ -25,6 +25,15 @@ import ( "github.com/hyperledger/firefly/pkg/core" ) +// @Summary Update an identity +// @ID patchUpdateIdentity +// @Tags identities +// @Accept json +// @Produce json +// @Param iid path string true "Identity ID" <-- THE CRITICAL FIX +// @Param body body core.IdentityUpdateDTO true "Identity update details" +// @Success 202 {object} core.Identity +// @Router /identities/{iid} [patch] var patchUpdateIdentity = &ffapi.Route{ Name: "patchUpdateIdentity", Path: "identities/{iid}", diff --git a/internal/apiserver/route_post_data.go b/internal/apiserver/route_post_data.go index faa6ccb61..22da62244 100644 --- a/internal/apiserver/route_post_data.go +++ b/internal/apiserver/route_post_data.go @@ -1,87 +1,90 @@ -// Copyright © 2022 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package apiserver - -import ( - "encoding/json" - "fmt" - "net/http" - "strings" - - "github.com/hyperledger/firefly-common/pkg/ffapi" - "github.com/hyperledger/firefly-common/pkg/fftypes" - "github.com/hyperledger/firefly-common/pkg/i18n" - "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/internal/orchestrator" - "github.com/hyperledger/firefly/pkg/core" -) - -var postData = &ffapi.Route{ - Name: "postData", - Path: "data", - Method: http.MethodPost, - PathParams: nil, - QueryParams: nil, - FormParams: []*ffapi.FormParam{ - {Name: "autometa", Description: coremsgs.APIParamsAutometa}, - {Name: "metadata", Description: coremsgs.APIParamsMetadata}, - {Name: "validator", Description: coremsgs.APIParamsValidator}, - {Name: "datatype.name", Description: coremsgs.APIParamsDatatypeName}, - {Name: "datatype.version", Description: coremsgs.APIParamsDatatypeVersion}, - }, - Description: coremsgs.APIEndpointsPostData, - JSONInputValue: func() interface{} { return &core.DataRefOrValue{} }, - JSONOutputValue: func() interface{} { return &core.Data{} }, - JSONOutputCodes: []int{http.StatusCreated}, - Extensions: &coreExtensions{ - EnabledIf: func(or orchestrator.Orchestrator) bool { - return or.Data() != nil - }, - CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - output, err = cr.or.Data().UploadJSON(cr.ctx, r.Input.(*core.DataRefOrValue)) - return output, err - }, - CoreFormUploadHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - if !cr.or.Data().BlobsEnabled() { - return nil, i18n.NewError(r.Req.Context(), coremsgs.MsgActionNotSupported) - } - - data := &core.DataRefOrValue{} - validator := r.FP["validator"] - if len(validator) > 0 { - data.Validator = core.ValidatorType(validator) - } - if r.FP["datatype.name"] != "" { - data.Datatype = &core.DatatypeRef{ - Name: r.FP["datatype.name"], - Version: r.FP["datatype.version"], - } - } - metadata := r.FP["metadata"] - if len(metadata) > 0 { - // The metadata might be JSON, or just a simple string. Try to unmarshal and see - var marshalCheck interface{} - if err := json.Unmarshal([]byte(metadata), &marshalCheck); err != nil { - metadata = fmt.Sprintf(`"%s"`, metadata) - } - data.Value = fftypes.JSONAnyPtr(metadata) - } - output, err = cr.or.Data().UploadBlob(cr.ctx, data, r.Part, strings.EqualFold(r.FP["autometa"], "true")) - return output, err - }, - }, -} +// Copyright © 2022 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package apiserver + +import ( + "encoding/json" + "fmt" + "net/http" + "strings" + + "github.com/hyperledger/firefly-common/pkg/ffapi" + "github.com/hyperledger/firefly-common/pkg/fftypes" + "github.com/hyperledger/firefly-common/pkg/i18n" + "github.com/hyperledger/firefly/internal/coremsgs" + "github.com/hyperledger/firefly/internal/orchestrator" + "github.com/hyperledger/firefly/pkg/core" +) + +var postData = &ffapi.Route{ + Name: "postData", + Path: "data", + Method: http.MethodPost, + PathParams: nil, + QueryParams: nil, + FormParams: []*ffapi.FormParam{ + {Name: "autometa", Description: coremsgs.APIParamsAutometa}, + {Name: "metadata", Description: coremsgs.APIParamsMetadata}, + {Name: "validator", Description: coremsgs.APIParamsValidator}, + {Name: "datatype.name", Description: coremsgs.APIParamsDatatypeName}, + {Name: "datatype.version", Description: coremsgs.APIParamsDatatypeVersion}, + }, + Description: coremsgs.APIEndpointsPostData, + JSONInputValue: func() interface{} { return &core.DataRefOrValue{} }, + JSONOutputValue: func() interface{} { return &core.Data{} }, + JSONOutputCodes: []int{http.StatusCreated}, + Extensions: &coreExtensions{ + EnabledIf: func(or orchestrator.Orchestrator) bool { + return or.Data() != nil + }, + CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { + output, err = cr.or.Data().UploadJSON(cr.ctx, r.Input.(*core.DataRefOrValue)) + return output, err + }, + CoreFormUploadHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { + if !cr.or.Data().BlobsEnabled() { + return nil, i18n.NewError(r.Req.Context(), coremsgs.MsgActionNotSupported) + } + // Check for file upload + if r.Part == nil || r.Part.FileName() == "" { + return nil, i18n.NewError(r.Req.Context(), coremsgs.MsgMissingFileUpload) + } + data := &core.DataRefOrValue{} + validator := r.FP["validator"] + if len(validator) > 0 { + data.Validator = core.ValidatorType(validator) + } + if r.FP["datatype.name"] != "" { + data.Datatype = &core.DatatypeRef{ + Name: r.FP["datatype.name"], + Version: r.FP["datatype.version"], + } + } + metadata := r.FP["metadata"] + if len(metadata) > 0 { + // The metadata might be JSON, or just a simple string. Try to unmarshal and see + var marshalCheck interface{} + if err := json.Unmarshal([]byte(metadata), &marshalCheck); err != nil { + metadata = fmt.Sprintf(`"%s"`, metadata) + } + data.Value = fftypes.JSONAnyPtr(metadata) + } + output, err = cr.or.Data().UploadBlob(cr.ctx, data, r.Part, strings.EqualFold(r.FP["autometa"], "true")) + return output, err + }, + }, +} diff --git a/internal/swagger/docs.go b/internal/swagger/docs.go new file mode 100644 index 000000000..3a76740b3 --- /dev/null +++ b/internal/swagger/docs.go @@ -0,0 +1,36 @@ +// Package swagger Code generated by swaggo/swag at 2025-10-10 07:17:54.1777731 +0530 IST m=+84.795132601. DO NOT EDIT +package swagger + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": {} +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "", + Host: "", + BasePath: "", + Schemes: []string{}, + Title: "", + Description: "", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/internal/swagger/swagger.json b/internal/swagger/swagger.json new file mode 100644 index 000000000..ec416cd4a --- /dev/null +++ b/internal/swagger/swagger.json @@ -0,0 +1,7 @@ +{ + "swagger": "2.0", + "info": { + "contact": {} + }, + "paths": {} +} \ No newline at end of file diff --git a/internal/swagger/swagger.yaml b/internal/swagger/swagger.yaml new file mode 100644 index 000000000..b64379cad --- /dev/null +++ b/internal/swagger/swagger.yaml @@ -0,0 +1,4 @@ +info: + contact: {} +paths: {} +swagger: "2.0"