addContent method Null safety
- String contentType,
- APISchemaObject? bodyObject
Adds a bodyObject
to content for a content-type.
contentType
must take the form 'primaryType/subType', e.g. 'application/json'. Do not include charsets.
If content is null, it is created. If contentType
does not exist in content, bodyObject
is added for contentType
.
If contentType
exists, the bodyObject
is added the list of possible schemas that were previously added.
Implementation
void addContent(String contentType, APISchemaObject? bodyObject) {
content ??= {};
final key = contentType;
final existingContent = content![key];
if (existingContent == null) {
content![key] = APIMediaType(schema: bodyObject);
return;
}
final schema = existingContent.schema;
if (schema?.oneOf != null) {
schema!.oneOf!.add(bodyObject);
} else {
final container = APISchemaObject()..oneOf = [schema, bodyObject];
existingContent.schema = container;
}
}