Skip to content

Commit

Permalink
refactor: refactor defaults of DigestSecurityScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jun 12, 2022
1 parent 7d51463 commit d5afd48
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions lib/src/definitions/security/digest_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@
import 'helper_functions.dart';
import 'security_scheme.dart';

const _defaultInValue = "header";

const _defaultQoPValue = "auth";

/// Digest Access Authentication security configuration identified by the
/// Vocabulary Term `digest`.
class DigestSecurityScheme extends SecurityScheme {
@override
String get scheme => "digest";

/// Name for query, header, cookie, or uri parameters.
String? name;
final String? name;

String? _in;

/// Specifies the location of security authentication information.
late String in_ = "header";
String get in_ => _in ?? _defaultInValue;

String? _qop;

/// Quality of protection.
late String qop = "auth";
String get qop => _qop ?? _defaultQoPValue;

final List<String> _parsedJsonFields = [];

Expand All @@ -32,37 +40,42 @@ class DigestSecurityScheme extends SecurityScheme {
String? in_,
String? qop,
Map<String, String>? descriptions})
: in_ = in_ ?? "header",
qop = qop ?? "auth" {
: _in = in_,
_qop = qop {
this.description = description;
this.descriptions.addAll(descriptions ?? {});
}

dynamic _getJsonValue(Map<String, dynamic> json, String key) {
_parsedJsonFields.add(key);
static dynamic _getJsonValue(Map<String, dynamic> json, String key,
[List<String>? parsedJsonFields]) {
parsedJsonFields?.add(key);
return json[key];
}

static String? _parseNameJson(Map<String, dynamic> json) {
final dynamic jsonName = _getJsonValue(json, "name");
if (jsonName is String) {
return jsonName;
}

return null;
}

/// Creates a [DigestSecurityScheme] from a [json] object.
DigestSecurityScheme.fromJson(Map<String, dynamic> json) {
_parsedJsonFields.addAll(parseSecurityJson(this, json));
DigestSecurityScheme.fromJson(Map<String, dynamic> json)
: name = _parseNameJson(json) {
_parsedJsonFields
..addAll(parseSecurityJson(this, json))
..add("name");

final dynamic jsonIn = _getJsonValue(json, "in");
final dynamic jsonIn = _getJsonValue(json, "in", _parsedJsonFields);
if (jsonIn is String) {
in_ = jsonIn;
_parsedJsonFields.add("in");
_in = jsonIn;
}

final dynamic jsonQop = _getJsonValue(json, "qop");
final dynamic jsonQop = _getJsonValue(json, "qop", _parsedJsonFields);
if (jsonQop is String) {
qop = jsonQop;
_parsedJsonFields.add("qop");
}

final dynamic jsonName = _getJsonValue(json, "name");
if (jsonName is String) {
name = jsonName;
_parsedJsonFields.add("name");
_qop = jsonQop;
}

parseAdditionalFields(additionalFields, json, _parsedJsonFields);
Expand Down

0 comments on commit d5afd48

Please sign in to comment.