Skip to content

Commit

Permalink
Update metadata open API schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbertra committed Nov 24, 2023
1 parent a23ec08 commit bd09ee0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
33 changes: 32 additions & 1 deletion marlowe-runtime-web/.golden/OpenApi/golden
Expand Up @@ -1435,7 +1435,35 @@
"type": "string"
},
"Metadata": {
"description": "An arbitrary JSON value for storage in a metadata key"
"description": "Arbitrary JSON-encoded transaction metadata",
"oneOf": [
{
"type": "integer"
},
{
"description": "Hex-encoded binary data of up to 64 bytes",
"pattern": "0x[A-Fa-f0-9]{0,128}",
"type": "string"
},
{
"description": "Text data of up to 64 characters",
"type": "string"
},
{
"description": "Array of metadata values",
"items": {
"$ref": "#/components/schemas/Metadata"
},
"type": "array"
},
{
"additionalProperties": {
"$ref": "#/components/schemas/Metadata"
},
"description": "Object of metadata values",
"type": "object"
}
]
},
"Next": {
"description": "Describe the reducibility (Can be Reduced ?) and the applicability (Can Inputs be Applied ?) for a given contract.",
Expand Down Expand Up @@ -2359,6 +2387,9 @@
"type": "object"
},
"TokenMetadata": {
"additionalProperties": {
"$ref": "#/components/schemas/Metadata"
},
"description": "Metadata for an NFT, as described by https://cips.cardano.org/cips/cip25/",
"properties": {
"description": {
Expand Down
35 changes: 33 additions & 2 deletions marlowe-runtime-web/src/Language/Marlowe/Runtime/Web/Types.hs
Expand Up @@ -33,6 +33,7 @@ import Data.OpenApi (
HasAdditionalProperties (..),
HasType (..),
NamedSchema (..),
OpenApiItems (..),
OpenApiType (..),
Reference (..),
Referenced (..),
Expand Down Expand Up @@ -502,11 +503,39 @@ newtype Metadata = Metadata {unMetadata :: Value}
deriving newtype (ToJSON, FromJSON)

instance ToSchema Metadata where
declareNamedSchema _ =
declareNamedSchema _ = do
integerSchema <- declareSchemaRef $ Proxy @Integer
let metadataSchema = Ref $ Reference "Metadata"
binaryTextSchema =
mempty
& OpenApi.description ?~ "Hex-encoded binary data of up to 64 bytes"
& OpenApi.type_ ?~ OpenApiString
& OpenApi.pattern ?~ "0x[A-Fa-f0-9]{0,128}"
plainTextSchema =
mempty
& OpenApi.description ?~ "Text data of up to 64 characters"
& OpenApi.type_ ?~ OpenApiString
metadataArraySchema =
mempty
& OpenApi.description ?~ "Array of metadata values"
& OpenApi.type_ ?~ OpenApiArray
& OpenApi.items ?~ OpenApiItemsObject metadataSchema
metadataObjectSchema =
mempty
& OpenApi.description ?~ "Object of metadata values"
& OpenApi.type_ ?~ OpenApiObject
& OpenApi.additionalProperties ?~ AdditionalPropertiesSchema metadataSchema
pure $
NamedSchema (Just "Metadata") $
mempty
& OpenApi.description ?~ "An arbitrary JSON value for storage in a metadata key"
& OpenApi.description ?~ "Arbitrary JSON-encoded transaction metadata"
& oneOf
?~ [ integerSchema
, Inline binaryTextSchema
, Inline plainTextSchema
, Inline metadataArraySchema
, Inline metadataObjectSchema
]

data TxHeader = TxHeader
{ contractId :: TxOutRef
Expand Down Expand Up @@ -1027,6 +1056,7 @@ instance ToSchema TokenMetadata where
declareNamedSchema _ = do
stringSchema <- declareSchemaRef (Proxy @Text)
filesSchema <- declareSchemaRef (Proxy @[TokenMetadataFile])
metadataSchema <- declareSchemaRef (Proxy @Metadata)
pure $
NamedSchema (Just "TokenMetadata") $
mempty
Expand All @@ -1040,6 +1070,7 @@ instance ToSchema TokenMetadata where
, ("description", stringSchema)
, ("files", filesSchema)
]
& additionalProperties ?~ AdditionalPropertiesSchema metadataSchema

data TokenMetadataFile = TokenMetadataFile
{ name :: Text
Expand Down

0 comments on commit bd09ee0

Please sign in to comment.