Trying to Map the data types supported in AsyncAPI to the ones available in Avro Schema. We have a Data type available in Avro schema that is Map , trying to find a way to represent it in Async API Yaml. Can anyone please advice ?
-
a map in YAML is called a hash – OneCricketeer Jan 21 '20 at 09:48
2 Answers
There is no direct equivalent in AsyncAPI to an Avro Map but you can encode a map as an object
by using the additionalProperties
validation keyword:
type: object
additionalProperties:
type: integer
might correspond to an Avro map<int>
.
For complex types, you can define a schema to represent the complex type and use a $ref
instead of a type
in the additionalProperties
.
-
1Yeah, agree with you. Also, I'd like to point out that AsyncAPI chose JSON Schema as the language to describe schemas. So it's not how AsyncAPI does it but how JSON Schema does it :) – fmvilas Feb 07 '20 at 17:45
As above mentioned for complex types you can use additionalProperties: true
I will elaborate it furthermore
As you can see the 'json' may dynamic, we don't know the actual shape of it ,therefore we can use that one as below examples
map< json>
type: object
additionalProperties: true
map<map< json>>
type: object
additionalProperties:
type: object
additionalProperties: true
And also this additionalProperties: true is identical for additionalProperties: { } , if you want you can use that too , for additionalProperties to be false you can use additionalProperties: not : {}
but if you know the exact shape of json you can use it like this:
map< json> offset={"x":{"id":"sss"}}
type: object
additionalProperties:
type:object
properties:
id:
type: string
So in here only id field is allowed