when<TResult extends Object?> method

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

A switch-like method, using callbacks.

As opposed to map, this offers destructuring. It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case Subclass2(:final field2):
    return ...;
}

Implementation

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

}
}