maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
  1. TResult apiKey(
    1. String name,
    2. String? description,
    3. ApiKeyLocation location
    )?,
  2. TResult http(
    1. HttpSecurityScheme scheme,
    2. String? bearerFormat,
    3. String? description
    )?,
  3. TResult mutualTLS(
    1. String? description
    )?,
  4. TResult oauth2(
    1. String? description,
    2. OAuthFlows flows
    )?,
  5. TResult openIdConnect(
    1. String? description,
    2. String url
    )?,
  6. required TResult orElse(),
})

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( String name,  String? description, @JsonKey(name: 'in')  ApiKeyLocation location)?  apiKey,TResult Function( HttpSecurityScheme scheme,  String? bearerFormat,  String? description)?  http,TResult Function( String? description)?  mutualTLS,TResult Function( String? description,  OAuthFlows flows)?  oauth2,TResult Function( String? description, @JsonKey(name: 'openIdConnectUrl')  String url)?  openIdConnect,required TResult orElse(),}) {final _that = this;
switch (_that) {
case SecuritySchemeApiKey() when apiKey != null:
return apiKey(_that.name,_that.description,_that.location);case SecuritySchemeHttp() when http != null:
return http(_that.scheme,_that.bearerFormat,_that.description);case SecuritySchemeMutualTLS() when mutualTLS != null:
return mutualTLS(_that.description);case SecuritySchemeOauth2() when oauth2 != null:
return oauth2(_that.description,_that.flows);case SecuritySchemeOpenIdConnect() when openIdConnect != null:
return openIdConnect(_that.description,_that.url);case _:
  return orElse();

}
}