From 8378ac4dac0f1be7048625c446de3ea6e918c211 Mon Sep 17 00:00:00 2001 From: Ben Bierens <39762930+benbierens@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:12:15 +0100 Subject: [PATCH] Openapi mismatches (#754) * Aligns response with openapi spec * Fixes json serialization for local content response * Review comments by Mark * Fixes missed rename * Removes array type for dataList --- codex/rest/api.nim | 2 +- codex/rest/json.nim | 8 ++++++++ openapi.yaml | 9 ++++++--- tests/integration/codexclient.nim | 4 ++-- tests/integration/testIntegration.nim | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 18f65006..311719fd 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -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, diff --git a/codex/rest/json.nim b/codex/rest/json.nim index 7fe13c32..142af9d2 100644 --- a/codex/rest/json.nim +++ b/codex/rest/json.nim @@ -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 @@ -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, diff --git a/openapi.yaml b/openapi.yaml index adfc887a..3a1ad70e 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -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": @@ -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": diff --git a/tests/integration/codexclient.nim b/tests/integration/codexclient.nim index 47a1dbad..b4230195 100644 --- a/tests/integration/codexclient.nim +++ b/tests/integration/codexclient.nim @@ -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" diff --git a/tests/integration/testIntegration.nim b/tests/integration/testIntegration.nim index 57ce0955..a18259aa 100644 --- a/tests/integration/testIntegration.nim +++ b/tests/integration/testIntegration.nim @@ -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