From 7b722b18e3487c36fc45894945901a96f8e0a398 Mon Sep 17 00:00:00 2001 From: Artem Poltorzhitskiy Date: Fri, 13 Sep 2024 12:04:22 +0200 Subject: [PATCH] Fix: swagger for /v1/blob endpoint (#283) --- cmd/api/docs/swagger.json | 77 +++++++++++++++--------------------- cmd/api/handler/namespace.go | 21 +++++----- 2 files changed, 42 insertions(+), 56 deletions(-) diff --git a/cmd/api/docs/swagger.json b/cmd/api/docs/swagger.json index ff17d577..be8dc50b 100644 --- a/cmd/api/docs/swagger.json +++ b/cmd/api/docs/swagger.json @@ -1164,7 +1164,7 @@ } }, "post": { - "description": "Returns blob\nTo authorize your requests you have to select the required tariff on our site. Then you receive api key to authorize. Api key should be passed via request header `apikey`.", + "description": "Returns blob.\nTo authorize your requests you have to select the required tariff on our site. Then you receive api key to authorize. Api key should be passed via request header `apikey`.", "consumes": [ "application/json" ], @@ -1178,31 +1178,12 @@ "operationId": "get-blob", "parameters": [ { - "description": "Base64-encoded namespace id and version", - "name": "hash", + "description": "Request body containing height, commitment and namespace hash", + "name": "request", "in": "body", "required": true, "schema": { - "type": "string" - } - }, - { - "minimum": 1, - "description": "Block heigth", - "name": "height", - "in": "body", - "required": true, - "schema": { - "type": "integer" - } - }, - { - "description": "Blob commitment", - "name": "commitment", - "in": "body", - "required": true, - "schema": { - "type": "string" + "$ref": "#/definitions/handler.postBlobRequest" } } ], @@ -1224,7 +1205,7 @@ }, "/blob/metadata": { "post": { - "description": "Returns blob metadata", + "description": "Returns blob metadata\nTo authorize your requests you have to select the required tariff on our site. Then you receive api key to authorize. Api key should be passed via request header `apikey`.", "consumes": [ "application/json" ], @@ -1238,31 +1219,12 @@ "operationId": "get-blob-metadata", "parameters": [ { - "description": "Base64-encoded namespace id and version", - "name": "hash", - "in": "body", - "required": true, - "schema": { - "type": "string" - } - }, - { - "minimum": 1, - "description": "Block heigth", - "name": "height", + "description": "Request body containing height, commitment and namespace hash", + "name": "request", "in": "body", "required": true, "schema": { - "type": "integer" - } - }, - { - "description": "Blob commitment", - "name": "commitment", - "in": "body", - "required": true, - "schema": { - "type": "string" + "$ref": "#/definitions/handler.postBlobRequest" } } ], @@ -5180,6 +5142,29 @@ } } }, + "handler.postBlobRequest": { + "type": "object", + "required": [ + "commitment", + "hash", + "height" + ], + "properties": { + "commitment": { + "type": "string", + "example": "vbGakK59+Non81TE3ULg5Ve5ufT9SFm/bCyY+WLR3gg=" + }, + "hash": { + "type": "string", + "example": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAs2bWWU6FOB0=" + }, + "height": { + "type": "integer", + "minimum": 1, + "example": 123456 + } + } + }, "responses.Address": { "description": "Celestia address information", "type": "object", diff --git a/cmd/api/handler/namespace.go b/cmd/api/handler/namespace.go index 3d81e05d..e377f8b4 100644 --- a/cmd/api/handler/namespace.go +++ b/cmd/api/handler/namespace.go @@ -468,20 +468,18 @@ func (handler *NamespaceHandler) Blobs(c echo.Context) error { } type postBlobRequest struct { - Hash string `json:"hash" validate:"required,namespace"` - Height types.Level `json:"height" validate:"required,min=1"` - Commitment string `json:"commitment" validate:"required,base64"` + Hash string `example:"AAAAAAAAAAAAAAAAAAAAAAAAAAAAs2bWWU6FOB0=" json:"hash" validate:"required,namespace"` + Height types.Level `example:"123456" json:"height" validate:"required,min=1"` + Commitment string `example:"vbGakK59+Non81TE3ULg5Ve5ufT9SFm/bCyY+WLR3gg=" json:"commitment" validate:"required,base64"` } // Blob godoc // // @Summary Get namespace blob by commitment on height -// @Description Returns blob +// @Description Returns blob. // @Tags namespace // @ID get-blob -// @Param hash body string true "Base64-encoded namespace id and version" -// @Param height body integer true "Block heigth" minimum(1) -// @Param commitment body string true "Blob commitment" +// @Param request body postBlobRequest true "Request body containing height, commitment and namespace hash" // @Accept json // @Produce json // @Success 200 {object} responses.Blob @@ -517,14 +515,17 @@ func (handler *NamespaceHandler) Blob(c echo.Context) error { // @Description Returns blob metadata // @Tags namespace // @ID get-blob-metadata -// @Param hash body string true "Base64-encoded namespace id and version" -// @Param height body integer true "Block heigth" minimum(1) -// @Param commitment body string true "Blob commitment" +// @Param request body postBlobRequest true "Request body containing height, commitment and namespace hash" // @Accept json // @Produce json // @Success 200 {object} responses.BlobLog // @Failure 400 {object} Error // @Router /blob/metadata [post] +// +// @securityDefinitions.apikey ApiKeyAuth +// @in header +// @name apikey +// @description To authorize your requests you have to select the required tariff on our site. Then you receive api key to authorize. Api key should be passed via request header `apikey`. func (handler *NamespaceHandler) BlobMetadata(c echo.Context) error { req, err := bindAndValidate[postBlobRequest](c) if err != nil {