OpenAPI Specification allows you to add an object
type in oneOf
and anyOf
in Java SDKs. Defining an object
type means any key/value pair is accepted. Object
type in Java means it can refer to any instance, as Object
is the root class. Therefore, this change enforces that for any object
type case falling under oneOf
and anyOf
, the Java SDK will treat it as Map
.
Details
warning
Please note that the support for oneOf/anyOf
is still in alpha, and some cases may not be supported at this point. Please contact support@apimatic.io
in case of any guidance.
oneOf
Here is how you can define an Object
type in oneOf
in OpenAPI specification:
"oneOf": [
{
"type": "number"
},
{
"type": "boolean"
},
{
"type": "object"
}
]
In Java SDKs, the corresponding type of the Object
will be Map
(i.e. key/value pairs) and can be initialized with any key/value pair as shown below:
Map<String, Object> object = new HashMap<>();
object.put("key", "value");
OneOfContainer oneOfContainer = OneOfContainer.fromObject(object); // Initialized with the object case in oneOf
anyOf
For anyOf
, you can define an Object
type the same way as for oneOf
, as shown:
"anyOf": [
{
"type": "number"
},
{
"type": "boolean"
},
{
"type": "object"
}
]
In Java SDKs, you can consume anyOf
cases as explained in this code sample:
Map<String, Object> object = new HashMap<>();
object.put("key", "value");
AnyOfContainer anyOfContainer = AnyOfContainer.fromObject(object); // Initialized with the object case in anyOf