Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix null pointer exception in APISecurityRequirement with requirements #6

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
12c560b
fix null pointer exception.
hpoul Jun 7, 2020
530d684
add test for security requirements.
hpoul Jun 9, 2020
d224464
add support for security requirements.
hpoul Jun 24, 2020
d572797
sed -i '' 's/package:open_api/package:open_api_forked/g' `find . -nam…
hpoul Jul 28, 2020
9cf65bf
nullsafety
j4qfrost Mar 1, 2021
89d2c38
update travis
j4qfrost Mar 1, 2021
966f6a3
check null type return
j4qfrost Mar 1, 2021
322ebec
test large configs
j4qfrost Mar 1, 2021
aa9c66c
test kube config
j4qfrost Mar 1, 2021
c237f9a
check changes
j4qfrost Mar 1, 2021
ea7a146
add more nulls
j4qfrost Mar 1, 2021
789d1ce
i am a dumb dumb
j4qfrost Mar 1, 2021
eff3ce3
still dumb and should run locally
j4qfrost Mar 1, 2021
9cf53f0
revert some bool fields
j4qfrost Mar 1, 2021
278d80d
containsPathParameters parameterNames nullable
j4qfrost Mar 8, 2021
5f0f37c
oops
j4qfrost Mar 9, 2021
d5e895e
try non nullable
j4qfrost Mar 9, 2021
0f6cad8
Merge remote-tracking branch 'j4qfrost/master'
hpoul Mar 10, 2021
535ad56
fixed tests.
hpoul Mar 10, 2021
3089d6d
depend on codable_forked
hpoul Mar 10, 2021
1f9f395
sed -i '' 's/package:codable/package:codable_forked/g' `find . -name …
hpoul Mar 10, 2021
cf8d27d
increase version to 3.0.0
hpoul Mar 10, 2021
3c7e873
rename isRequired to required
hpoul Mar 19, 2021
3554723
point homepage to forked repo.
hpoul Mar 19, 2021
557f13b
fix isRequired / isDeprecated
hpoul Mar 19, 2021
962f70b
fix header parameters, update dependency on codable.
hpoul Mar 20, 2021
892ed7d
remove many forced null unwrap
hpoul Aug 2, 2021
ebbda84
non nullable list elements
hpoul Aug 2, 2021
fca695c
fix required null error.
hpoul Aug 2, 2021
ecd76cd
add openIDConnect security scheme type.
hpoul Oct 10, 2022
85b52ee
only fixed a few warnigns, deprecated lints.
hpoul Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: dart
dart:
- stable
- beta

before_script:
- mkdir test/specs
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 3.0.0+6

- add openIDConnect security scheme type.

## 3.0.0+5

- Remove forced null unwraps.

## 3.0.0+3

- fix header parameters, update dependency on codable.

## 3.0.0+2

- Rename APISchemaObject.isRequired back to required

## 3.0.0

- nullsafety migration

## 2.0.1+1

- forked version to fix v3 security requirements

## 2.0.1

- Fix bug when merging APIResponse bodies
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Example
---

```dart
final file = new File("test/specs/kubernetes.json");
final file = File("test/specs/kubernetes.json");
final contents = await file.readAsString();
final doc = new APIDocument.fromJSON(contents);
final doc = APIDocument.fromJSON(contents);

final output = JSON.encode(doc.asMap());
```
Expand Down
6 changes: 3 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include: package:lints/recommended.yaml

analyzer:
strong-mode: true
# exclude:
# - path/to/excluded/files/**

Expand All @@ -8,8 +9,7 @@ linter:
rules:
- cancel_subscriptions
- hash_and_equals
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- collection_methods_unrelated_type
- test_types_in_equals
- unrelated_type_equality_checks
- valid_regexps
13 changes: 8 additions & 5 deletions lib/src/object.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:meta/meta.dart';
import 'package:codable/codable.dart';
import 'package:codable_forked/codable.dart';

export 'package:codable/codable.dart';
export 'package:codable_forked/codable.dart';

