encode method

void encode(
  1. KeyedArchive object
)
override

Implementation

void encode(KeyedArchive object) {
  super.encode(object);

  if (type == null) {
    throw ArgumentError(
        "APISecurityScheme must have non-null values for: 'type'.");
  }

  object.encode("type", APISecuritySchemeTypeCodec.encode(type));
  object.encode("description", description);

  switch (type) {
    case APISecuritySchemeType.apiKey:
      {
        if (name == null || location == null) {
          throw ArgumentError(
              "APISecurityScheme with 'apiKey' type must have non-null values for: 'name', 'location'.");
        }

        object.encode("name", name);
        object.encode("in", APIParameterLocationCodec.encode(location));
      }
      break;
    case APISecuritySchemeType.oauth2:
      {
        if (flows == null) {
          throw ArgumentError(
              "APISecurityScheme with 'oauth2' type must have non-null values for: 'flows'.");
        }

        object.encodeObjectMap("flows", flows);
      }
      break;
    case APISecuritySchemeType.http:
      {
        if (scheme == null) {
          throw ArgumentError(
              "APISecurityScheme with 'http' type must have non-null values for: 'scheme'.");
        }

        object.encode("scheme", scheme);
        object.encode("bearerFormat", format);
      }
      break;
    case APISecuritySchemeType.openID:
      {
        if (connectURL == null) {
          throw ArgumentError(
              "APISecurityScheme with 'openID' type must have non-null values for: 'connectURL'.");
        }
        object.encode("openIdConnectUrl", connectURL);
      }
      break;
    default:
      throw ArgumentError(
          "APISecurityScheme must have non-null values for: 'type'.");
  }
}