fromJson static method

GetModel200Response? fromJson(
  1. dynamic value
)

Returns a new GetModel200Response instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static GetModel200Response? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'data'), 'Required key "GetModel200Response[data]" is missing from JSON.');
      assert(json[r'data'] != null, 'Required key "GetModel200Response[data]" has a null value in JSON.');
      assert(json.containsKey(r'cost'), 'Required key "GetModel200Response[cost]" is missing from JSON.');
      assert(json[r'cost'] != null, 'Required key "GetModel200Response[cost]" has a null value in JSON.');
      assert(json.containsKey(r'credits_remaining'), 'Required key "GetModel200Response[credits_remaining]" is missing from JSON.');
      assert(json[r'credits_remaining'] != null, 'Required key "GetModel200Response[credits_remaining]" has a null value in JSON.');
      assert(json.containsKey(r'rate_limit_limit'), 'Required key "GetModel200Response[rate_limit_limit]" is missing from JSON.');
      assert(json[r'rate_limit_limit'] != null, 'Required key "GetModel200Response[rate_limit_limit]" has a null value in JSON.');
      assert(json.containsKey(r'rate_limit_remaining'), 'Required key "GetModel200Response[rate_limit_remaining]" is missing from JSON.');
      assert(json[r'rate_limit_remaining'] != null, 'Required key "GetModel200Response[rate_limit_remaining]" has a null value in JSON.');
      assert(json.containsKey(r'rate_limit_reset'), 'Required key "GetModel200Response[rate_limit_reset]" is missing from JSON.');
      assert(json[r'rate_limit_reset'] != null, 'Required key "GetModel200Response[rate_limit_reset]" has a null value in JSON.');
      assert(json.containsKey(r'metering'), 'Required key "GetModel200Response[metering]" is missing from JSON.');
      assert(json[r'metering'] != null, 'Required key "GetModel200Response[metering]" has a null value in JSON.');
      assert(json.containsKey(r'request_id'), 'Required key "GetModel200Response[request_id]" is missing from JSON.');
      assert(json[r'request_id'] != null, 'Required key "GetModel200Response[request_id]" has a null value in JSON.');
      return true;
    }());

    return GetModel200Response(
      data: ModelDetail.fromJson(json[r'data'])!,
      cost: mapValueOfType<int>(json, r'cost')!,
      creditsRemaining: mapValueOfType<int>(json, r'credits_remaining')!,
      rateLimitLimit: mapValueOfType<int>(json, r'rate_limit_limit')!,
      rateLimitRemaining: mapValueOfType<int>(json, r'rate_limit_remaining')!,
      rateLimitReset: mapValueOfType<int>(json, r'rate_limit_reset')!,
      metering: GetModel200ResponseMeteringEnum.fromJson(json[r'metering'])!,
      requestId: mapValueOfType<String>(json, r'request_id')!,
    );
  }
  return null;
}