blockfrost / openapi

OpenAPI specification for Blockfrost.io service
https://docs.blockfrost.io
MIT License
22 stars 16 forks source link

`json_metadata` `/metadata/txs/labels/x` returns incorrect data for non-object metadata #343

Closed slowbackspace closed 8 months ago

slowbackspace commented 8 months ago

eg. string and numbers are turned in weird object format instead of the original primitive type.

Simplest way to reproduce is to fetch /metadata/txs/labels/2?count=1 on preprod.

[
  {
    "tx_hash": "5cb4f3f2b94cb04cb1ef96de7860ec4b7c4966d2748de6d9445c6480d72f0455",
    "json_metadata": {
      "0": "6",
      "1": "4",
      "2": "4",
      "3": "9",
      "4": "2",
      "5": "0",
      "6": "2",
      "7": "2",
      "8": "e",
      "9": "9",
      "10": "d",
      "11": "c",
      "12": "5",
      "13": "1",
      "14": "8",
      "15": "4",
      "16": "f",
      "17": "7",
      "18": "f",
      "19": "f",
      "20": "d",
      "21": "8",
      "22": "7",
      "23": "9",
      "24": "9",
      "25": "f",
      "26": "d",
      "27": "8",
      "28": "7",
      "29": "9",
      "30": "9",
      "31": "f",
      "32": "d",
      "33": "8",
      "34": "7",
      "35": "9",
      "36": "9",
      "37": "f",
      "38": "5",
      "39": "8",
      "40": "1",
      "41": "c",
      "42": "4",
      "43": "9",
      "44": "0",
      "45": "7",
      "46": "f",
      "47": "2",
      "48": "5",
      "49": "5",
      "50": "5",
      "51": "9",
      "52": "3",
      "53": "3",
      "54": "2",
      "55": "7",
      "56": "b",
      "57": "2",
      "58": "2",
      "59": "d",
      "60": "4",
      "61": "1",
      "62": "e",
      "63": "d",
    }
  }
]

related and fixing this issue will probably close: https://github.com/blockfrost/blockfrost-backend-ryo/issues/152

slowbackspace commented 8 months ago

okay, so the problem is in openapi schema used by fastify to serialize response. without the schema the response looks as expected.

schema:

{
   "response":{
      "200":{
         "type":"array",
         "items":{
            "type":"object",
            "properties":{
               "tx_hash":{
                  "type":"string",
                  "description":"Transaction hash that contains the specific metadata"
               },
               "json_metadata":{
                  "additionalProperties":true,
                  "anyOf":[
                     {
                        "type":"string"
                     },
                     {
                        "type":"object",
                        "additionalProperties":true
                     },
                     {
                        "type":"array",
                        "items":{

                        }
                     },
                     {
                        "type":"integer"
                     },
                     {
                        "type":"number"
                     },
                     {
                        "type":"boolean"
                     }
                  ],
                  "nullable":true,
                  "description":"Content of the JSON metadata"
               }
            },
            "required":[
               "tx_hash",
               "json_metadata"
            ]
         },
         "example":[
            {
               "tx_hash":"257d75c8ddb0434e9b63e29ebb6241add2b835a307aa33aedba2effe09ed4ec8",
               "json_metadata":{
                  "ADAUSD":[
                     {
                        "value":"0.10409800535729975",
                        "source":"ergoOracles"
                     }
                  ]
               }
            },
            {
               "tx_hash":"e865f2cc01ca7381cf98dcdc4de07a5e8674b8ea16e6a18e3ed60c186fde2b9c",
               "json_metadata":{
                  "ADAUSD":[
                     {
                        "value":"0.15409850555139935",
                        "source":"ergoOracles"
                     }
                  ]
               }
            },
            {
               "tx_hash":"4237501da3cfdd53ade91e8911e764bd0699d88fd43b12f44a1f459b89bc91be",
               "json_metadata":null
            }
         ]
      },
      "400":{
         "type":"object",
         "properties":{
            "status_code":{
               "type":"integer",
               "example":400
            },
            "error":{
               "type":"string",
               "example":"Bad Request"
            },
            "message":{
               "type":"string",
               "example":"Backend did not understand your request."
            }
         },
         "required":[
            "error",
            "message",
            "status_code"
         ]
      },
      "403":{
         "type":"object",
         "properties":{
            "status_code":{
               "type":"integer",
               "example":403
            },
            "error":{
               "type":"string",
               "example":"Forbidden"
            },
            "message":{
               "type":"string",
               "example":"Invalid project token."
            }
         },
         "required":[
            "error",
            "message",
            "status_code"
         ]
      },
      "404":{
         "type":"object",
         "properties":{
            "status_code":{
               "type":"integer",
               "example":404
            },
            "error":{
               "type":"string",
               "example":"Not Found"
            },
            "message":{
               "type":"string",
               "example":"The requested component has not been found."
            }
         },
         "required":[
            "error",
            "message",
            "status_code"
         ]
      },
      "418":{
         "type":"object",
         "properties":{
            "status_code":{
               "type":"integer",
               "example":418
            },
            "error":{
               "type":"string",
               "example":"Requested Banned"
            },
            "message":{
               "type":"string",
               "example":"IP has been auto-banned for flooding."
            }
         },
         "required":[
            "error",
            "message",
            "status_code"
         ]
      },
      "429":{
         "type":"object",
         "properties":{
            "status_code":{
               "type":"integer",
               "example":429
            },
            "error":{
               "type":"string",
               "example":"Project Over Limit"
            },
            "message":{
               "type":"string",
               "example":"Usage is over limit."
            }
         },
         "required":[
            "error",
            "message",
            "status_code"
         ]
      },
      "500":{
         "type":"object",
         "properties":{
            "status_code":{
               "type":"integer",
               "example":500
            },
            "error":{
               "type":"string",
               "example":"Internal Server Error"
            },
            "message":{
               "type":"string",
               "example":"An unexpected response was received from the backend."
            }
         },
         "required":[
            "error",
            "message",
            "status_code"
         ]
      }
   },
   "querystring":{
      "type":"object",
      "properties":{
         "count":{
            "type":"integer",
            "minimum":1,
            "maximum":100,
            "default":100
         },
         "page":{
            "type":"integer",
            "minimum":1,
            "maximum":21474836,
            "default":1
         },
         "order":{
            "type":"string",
            "enum":[
               "asc",
               "desc"
            ],
            "default":"asc"
         }
      }
   },
   "params":{
      "type":"object",
      "properties":{
         "label":{
            "type":"string"
         }
      }
   }
}