when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult cookie(
    1. String? name,
    2. String? description,
    3. bool? required,
    4. bool? deprecated,
    5. String? style,
    6. bool? explode,
    7. bool? allowReserved,
    8. String? example,
    9. Schema schema,
    10. String? ref,
    ),
  2. required TResult header(
    1. String? name,
    2. String? description,
    3. bool? required,
    4. bool? deprecated,
    5. String? style,
    6. bool? explode,
    7. bool? allowReserved,
    8. String? example,
    9. Schema schema,
    10. String? ref,
    ),
  3. required TResult query(
    1. String? name,
    2. String? description,
    3. bool? required,
    4. bool? deprecated,
    5. String? style,
    6. bool? explode,
    7. bool? allowReserved,
    8. String? example,
    9. Schema schema,
    10. String? ref,
    ),
  4. required TResult path(
    1. String? name,
    2. String? description,
    3. bool? deprecated,
    4. String? style,
    5. bool? explode,
    6. bool? allowReserved,
    7. String? example,
    8. Schema? schema,
    9. String? ref,
    ),
})

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,  bool? required,  bool? deprecated,  String? style,  bool? explode,  bool? allowReserved,  String? example,  Schema schema, @JsonKey(name: '\$ref')@_ParamRefConverter()  String? ref)  cookie,required TResult Function( String? name,  String? description,  bool? required,  bool? deprecated,  String? style,  bool? explode,  bool? allowReserved,  String? example,  Schema schema, @JsonKey(name: '\$ref')@_ParamRefConverter()  String? ref)  header,required TResult Function( String? name,  String? description,  bool? required,  bool? deprecated,  String? style,  bool? explode,  bool? allowReserved,  String? example,  Schema schema, @JsonKey(name: '\$ref')@_ParamRefConverter()  String? ref)  query,required TResult Function( String? name,  String? description,  bool? deprecated,  String? style,  bool? explode,  bool? allowReserved,  String? example,  Schema? schema, @JsonKey(name: '\$ref')@_ParamRefConverter()  String? ref)  path,}) {final _that = this;
switch (_that) {
case ParameterCookie():
return cookie(_that.name,_that.description,_that.required,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case ParameterHeader():
return header(_that.name,_that.description,_that.required,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case ParameterQuery():
return query(_that.name,_that.description,_that.required,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case ParameterPath():
return path(_that.name,_that.description,_that.deprecated,_that.style,_that.explode,_that.allowReserved,_that.example,_that.schema,_that.ref);case _:
  throw StateError('Unexpected subclass');

}
}