class APIObject extends Coding {
Map<String, dynamic> extensions = {};
Expand All @@ -19,14 +19,17 @@ class APIObject extends Coding {

@mustCallSuper
void encode(KeyedArchive object) {
final invalidKeys = extensions.keys.where((key) => !key.startsWith("x-")).map((key) => "'$key'").toList();
final invalidKeys = extensions.keys
.where((key) => !key.startsWith("x-"))
.map((key) => "'$key'")
.toList();
if (invalidKeys.length > 0) {
throw new ArgumentError(
throw ArgumentError(
"extension keys must start with 'x-'. The following keys are invalid: ${invalidKeys.join(", ")}");
}

extensions.forEach((key, value) {
object.encode(key, value);
});
}
}
}
58 changes: 30 additions & 28 deletions lib/src/v2/document.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:codable/cast.dart' as cast;
import 'package:open_api/src/object.dart';
import 'package:open_api/src/v2/metadata.dart';
import 'package:open_api/src/v2/parameter.dart';
import 'package:open_api/src/v2/path.dart';
import 'package:open_api/src/v2/response.dart';
import 'package:open_api/src/v2/schema.dart';
import 'package:open_api/src/v2/security.dart';
import 'package:codable_forked/cast.dart' as cast;
import 'package:open_api_forked/src/object.dart';
import 'package:open_api_forked/src/v2/metadata.dart';
import 'package:open_api_forked/src/v2/parameter.dart';
import 'package:open_api_forked/src/v2/path.dart';
import 'package:open_api_forked/src/v2/response.dart';
import 'package:open_api_forked/src/v2/schema.dart';
import 'package:open_api_forked/src/v2/security.dart';

/// Represents an OpenAPI 2.0 specification.
class APIDocument extends APIObject {
Expand All @@ -18,21 +18,21 @@ class APIDocument extends APIObject {
}

String version = "2.0";
APIInfo info = new APIInfo();
String host;
String basePath;
APIInfo? info = APIInfo();
String? host;
String? basePath;

List<APITag> tags = [];
List<String> schemes = [];
List<String> consumes = [];
List<String> produces = [];
List<Map<String, List<String>>> security = [];
List<APITag?>? tags = [];
List<String>? schemes = [];
List<String>? consumes = [];
List<String>? produces = [];
List<Map<String, List<String?>>?> security = [];

Map<String, APIPath> paths = {};
Map<String, APIResponse> responses = {};
Map<String, APIParameter> parameters = {};
Map<String, APISchemaObject> definitions = {};
Map<String, APISecurityScheme> securityDefinitions = {};
Map<String, APIPath?>? paths = {};
Map<String, APIResponse?>? responses = {};
Map<String, APIParameter?>? parameters = {};
Map<String, APISchemaObject?>? definitions = {};
Map<String, APISecurityScheme?>? securityDefinitions = {};

Map<String, dynamic> asMap() {
return KeyedArchive.archive(this, allowReferences: true);
Expand All @@ -57,13 +57,15 @@ class APIDocument extends APIObject {
produces = object["produces"];
security = object["security"];

info = object.decodeObject("info", () => new APIInfo());
tags = object.decodeObjects("tags", () => new APITag());
paths = object.decodeObjectMap("paths", () => new APIPath());
responses = object.decodeObjectMap("responses", () => new APIResponse());
parameters = object.decodeObjectMap("parameters", () => new APIParameter());
definitions = object.decodeObjectMap("definitions", () => new APISchemaObject());
securityDefinitions = object.decodeObjectMap("securityDefinitions", () => new APISecurityScheme());
info = object.decodeObject("info", () => APIInfo());
tags = object.decodeObjects("tags", () => APITag());
paths = object.decodeObjectMap("paths", () => APIPath());
responses = object.decodeObjectMap("responses", () => APIResponse());
parameters = object.decodeObjectMap("parameters", () => APIParameter());
definitions =
object.decodeObjectMap("definitions", () => APISchemaObject());
securityDefinitions = object.decodeObjectMap(
"securityDefinitions", () => APISecurityScheme());
}

void encode(KeyedArchive object) {
Expand Down
12 changes: 6 additions & 6 deletions lib/src/v2/header.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import 'package:codable/codable.dart';
import 'package:open_api/src/v2/property.dart';
import 'package:open_api/src/v2/types.dart';
import 'package:codable_forked/codable.dart';
import 'package:open_api_forked/src/v2/property.dart';
import 'package:open_api_forked/src/v2/types.dart';

/// Represents a header in the OpenAPI specification.
class APIHeader extends APIProperty {
APIHeader();

String description;
APIProperty items;
String? description;
APIProperty? items;

void decode(KeyedArchive json) {
super.decode(json);
description = json.decode("description");
if (type == APIType.array) {
items = json.decodeObject("items", () => new APIProperty());
items = json.decodeObject("items", () => APIProperty());
}
}

Expand Down
20 changes: 10 additions & 10 deletions lib/src/v2/metadata.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import 'package:open_api/src/object.dart';
import 'package:open_api_forked/src/object.dart';

/// Represents a metadata for an API in the OpenAPI specification.
class APIInfo extends APIObject {
/// Creates empty metadata for specification.
APIInfo();

String title = "API";
String description = "Description";
String version = "1.0";
String termsOfServiceURL = "";
APIContact contact = new APIContact();
APILicense license = new APILicense();
String? description = "Description";
String? version = "1.0";
String? termsOfServiceURL = "";
APIContact? contact = APIContact();
APILicense? license = APILicense();

void decode(KeyedArchive object) {
super.decode(object);

title = object.decode("title");
description = object.decode("description");
termsOfServiceURL = object.decode("termsOfService");
contact = object.decodeObject("contact", () => new APIContact());
license = object.decodeObject("license", () => new APILicense());
contact = object.decodeObject("contact", () => APIContact());
license = object.decodeObject("license", () => APILicense());
version = object.decode("version");
}

Expand Down Expand Up @@ -92,8 +92,8 @@ class APITag extends APIObject {
description = object.decode("description");
}

String name;
String description;
String? name;
String? description;

void encode(KeyedArchive object) {
super.encode(object);
Expand Down
32 changes: 16 additions & 16 deletions lib/src/v2/operation.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:codable/cast.dart' as cast;
import 'package:open_api/src/object.dart';
import 'package:open_api/src/v2/parameter.dart';
import 'package:open_api/src/v2/response.dart';
import 'package:codable_forked/cast.dart' as cast;
import 'package:open_api_forked/src/object.dart';
import 'package:open_api_forked/src/v2/parameter.dart';
import 'package:open_api_forked/src/v2/response.dart';

/// Represents a HTTP operation (a path/method pair) in the OpenAPI specification.
class APIOperation extends APIObject {
Expand All @@ -16,18 +16,18 @@ class APIOperation extends APIObject {
"security": cast.List(cast.Map(cast.String, cast.List(cast.String))),
};

String summary = "";
String description = "";
String id;
String? summary = "";
String? description = "";
String? id;
bool deprecated = false;

List<String> tags = [];
List<String> schemes = [];
List<String> consumes = [];
List<String> produces = [];
List<APIParameter> parameters = [];
List<Map<String, List<String>>> security = [];
Map<String, APIResponse> responses = {};
List<String?>? tags = [];
List<String?>? schemes = [];
List<String?>? consumes = [];
List<String?>? produces = [];
List<APIParameter?>? parameters = [];
List<Map<String, List<String>>?>? security = [];
Map<String, APIResponse?>? responses = {};

void decode(KeyedArchive object) {
super.decode(object);
Expand All @@ -39,8 +39,8 @@ class APIOperation extends APIObject {
consumes = object.decode("consumes");
produces = object.decode("produces");
deprecated = object.decode("deprecated") ?? false;
parameters = object.decodeObjects("parameters", () => new APIParameter());
responses = object.decodeObjectMap("responses", () => new APIResponse());
parameters = object.decodeObjects("parameters", () => APIParameter());
responses = object.decodeObjectMap("responses", () => APIResponse());
schemes = object.decode("schemes");
security = object.decode("security");
}
Expand Down
Loading