blockfrost / openapi

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

Update OpenAPI for optional/missing response fields #279

Closed theeldermillenial closed 1 year ago

theeldermillenial commented 1 year ago

When calling API endpoints and validating responses, there are often missing fields in the response. This can create issues when trying to validate responses against the OpenAPI schema.

For example, when trying to get the asset information for Normcoin, no url or decimal fields are returned even though the OpenAPI spec does not mark them as optional fields in the response. For decimal, I would expect either a default value of 0 or for this field to be marked optional in the spec.

Normcoin (policy+name=5c9da1679c0f7ca1909c34e38a8e157eb8a5943236e588edf1cead014e6f726d636f696e)

For my particular use case, I am using datamodel-code-generator to generate API response classes for validation. This helps with things like data type conversion and validation of outputs. When generating datamodel classes based on the OpenAPI schema, I am having to make some modifications to the code being generated because the OpenAPI schema does not properly reflect the response objects returned.

theeldermillenial commented 1 year ago

For the above example, I would expect the output of the API to at least follow the required/optional fields outlined by the Cardano token registry: https://developers.cardano.org/docs/native-tokens/cardano-token-registry/

slowbackspace commented 1 year ago

Hi @theeldermillenial, sorry for the late reply.

Both decimals and url metadata fields are marked in OpenAPI as nullable, so their value can be null. I just tried curl on https://cardano-mainnet.blockfrost.io/api/v0/assets/5c9da1679c0f7ca1909c34e38a8e157eb8a5943236e588edf1cead014e6f726d636f696e and both fields are present and set to null which I think is fine according to the OpenAPI specification.

Do I understand correctly that your response completely omits these fields? How do you query the API?

{
  "asset": "5c9da1679c0f7ca1909c34e38a8e157eb8a5943236e588edf1cead014e6f726d636f696e",
  "policy_id": "5c9da1679c0f7ca1909c34e38a8e157eb8a5943236e588edf1cead01",
  "asset_name": "4e6f726d636f696e",
  "fingerprint": "asset1xl8k8pjlcaw7ynt5gj3y4e9cs23h5epz0efcmx",
  "quantity": "19592021",
  "initial_mint_tx_hash": "16b284e95063762d2c333ed6ba23313d81ef7411d4efbb1440ba6d641bc4a511",
  "mint_or_burn_count": 1,
  "onchain_metadata": null,
  "onchain_metadata_standard": null,
  "metadata": {
    "name": "Normcoin",
    "description": "Jokes on blue cards. Adam Eget. Compassion. Humour. The Absurd.",
    "ticker": "NORM",
    "url": null,
    "logo": "...",
    "decimals": null
  }
}
vladimirvolek commented 1 year ago

Feel free to reopen if you are still experiencing problems.

theeldermillenial commented 1 year ago

Sorry for the slow response. I will take a look at this and respond.

My main point was that at the time of writing, the values were not optional in the spec. Maybe that has changed and this is resolved. I'll respond with an update.

theeldermillenial commented 1 year ago

Sorry for spamming pings. I ran my tests multiple times and thought I found an issue. Now I am running it again it is not throwing an error. I am investigating more.