-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
In version 0.14.0 I get this error when calling the generate() method:
Unhandled exception:
LateInitializationError: Local 'result' has not been initialized.
#0 LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:214:5)
#1 Schema.toDartType (package:openapi_spec/src/open_api/schema.dart)
#2 SchemaGenerator._writeProperty (package:openapi_spec/src/generators/schema.dart:919:32)
#3 SchemaGenerator._writeObject (package:openapi_spec/src/generators/schema.dart:616:17)
#4 SchemaGenerator.generate (package:openapi_spec/src/generators/schema.dart:136:11)
#5 OpenApi.generate (package:openapi_spec/src/open_api/spec.dart:451:23)
#6 main (file:///myapp/main.dart:27:14)
The problem seems to be in the toDartType method in schema.dart: if unions.entries is empty then result will never be assigned:
if (anyOf != null && unions != null) {
final subSchemas = anyOf.map((e) => e.toDartType()).toList();
final leq = ListEquality();
for (final e in unions.entries) {
if (leq.equals(subSchemas, e.value)) {
final type = e.key.pascalCase;
if (nullable == true) {
result = '$type?';
} else {
result = type;
}
}
}
break;Changing the top if statement to this made it work:
if (anyOf != null && unions != null && unions.isNotEmpty) {
Perhaps there needs to be a similar change for anyOf?
Metadata
Metadata
Assignees
Labels
No labels