when<TResult extends Object?> method
- @optionalTypeArgs
- required TResult apiKey(
- String name,
- String? description,
- ApiKeyLocation location
- required TResult http(
- HttpSecurityScheme scheme,
- String? bearerFormat,
- String? description
- required TResult mutualTLS(
- String? description
- required TResult oauth2(
- String? description,
- OAuthFlows flows
- required TResult openIdConnect(),
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');
}
}