Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,118 @@ paths:
description: Success
default:
description: ""
/namespaces/{ns}/contracts/interfaces/generate:
post:
description: 'TODO: Description'
operationId: postGenerateContractInterface
parameters:
- description: 'TODO: Description'
in: path
name: ns
required: true
schema:
example: default
type: string
- description: Server-side request timeout (millseconds, or set a custom suffix
like 10s)
in: header
name: Request-Timeout
schema:
default: 120s
type: string
requestBody:
content:
application/json:
schema:
properties:
description:
type: string
input:
type: string
name:
type: string
namespace:
type: string
version:
type: string
type: object
responses:
"200":
content:
application/json:
schema:
properties:
description:
type: string
events:
items:
properties:
contract: {}
description:
type: string
id: {}
name:
type: string
namespace:
type: string
params:
items:
properties:
name:
type: string
schema:
type: string
type: object
type: array
pathname:
type: string
type: object
type: array
id: {}
message: {}
methods:
items:
properties:
contract: {}
description:
type: string
id: {}
name:
type: string
namespace:
type: string
params:
items:
properties:
name:
type: string
schema:
type: string
type: object
type: array
pathname:
type: string
returns:
items:
properties:
name:
type: string
schema:
type: string
type: object
type: array
type: object
type: array
name:
type: string
namespace:
type: string
version:
type: string
type: object
description: Success
default:
description: ""
/namespaces/{ns}/contracts/invoke:
post:
description: 'TODO: Description'
Expand Down
46 changes: 46 additions & 0 deletions internal/apiserver/route_post_contract_interface_generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 (
"net/http"

"github.com/hyperledger/firefly/internal/config"
"github.com/hyperledger/firefly/internal/i18n"
"github.com/hyperledger/firefly/internal/oapispec"
"github.com/hyperledger/firefly/pkg/fftypes"
)

var postContractInterfaceGenerate = &oapispec.Route{
Name: "postGenerateContractInterface",
Path: "namespaces/{ns}/contracts/interfaces/generate",
Method: http.MethodPost,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{},
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.FFIGenerationRequest{} },
JSONInputMask: nil,
JSONOutputValue: func() interface{} { return &fftypes.FFI{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
generationRequest := r.Input.(*fftypes.FFIGenerationRequest)
return getOr(r.Ctx).Contracts().GenerateFFI(r.Ctx, r.PP["ns"], generationRequest)
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 (
"bytes"
"encoding/json"
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/contractmocks"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestPostContractInterfaceGenerate(t *testing.T) {
o, r := newTestAPIServer()
mcm := &contractmocks.Manager{}
o.On("Contracts").Return(mcm)
input := fftypes.Datatype{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/contracts/interfaces/generate", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("GenerateFFI", mock.Anything, "ns1", mock.Anything).
Return(&fftypes.FFI{}, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}
1 change: 1 addition & 0 deletions internal/apiserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ var routes = []*oapispec.Route{
postContractInterfaceInvoke,
postContractInterfaceQuery,
postContractInterfaceSubscribe,
postContractInterfaceGenerate,

postNewContractAPI,
getContractAPIByName,
Expand Down
Loading