-
Notifications
You must be signed in to change notification settings - Fork 242
Fix: Provide clear error when filename is missing on /data endpoint (Fixes #220) #1705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
Comment on lines
+28
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These remind me of sprint boot tags, where did you get these from? |
||
| var patchUpdateIdentity = &ffapi.Route{ | ||
| Name: "patchUpdateIdentity", | ||
| Path: "identities/{iid}", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
|
Comment on lines
+62
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarity this is what changed |
||
| 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 | ||
| }, | ||
| }, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? |
||
| "swagger": "2.0", | ||
| "info": { | ||
| "contact": {} | ||
| }, | ||
| "paths": {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| info: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| contact: {} | ||
| paths: {} | ||
| swagger: "2.0" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto it would be significant decisions to bring in a DSL for describing APIs since we already have within ffapi the ability to describe the API and transform it to an OpenAPI document