Skip to content

Commit

Permalink
refactor: replace scheme getters with final fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Sep 26, 2022
1 parent 5ab8283 commit d75ce47
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 44 deletions.
7 changes: 2 additions & 5 deletions lib/src/definitions/security/ace_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AceSecurityScheme extends SecurityScheme {
this.scopes,
this.cnonce,
Map<String, String>? descriptions,
}) {
}) : super('ace:ACESecurityScheme') {
this.description = description;
this.descriptions.addAll(descriptions ?? {});
}
Expand All @@ -29,7 +29,7 @@ class AceSecurityScheme extends SecurityScheme {
AceSecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('ace:ACESecurityScheme') {
final Set<String> parsedFields = {};

as = json.parseField<String>('ace:as', parsedFields);
Expand All @@ -40,9 +40,6 @@ class AceSecurityScheme extends SecurityScheme {
parseSecurityJson(json, parsedFields, prefixMapping);
}

@override
String get scheme => 'ace:ACESecurityScheme';

/// URI of the authorization server.
String? as;

Expand Down
8 changes: 3 additions & 5 deletions lib/src/definitions/security/apikey_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class ApiKeySecurityScheme extends SecurityScheme {
this.name,
String? in_,
super.descriptions,
}) : in_ = in_ ?? _defaultInValue;
}) : in_ = in_ ?? _defaultInValue,
super('apikey');

/// Creates a [ApiKeySecurityScheme] from a [json] object.
ApiKeySecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('apikey') {
final Set<String> parsedFields = {};

name = json.parseField<String>('name', parsedFields);
Expand All @@ -36,9 +37,6 @@ class ApiKeySecurityScheme extends SecurityScheme {
parseSecurityJson(json, parsedFields, prefixMapping);
}

@override
String get scheme => 'apikey';

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

Expand Down
5 changes: 1 addition & 4 deletions lib/src/definitions/security/auto_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ class AutoSecurityScheme extends SecurityScheme {
AutoSecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('auto') {
parseSecurityJson(json, {}, prefixMapping);
}

@override
String get scheme => 'auto';
}
8 changes: 3 additions & 5 deletions lib/src/definitions/security/basic_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class BasicSecurityScheme extends SecurityScheme {
this.name,
String? in_,
super.descriptions,
}) : in_ = in_ ?? _defaultInValue;
}) : in_ = in_ ?? _defaultInValue,
super('basic');

/// Creates a [BasicSecurityScheme] from a [json] object.
BasicSecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('basic') {
final Set<String> parsedFields = {};

name = json.parseField<String>('name', parsedFields);
Expand All @@ -36,9 +37,6 @@ class BasicSecurityScheme extends SecurityScheme {
parseSecurityJson(json, parsedFields, prefixMapping);
}

@override
String get scheme => 'basic';

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

Expand Down
8 changes: 3 additions & 5 deletions lib/src/definitions/security/bearer_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ class BearerSecurityScheme extends SecurityScheme {
super.descriptions,
}) : in_ = in_ ?? _defaultInValue,
alg = alg ?? _defaultAlgValue,
format = format ?? _defaultFormatValue;
format = format ?? _defaultFormatValue,
super('bearer');

/// Creates a [BearerSecurityScheme] from a [json] object.
BearerSecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('bearer') {
final Set<String> parsedFields = {};

name = json.parseField<String>('name', parsedFields);
Expand All @@ -47,9 +48,6 @@ class BearerSecurityScheme extends SecurityScheme {
parseSecurityJson(json, parsedFields, prefixMapping);
}

@override
String get scheme => 'bearer';

/// URI of the authorization server.
late final String? authorization;

Expand Down
8 changes: 3 additions & 5 deletions lib/src/definitions/security/digest_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class DigestSecurityScheme extends SecurityScheme {
this.name,
super.descriptions,
}) : in_ = in_ ?? _defaultInValue,
qop = qop ?? _defaultQoPValue;
qop = qop ?? _defaultQoPValue,
super('digest');

/// Creates a [DigestSecurityScheme] from a [json] object.
DigestSecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('digest') {
final Set<String> parsedFields = {};

name = json.parseField<String>('name', parsedFields);
Expand All @@ -41,9 +42,6 @@ class DigestSecurityScheme extends SecurityScheme {
parseSecurityJson(json, parsedFields, prefixMapping);
}

@override
String get scheme => 'digest';

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

Expand Down
5 changes: 1 addition & 4 deletions lib/src/definitions/security/no_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ class NoSecurityScheme extends SecurityScheme {
NoSecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('nosec') {
parseSecurityJson(json, {}, prefixMapping);
}

@override
String get scheme => 'nosec';
}
6 changes: 2 additions & 4 deletions lib/src/definitions/security/oauth2_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OAuth2SecurityScheme extends SecurityScheme {
this.refresh,
this.token,
Map<String, String>? descriptions,
}) {
}) : super('oauth2') {
this.description = description;
this.descriptions.addAll(descriptions ?? {});
}
Expand All @@ -31,7 +31,7 @@ class OAuth2SecurityScheme extends SecurityScheme {
OAuth2SecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('oauth2') {
final Set<String> parsedFields = {};

authorization = json.parseField<String>('authorization', parsedFields);
Expand All @@ -42,8 +42,6 @@ class OAuth2SecurityScheme extends SecurityScheme {

parseSecurityJson(json, parsedFields, prefixMapping);
}
@override
String get scheme => 'oauth2';

/// URI of the authorization server.
///
Expand Down
7 changes: 2 additions & 5 deletions lib/src/definitions/security/psk_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PskSecurityScheme extends SecurityScheme {
String? description,
String? proxy,
Map<String, String>? descriptions,
}) {
}) : super('psk') {
this.description = description;
this.proxy = proxy;
this.descriptions.addAll(descriptions ?? {});
Expand All @@ -28,17 +28,14 @@ class PskSecurityScheme extends SecurityScheme {
PskSecurityScheme.fromJson(
Map<String, dynamic> json,
PrefixMapping prefixMapping,
) {
) : super('psk') {
final Set<String> parsedFields = {};

identity = json.parseField<String>('identity');

parseSecurityJson(json, parsedFields, prefixMapping);
}

@override
String get scheme => 'psk';

/// Name for query, header, cookie, or uri parameters.
String? identity;
}
5 changes: 3 additions & 2 deletions lib/src/definitions/security/security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import 'psk_security_scheme.dart';
/// mechanism.
abstract class SecurityScheme {
/// Constructor.
SecurityScheme({
SecurityScheme(
this.scheme, {
this.description,
this.proxy,
Map<String, String>? descriptions,
Expand All @@ -33,7 +34,7 @@ abstract class SecurityScheme {
///
/// Can be one of `nosec`, `combo`, `basic`, `digest`, `bearer`, `psk`,
/// `oauth2`, or `apikey`.
String get scheme;
final String scheme;

/// The default [description] of this [SecurityScheme].
String? description;
Expand Down

0 comments on commit d75ce47

Please sign in to comment.