From d5afd488e5623458a27610f1cde8cd95b737e3e2 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sun, 12 Jun 2022 08:24:51 +0200 Subject: [PATCH] refactor: refactor defaults of DigestSecurityScheme --- .../security/digest_security_scheme.dart | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/src/definitions/security/digest_security_scheme.dart b/lib/src/definitions/security/digest_security_scheme.dart index 0ce952ea..2a824c6c 100644 --- a/lib/src/definitions/security/digest_security_scheme.dart +++ b/lib/src/definitions/security/digest_security_scheme.dart @@ -7,6 +7,10 @@ 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 { @@ -14,13 +18,17 @@ class DigestSecurityScheme extends SecurityScheme { 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 _parsedJsonFields = []; @@ -32,37 +40,42 @@ class DigestSecurityScheme extends SecurityScheme { String? in_, String? qop, Map? descriptions}) - : in_ = in_ ?? "header", - qop = qop ?? "auth" { + : _in = in_, + _qop = qop { this.description = description; this.descriptions.addAll(descriptions ?? {}); } - dynamic _getJsonValue(Map json, String key) { - _parsedJsonFields.add(key); + static dynamic _getJsonValue(Map json, String key, + [List? parsedJsonFields]) { + parsedJsonFields?.add(key); return json[key]; } + static String? _parseNameJson(Map 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 json) { - _parsedJsonFields.addAll(parseSecurityJson(this, json)); + DigestSecurityScheme.fromJson(Map 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);