Skip to content

Commit

Permalink
Merge pull request #1501 from kaleido-io/fix_get_api
Browse files Browse the repository at this point in the history
Add base API url to contract api result
  • Loading branch information
nguyer authored Apr 25, 2024
2 parents 02e9d9e + 365337b commit 3e769de
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/reference/types/contractapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ nav_order: 4
"name": "my_contract_api",
"message": "b09d9f77-7b16-4760-a8d7-0e3c319b2a16",
"urls": {
"api": "http://127.0.0.1:5000/api/v1/namespaces/default/apis/my_contract_api",
"openapi": "http://127.0.0.1:5000/api/v1/namespaces/default/apis/my_contract_api/api/swagger.json",
"ui": "http://127.0.0.1:5000/api/v1/namespaces/default/apis/my_contract_api/api"
},
Expand Down Expand Up @@ -69,6 +70,7 @@ nav_order: 4

| Field Name | Description | Type |
|------------|-------------|------|
| `api` | The URL to use to invoke the API | `string` |
| `openapi` | The URL to download the OpenAPI v3 (Swagger) description for the API generated in JSON or YAML format | `string` |
| `ui` | The URL to use in a web browser to access the SwaggerUI explorer/exerciser for the API | `string` |

Expand Down
36 changes: 36 additions & 0 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -253,6 +256,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -315,6 +321,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -427,6 +436,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -551,6 +563,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -613,6 +628,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -11944,6 +11962,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -12075,6 +12096,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -12137,6 +12161,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -12263,6 +12290,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -12394,6 +12424,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down Expand Up @@ -12456,6 +12489,9 @@ paths:
urls:
description: The URLs to use to access the API
properties:
api:
description: The URL to use to invoke the API
type: string
openapi:
description: The URL to download the OpenAPI v3 (Swagger)
description for the API generated in JSON or YAML format
Expand Down
1 change: 1 addition & 0 deletions internal/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ func (cm *contractManager) addContractURLs(httpServerURL string, api *core.Contr
baseURL := fmt.Sprintf("%s/apis/%s", httpServerURL, api.Name)
api.URLs.OpenAPI = baseURL + "/api/swagger.json"
api.URLs.UI = baseURL + "/api"
api.URLs.API = baseURL
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,7 @@ func TestGetContractAPI(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "http://localhost/api/v1/namespaces/ns1/apis/banana/api/swagger.json", result.URLs.OpenAPI)
assert.Equal(t, "http://localhost/api/v1/namespaces/ns1/apis/banana/api", result.URLs.UI)
assert.Equal(t, "http://localhost/api/v1/namespaces/ns1/apis/banana", result.URLs.API)
}

func TestGetContractAPIs(t *testing.T) {
Expand All @@ -3235,6 +3236,7 @@ func TestGetContractAPIs(t *testing.T) {
assert.Equal(t, 1, len(results))
assert.Equal(t, "http://localhost/api/v1/namespaces/ns1/apis/banana/api/swagger.json", results[0].URLs.OpenAPI)
assert.Equal(t, "http://localhost/api/v1/namespaces/ns1/apis/banana/api", results[0].URLs.UI)
assert.Equal(t, "http://localhost/api/v1/namespaces/ns1/apis/banana", results[0].URLs.API)
}

func TestGetContractAPIInterface(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/coremsgs/en_struct_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ var (
ContractAPIPublished = ffm("ContractAPI.published", "Indicates if the API is published to other members of the multiparty network")

// ContractURLs field descriptions
ContractURLsAPI = ffm("ContractURLs.api", "The URL to use to invoke the API")
ContractURLsOpenAPI = ffm("ContractURLs.openapi", "The URL to download the OpenAPI v3 (Swagger) description for the API generated in JSON or YAML format")
ContractURLsUI = ffm("ContractURLs.ui", "The URL to use in a web browser to access the SwaggerUI explorer/exerciser for the API")

Expand Down
3 changes: 2 additions & 1 deletion internal/reference/reference.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -100,6 +100,7 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e
}`),
Message: fftypes.MustParseUUID("b09d9f77-7b16-4760-a8d7-0e3c319b2a16"),
URLs: core.ContractURLs{
API: "http://127.0.0.1:5000/api/v1/namespaces/default/apis/my_contract_api",
OpenAPI: "http://127.0.0.1:5000/api/v1/namespaces/default/apis/my_contract_api/api/swagger.json",
UI: "http://127.0.0.1:5000/api/v1/namespaces/default/apis/my_contract_api/api",
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/contracts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -55,6 +55,7 @@ type ContractDeployRequest struct {
}

type ContractURLs struct {
API string `ffstruct:"ContractURLs" json:"api"`
OpenAPI string `ffstruct:"ContractURLs" json:"openapi"`
UI string `ffstruct:"ContractURLs" json:"ui"`
}
Expand Down

0 comments on commit 3e769de

Please sign in to comment.