addContent method Null safety

void addContent(
  1. String contentType,
  2. 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.


void addContent(String contentType, APISchemaObject bodyObject) {
  content ??= {};

  final key = contentType;
  final existingContent = content![key];
  if (existingContent == null) {
    content![key] = new APIMediaType(schema: bodyObject);

  final schema = existingContent.schema;
  if (schema?.oneOf != null) {
  } else {
    final container = new APISchemaObject()..oneOf = [schema!, bodyObject];
    existingContent.schema = container;