Skip to content

Commit

Permalink
fixup! feat!: implement proper serialization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jun 3, 2024
1 parent a5a3018 commit 7433ef3
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 103 deletions.
21 changes: 19 additions & 2 deletions lib/src/core/definitions/security/ace_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,24 @@ final class AceSecurityScheme extends SecurityScheme {

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
final result = super.toJson();

if (as != null) {
result["as"] = as;
}

if (audience != null) {
result["audience"] = audience;
}

if (scopes != null) {
result["scopes"] = scopes;
}

if (cnonce != null) {
result["cnonce"] = cnonce;
}

return result;
}
}
12 changes: 10 additions & 2 deletions lib/src/core/definitions/security/apikey_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ final class ApiKeySecurityScheme extends SecurityScheme {

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
final result = <String, dynamic>{
"in": in_,
...super.toJson(),
};

if (name != null) {
result["name"] = name;
}

return result;
}
}
26 changes: 0 additions & 26 deletions lib/src/core/definitions/security/auto_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,4 @@ final class AutoSecurityScheme extends SecurityScheme {

@override
String get scheme => autoSecuritySchemeName;

@override
Map<String, dynamic> toJson() {
final result = <String, dynamic>{
"scheme": autoSecuritySchemeName,
...additionalFields,
};

if (description != null) {
result["description"] = description;
}

if (descriptions != null) {
result["descriptions"] = descriptions;
}

if (jsonLdType != null) {
result["@type"] = jsonLdType;
}

if (proxy != null) {
result["proxy"] = proxy;
}

return result;
}
}
12 changes: 10 additions & 2 deletions lib/src/core/definitions/security/basic_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ final class BasicSecurityScheme extends SecurityScheme {

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
final result = <String, dynamic>{
"in": in_,
...super.toJson(),
};

if (name != null) {
result["name"] = name;
}

return result;
}
}
18 changes: 16 additions & 2 deletions lib/src/core/definitions/security/bearer_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,21 @@ final class BearerSecurityScheme extends SecurityScheme {

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
final result = <String, dynamic>{
"in": in_,
"alg": alg,
"format": format,
...super.toJson(),
};

if (name != null) {
result["name"] = name;
}

if (authorization != null) {
result["authorization"] = authorization;
}

return result;
}
}
13 changes: 11 additions & 2 deletions lib/src/core/definitions/security/combo_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ final class ComboSecurityScheme extends SecurityScheme {

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
final result = super.toJson();

if (oneOf != null) {
result["oneOf"] = oneOf;
}

if (allOf != null) {
result["allOf"] = allOf;
}

return result;
}
}
19 changes: 1 addition & 18 deletions lib/src/core/definitions/security/digest_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,11 @@ final class DigestSecurityScheme extends SecurityScheme {
@override
Map<String, dynamic> toJson() {
final result = <String, dynamic>{
"scheme": digestSecuritySchemeName,
"in": in_,
"qop": qop,
...additionalFields,
...super.toJson(),
};

if (description != null) {
result["description"] = description;
}

if (descriptions != null) {
result["descriptions"] = descriptions;
}

if (jsonLdType != null) {
result["@type"] = jsonLdType;
}

if (proxy != null) {
result["proxy"] = proxy;
}

if (name != null) {
result["name"] = name;
}
Expand Down
26 changes: 0 additions & 26 deletions lib/src/core/definitions/security/no_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,4 @@ final class NoSecurityScheme extends SecurityScheme {

@override
String get scheme => nosecSecuritySchemeName;

@override
Map<String, dynamic> toJson() {
final result = <String, dynamic>{
"scheme": nosecSecuritySchemeName,
...additionalFields,
};

if (description != null) {
result["description"] = description;
}

if (descriptions != null) {
result["descriptions"] = descriptions;
}

if (jsonLdType != null) {
result["proxy"] = jsonLdType;
}

if (proxy != null) {
result["@type"] = proxy;
}

return result;
}
}
24 changes: 22 additions & 2 deletions lib/src/core/definitions/security/oauth2_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,27 @@ final class OAuth2SecurityScheme extends SecurityScheme {

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
final result = <String, dynamic>{
"flow": flow,
...super.toJson(),
};

if (authorization != null) {
result["authorization"] = authorization;
}

if (token != null) {
result["token"] = token;
}

if (refresh != null) {
result["refresh"] = refresh;
}

if (scopes != null) {
result["scopes"] = scopes;
}

return result;
}
}
21 changes: 1 addition & 20 deletions lib/src/core/definitions/security/psk_security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,7 @@ final class PskSecurityScheme extends SecurityScheme {

@override
Map<String, dynamic> toJson() {
final result = <String, dynamic>{
"scheme": pskSecuritySchemeName,
...additionalFields,
};

if (description != null) {
result["description"] = description;
}

if (descriptions != null) {
result["descriptions"] = descriptions;
}

if (jsonLdType != null) {
result["@type"] = jsonLdType;
}

if (proxy != null) {
result["proxy"] = proxy;
}
final result = super.toJson();

if (identity != null) {
result["identity"] = identity;
Expand Down
26 changes: 25 additions & 1 deletion lib/src/core/definitions/security/security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,29 @@ abstract base class SecurityScheme {

/// Converts this [SecurityScheme] instance into a [Map] that can be easily
/// converted to JSON.
Map<String, dynamic> toJson();
@mustCallSuper
Map<String, dynamic> toJson() {
final result = <String, dynamic>{
"scheme": scheme,
...additionalFields,
};

if (description != null) {
result["description"] = description;
}

if (descriptions != null) {
result["descriptions"] = descriptions;
}

if (jsonLdType != null) {
result["@type"] = jsonLdType;
}

if (proxy != null) {
result["proxy"] = proxy;
}

return result;
}
}

0 comments on commit 7433ef3

Please sign in to comment.