Skip to content

Commit

Permalink
Openapi mismatches (#754)
Browse files Browse the repository at this point in the history
* Aligns response with openapi spec

* Fixes json serialization for local content response

* Review comments by Mark

* Fixes missed rename

* Removes array type for dataList
  • Loading branch information
benbierens authored Mar 26, 2024
1 parent 4038eed commit 8378ac4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion codex/rest/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ proc formatManifestBlocks(node: CodexNodeRef): Future[JsonNode] {.async.} =
content.add(restContent)

await node.iterateManifests(formatManifest)
return %content
return %RestContentList.init(content)

proc retrieveCid(
node: CodexNodeRef,
Expand Down
8 changes: 8 additions & 0 deletions codex/rest/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type
cid* {.serialize.}: Cid
manifest* {.serialize.}: Manifest

RestContentList* = object
content* {.serialize.}: seq[RestContent]

RestNode* = object
nodeId* {.serialize.}: RestNodeId
peerId* {.serialize.}: PeerId
Expand All @@ -67,6 +70,11 @@ type
quotaUsedBytes* {.serialize.}: uint
quotaReservedBytes* {.serialize.}: uint

proc init*(_: type RestContentList, content: seq[RestContent]): RestContentList =
RestContentList(
content: content
)

proc init*(_: type RestContent, cid: Cid, manifest: Manifest): RestContent =
RestContent(
cid: cid,
Expand Down
9 changes: 6 additions & 3 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,8 @@ paths:
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/DataList"
$ref: "#/components/schemas/DataList"

"400":
description: Invalid CID is specified
"404":
Expand Down Expand Up @@ -632,6 +631,10 @@ paths:
responses:
"200":
description: Returns the Request ID as decimal string
content:
text/plain:
schema:
type: string
"400":
description: Invalid or missing Request ID
"404":
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/codexclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ proc download*(client: CodexClient, cid: Cid, local = false): ?!string =

success response.body

proc list*(client: CodexClient): ?!seq[RestContent] =
proc list*(client: CodexClient): ?!RestContentList =
let url = client.baseurl & "/data"
let response = client.http.get(url)

if response.status != "200 OK":
return failure(response.status)

seq[RestContent].fromJson(response.body)
RestContentList.fromJson(response.body)

proc space*(client: CodexClient): ?!RestRepoStore =
let url = client.baseurl & "/space"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/testIntegration.nim
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ twonodessuite "Integration tests", debug1 = false, debug2 = false:
let list = client1.list().get

check:
[cid1, cid2].allIt(it in list.mapIt(it.cid))
[cid1, cid2].allIt(it in list.content.mapIt(it.cid))

test "node handles new storage availability":
let availability1 = client1.postAvailability(totalSize=1.u256, duration=2.u256, minPrice=3.u256, maxCollateral=4.u256).get
Expand Down

0 comments on commit 8378ac4

Please sign in to comment.